ASP.net中的FileUpload问题 [英] FileUpload Problem in ASP.net

查看:109
本文介绍了ASP.net中的FileUpload问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发环境VS2010中工作.我已经在根目录下创建了一个目录.
当我使用FileUpload Controll上传文件时,出现以下错误.

访问被拒绝".我已将NetworkAuthority的权限授予了主管.请注意,我尚未在IIS上发布网站.

代码在下面给出

I am working in Developement Environment VS2010. I have created a directory at the root level.
When I upload File with FileUpload Controll it give me following Error.

"Access is denied". I have given rights to NetworkAuthority to the director. Please note that I have not published site at the IIS.

Code is given below

string saveDir = @"UpLoads";
           string appPath = Request.PhysicalApplicationPath;
           if (FileUpload1.HasFile)
           {
               string savePath = appPath + saveDir;
               FileUpload1.SaveAs(savePath);
               UploadStatusLabel.Visible = false;
               //lblErrorMsg.Text = "Your file was uploaded successfully.";
               return true;
           }
           else
           {
               // Notify the user that a file was not uploaded..
               UploadStatusLabel.Visible = true;
               UploadStatusLabel.Text = "Specify a file.";
              return false;
           }


请帮帮我.

阿扎尔
Iqbal


Please help me.

Azhar
Iqbal

推荐答案

请使用Server.MapPath(.")+文件路径(/folder/filename.extension)"
Please check your physical path with Server.MapPath(".")+"your file''s path(/folder/filename.extension)"


我将通过代码创建目录以避免该问题,
那么创造者就是消费者...

I would create the directory by code to avoid that problem,
then the creator is the consumer...

if (!Directory.Exists("yourPath")){
   Directory.CreateDirectory("yourPath");
}


...


...


尝试一下

Try this

string TempPath = "UploadPatientImage\\TempImage";
                DirectoryInfo thisFolder = new DirectoryInfo(TempPath);
                if (!thisFolder.Exists)
                {
                    thisFolder.Create();
                }
                FileUpload1.PostedFile.SaveAs(TempPath + "\\" + FileUpload1.FileName);


这篇关于ASP.net中的FileUpload问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆