FileUpload1.Value 获取文件的路径..
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 }
可以共同参考一下!!
//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; } }
HttpPostedFile.FileName可以获取客户端上的文件的完全限定名称,但现在的浏览器为了安全起见,有时是不会提供完整的路径,只提供文件名。
就是这个。
貌似不是这个,这个是文件的路径,我很清楚的记得我用的哪个方法得到的是一连串的数字,
楼上正解
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();
}
using System.IO;
string mikecat_filename = Path.GetTempFileName();
//返回唯一临时文件名并在磁盘上通过该名
//称创建零字节文件。
System.IO.Path.GetFileName
是这个吗?
GUId