asp上传文件,怎么不改变文件原来的名字?
stringstrName=FileUpload1.PostedFile.FileName;if(strName!=""){inti=strName.LastIndexO...
string strName = FileUpload1.PostedFile.FileName;
if (strName != "")
{
int i = strName.LastIndexOf(".");
string newName = FileUpload1.PostedFile.FileName;
string relativePath = "admin\\images";
string absolutePath = Server.MapPath("~\\admin\\image");
if (!Directory.Exists(absolutePath))
{
Directory.CreateDirectory(absolutePath);
}
string newFileName = absolutePath + "\\" + newName;
FileUpload1.PostedFile.SaveAs(newFileName);
TextBox1.Text = relativePath + "\\" + newName;
Page.RegisterClientScriptBlock("alert", "<script>alert('" + "上传图片成功!" + "')</script>");
}
}
代码该如何修改? 展开
if (strName != "")
{
int i = strName.LastIndexOf(".");
string newName = FileUpload1.PostedFile.FileName;
string relativePath = "admin\\images";
string absolutePath = Server.MapPath("~\\admin\\image");
if (!Directory.Exists(absolutePath))
{
Directory.CreateDirectory(absolutePath);
}
string newFileName = absolutePath + "\\" + newName;
FileUpload1.PostedFile.SaveAs(newFileName);
TextBox1.Text = relativePath + "\\" + newName;
Page.RegisterClientScriptBlock("alert", "<script>alert('" + "上传图片成功!" + "')</script>");
}
}
代码该如何修改? 展开
2个回答
2012-06-19
展开全部
FileUpload1.FileName 是获得上传的文件名,FileUpload1.PostedFile.FileName 获得上传的文件名包括其完整路径。但FileUpload1.PostedFile.FileName 在ie8下却只是获得文件名
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询