Sirwan Afifi
Sirwan Afifi

Reputation: 10824

Access is Denied when i want to Create Folder inside Content Folder

hi i am using this code to upload a file with ASP.NET MVC everything is OK but it cant Access to Upload Folder :

public static char DirSeparator = System.IO.Path.DirectorySeparatorChar;
        public static string FilesPath = "Content" + DirSeparator + "Uploads" + DirSeparator;
        public static string UploadFile(HttpPostedFileBase file)
        {
            if (null == file) return "";
            if (!(file.ContentLength > 0)) return "";
            string fileName = file.FileName; string fileExt = Path.GetExtension(file.FileName);
            if (null == fileExt) return "";
            if (!Directory.Exists(FilesPath))
            {
                Directory.CreateDirectory(FilesPath);
            }
            string path = FilesPath + DirSeparator + fileName;
            file.SaveAs(Path.GetFullPath(path));
            return fileName;
        }

and i get this error :

Access to '/Content/Upload/' is Denied

where is my problem,

Thanks in your Advise

Upvotes: 1

Views: 1643

Answers (1)

Matt Clark
Matt Clark

Reputation: 28599

Your problem is with permissions, and that your permission is being run as a user that does not have access to the location where you are requesting it to make a directory. Be sure that your user owns or has group permissions to be in, and create file/folders in the location you are trying.

Upvotes: 1

Related Questions