HttpPostedFile PostedFile获取不到FileName
if (PostedFile.FileName != "")
{
try
{
string fileName = PathToName(PostedFile.FileName);
for (int i = 0; i < FileType.Length; i++)
{
if (fileName.EndsWith(FileType[i]))
{
filetype = 1;
}
}
if (filetype != 1)
{
string errs = "";
for (int i = 0; i < FileType.Length; i++)
{
errs = errs + FileType[i] + "/";
}
this.error = "System only support file as " + errs + ",Not spport " + PostedFile.ContentType + " file";
return;
}
if (PostedFile.ContentLength > FileLength)
{ this.error = "file size more than limit"; return; }
FileUtil.CreatFolder(SavePath);
string newfilename=DateTime.Now.ToFileTime().ToString();
int fi = fileName.LastIndexOf('.');
string suffix = fileName.Substring(fi, fileName.Length-fi);
PostedFile.SaveAs(SavePath + newfilename + suffix);
this.uploadFileName = newfilename + suffix;
return;
}
catch (System.Exception exc) { this.error = exc.Message; }
}
this.error = "Please select the upload file";
我自己电脑没问题,但是发布到服务器上,弹出"Please select the upload file",我不知道为什么,我看不到服务器那边情况,只能推测可能是没有取到FileName。
谁知道这种会是什么情况?
[解决办法]
try catch 编写的时候,使用不合理
[解决办法]
cathc中,return