问题:IE8、部分IE7可正常上传,但部分IE7和IE六上传失败。虚拟路径无效。
解决方案:
private void UpLoad()
{
string filePath = "";
//**********************************************************问题1**********************************************************
//filePath = this.FileUpload1.PostedFile.FileName;//之前的写法,IE6、7报错
HttpPostedFile PostFile = this.FileUpload1.PostedFile;//上传的文件对象(正常)
filePath = System.IO.Path.GetFileName(PostFile.FileName); //文件名(正常)
DirectoryInfo upDir = new DirectoryInfo(Server.MapPath("../SystemManage/DocumentManage"));
if (!upDir.Exists)
{
upDir.Create();
}
int m = filePath.LastIndexOf("."); //取得文件名中最后一个"."的索引
string newext = filePath.Substring(m);
int ContentLength = this.FileUpload1.PostedFile.ContentLength;
int UploadedLength = 0;
if (FileUpload1.FileContent.Length != 0)
{
DateTime now = DateTime.Now; //获取系统时间
string path1 = (filePath.Split('.')[0] + DateTime.Now.ToString("yyyMMddHHmmss").Trim() + newext).Trim();
string path = this.Server.MapPath(@"DocumentManage/" + Server.HtmlEncode(path1));
try
{
FileUpload1.PostedFile.SaveAs(path); //上传大文件发布以后报错
}
catch (Exception ex)
{ }
}
}