首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

HttpPostedFile PostedFile获取不到FileName,该怎么解决

2013-01-04 
HttpPostedFile PostedFile获取不到FileNameif (PostedFile.FileName ! ){try{string fileName PathT

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

引用:
怎么?会是因为这个跳到 this.error = "Please select the upload file";这句?
那应该怎么写?

热点排行