FileUpload路径
生活随笔
收集整理的這篇文章主要介紹了
FileUpload路径
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
string xlsPath = this.FileUpload1.PostedFile.FileName;
string xlsPath = Server.MapPath("~/Excel/客戶需求表.xls");
兩者區別:
前者是物理路徑,后者是服務器路徑. FileUpload ful = new FileUpload();
????????ful.FileName;?? //文件件
????????ful.PostedFile.ContentLength;//文件大小,單位 B,除以 1024得到 K
????????ful.PostedFile.FileName;//完全路徑
protected void Button1_Click(object sender, EventArgs e)
????{
????????Boolean fileOK = false;
????????String path = Server.MapPath("~/UploadedImages/");
????????if (FileUpload1.HasFile)
????????{
????????????String fileExtension =
????????????????System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
????????????String[] allowedExtensions =
????????????????{ ".gif", ".png", ".jpeg", ".jpg" };
????????????for (int i = 0; i < allowedExtensions.Length; i++)
????????????{
????????????????if (fileExtension == allowedExtensions)
????????????????{
????????????????????fileOK = true;
????????????????}
????????????}
????????}
????????if (fileOK)
????????{
????????????try
????????????{
????????????????FileUpload1.PostedFile.SaveAs(path
????????????????????+ FileUpload1.FileName);
????????????????Label1.Text = "File uploaded!";
????????????}
????????????catch (Exception ex)
????????????{
????????????????Label1.Text = "File could not be uploaded.";
????????????}
????????}
????????else
????????{
????????????Label1.Text = "Cannot accept files of this type.";
????????}
????}
string xlsPath = Server.MapPath("~/Excel/客戶需求表.xls");
兩者區別:
前者是物理路徑,后者是服務器路徑. FileUpload ful = new FileUpload();
????????ful.FileName;?? //文件件
????????ful.PostedFile.ContentLength;//文件大小,單位 B,除以 1024得到 K
????????ful.PostedFile.FileName;//完全路徑
protected void Button1_Click(object sender, EventArgs e)
????{
????????Boolean fileOK = false;
????????String path = Server.MapPath("~/UploadedImages/");
????????if (FileUpload1.HasFile)
????????{
????????????String fileExtension =
????????????????System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
????????????String[] allowedExtensions =
????????????????{ ".gif", ".png", ".jpeg", ".jpg" };
????????????for (int i = 0; i < allowedExtensions.Length; i++)
????????????{
????????????????if (fileExtension == allowedExtensions)
????????????????{
????????????????????fileOK = true;
????????????????}
????????????}
????????}
????????if (fileOK)
????????{
????????????try
????????????{
????????????????FileUpload1.PostedFile.SaveAs(path
????????????????????+ FileUpload1.FileName);
????????????????Label1.Text = "File uploaded!";
????????????}
????????????catch (Exception ex)
????????????{
????????????????Label1.Text = "File could not be uploaded.";
????????????}
????????}
????????else
????????{
????????????Label1.Text = "Cannot accept files of this type.";
????????}
????}
轉載于:https://www.cnblogs.com/MySpace/archive/2009/11/10/1599826.html
總結
以上是生活随笔為你收集整理的FileUpload路径的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QQ协议TEA加密解密代码 C#
- 下一篇: 网站优化中,有哪些事项是一定要做好的