Click here to Skip to main content
15,031,495 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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;
           }

Please help me.

Azhar
Iqbal
Posted
Updated 10-Oct-11 2:44am
v3

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...

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

...
   
Try this

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900