首页 新闻 赞助 找找看

一个文件名的问题

0
悬赏园豆:200 [已解决问题] 解决于 2012-12-23 22:52

前一段时间用FileUpload上传文件的时候用了一行代码就获取了文件的唯一的标识名,我忘记了代码是怎么写的了,求高手指教。

 

 

是用了一个属性还是方法之类的东西,就获取了文件的类似于唯一名之类的东西。

动感超人z的主页 动感超人z | 初学一级 | 园豆:1
提问于:2012-10-28 22:52
< >
分享
最佳答案
0

FileUpload1.Value 获取文件的路径..

收获园豆:200
jingjunfeng | 小虾三级 |园豆:873 | 2012-10-28 23:42
其他回答(8)
0
 1     protected void lbtnUp_Click(object sender, EventArgs e)
 2     {
 3         if (fuProductPhoto.HasFile)
 4         {
 5             if (fuProductPhoto.PostedFile.ContentLength > 100 * 1024)
 6             {
 7                 Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("照片大小不能超过100K,请重新选择"));
 8             }
 9             else
10             {
11                 if (fuProductPhoto.PostedFile.ContentType == "image/gif" || fuProductPhoto.PostedFile.ContentType == "image/x-png" || fuProductPhoto.PostedFile.ContentType == "image/pjpeg" || fuProductPhoto.PostedFile.ContentType == "image/bmp")
12                 {
13                     string strNewName = WebUnitily.GetName() + System.IO.Path.GetExtension(fuProductPhoto.FileName);
14                     string strPath = Server.MapPath("~/photo/" + strNewName);
15                     fuProductPhoto.PostedFile.SaveAs(strPath);
16                     imgPhoto.ImageUrl = "~/photo/" + strNewName;
17                     ViewState["photo"] = strNewName;
18                 }
19                 else
20                 {
21                     Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("请上传常用格式的图片"));
22                 }
23 
24             }
25         }
26         else
27         {
28             Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("请您选择照片后再上传?"));
29         }
30     }

可以共同参考一下!!

Kencery | 园豆:357 (菜鸟二级) | 2012-10-28 23:53
0
 //Upload pic
        string fullFileName1 = this.AdBanner1.PostedFile.FileName;
        string fileName1 = fullFileName1.Substring(fullFileName1.LastIndexOf("\\") + 1);
        string type1 = fullFileName1.Substring(fullFileName1.LastIndexOf(".") + 1);
        string PicUrl1 = "UpLoad/" + DateTime.Now.ToString("yyyyMMddHHmmss") + fileName1;

        if (PicUrl1.ToString().Trim().Length > 21)
        {
            if (type1 == "jpg" || type1 == "gif" || type1 == "JPG" || type1 == "GIF" || type1 == "doc" || type1 == "DOC" || type1 == "xls" || type1 == "XLS" || type1 == "zip" || type1 == "ZIP")
            {
                this.AdBanner1.PostedFile.SaveAs(Server.MapPath("UpLoad") + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + fileName1);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), ("alert"), "<script>alert('只能上传:jpg,gif,doc,xls,zip');</script>");
                return;
            }
        }
jason2013 | 园豆:1998 (小虾三级) | 2012-10-29 08:36
0

HttpPostedFile.FileName可以获取客户端上的文件的完全限定名称,但现在的浏览器为了安全起见,有时是不会提供完整的路径,只提供文件名。

I,Robot | 园豆:9783 (大侠五级) | 2012-10-29 08:58

就是这个。

支持(0) 反对(0) chenping2008 | 园豆:9836 (大侠五级) | 2012-10-29 09:18

貌似不是这个,这个是文件的路径,我很清楚的记得我用的哪个方法得到的是一连串的数字,

支持(0) 反对(0) 动感超人z | 园豆:1 (初学一级) | 2012-10-29 17:56
0

楼上正解

ms_water | 园豆:510 (小虾三级) | 2012-10-29 09:14
0

 protected void btn_AddDocConfirm_Click(object sender, EventArgs e)
        {
            string DocDescription = txt_DocDescription_Add.Text;
            int FileSize = 0;
            int UpdateUserID = Convert.ToInt32(Session["UserID"]);
            string FileAlias = "User" + UpdateUserID.ToString() + "_"+DateTime.Now.ToLocalTime();
            string DocName = "";
            string FileType = "";
            if (FileUpload_AddDoc.HasFile)
            {
               FileSize= FileUpload_AddDoc.PostedFile.ContentLength;
               DocName = FileUpload_AddDoc.FileName;
               FileType =System.IO.Path.GetExtension(FileUpload_AddDoc.FileName);
            }
            FileAlias = FileAlias + FileType;
            string CategoryID =ddl_DocCategory_Add.SelectedValue;
            string UpdateTime = DateTime.Now.ToShortDateString();
            string FilePath = Server.MapPath(@"~/Doc/" + FileAlias);
            FileUpload_AddDoc.SaveAs(FilePath);
            DataAccess da = new DataAccess(Convert.ToString(Session["ConnectString"]));
            int newDocID = da.ExecSProc("Document_InUpDel", "SQLInsert", 0, txt_DocName_Add.Text, DocDescription, FilePath, FileSize, FileType, FileAlias, CategoryID, UpdateUserID, UpdateTime);

            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "closebg() ", true);
            pl_DocAdd.Visible = false;
            bindDocuments();
        }

其小本 | 园豆:37 (初学一级) | 2012-10-29 14:48
0

using System.IO;

string mikecat_filename = Path.GetTempFileName();

//返回唯一临时文件名并在磁盘上通过该名
//称创建零字节文件。

励马 | 园豆:67 (初学一级) | 2012-10-30 15:02
0

System.IO.Path.GetFileName

是这个吗?

undefined | 园豆:898 (小虾三级) | 2012-10-30 19:09
0

GUId

王大湿 | 园豆:457 (菜鸟二级) | 2012-11-01 20:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册