Skip to main content

'The X has no access to path Y' or 'Access to the path X is denied' for File and Image Extensions

Error Description:

The errors occur when you use the following extensions:

Solution:

Make sure that you granted access to the folders specified in the following properties:

You can use the code below in the controller action to check if the specified Web Server’s directory has permissions for file operations:

public ActionResult Index() {
    string dirVirtualPath = "~/TestDir";
    string dirPhysicalPath = Server.MapPath(dirVirtualPath);
    if(!Directory.Exists(dirPhysicalPath)) {
        Directory.CreateDirectory(dirPhysicalPath);
    }
    string fileName = "TestFile.txt";
    string fileFullPath = Path.Combine(dirPhysicalPath, fileName);
    System.IO.File.WriteAllText(fileFullPath, "File Content Here...");
    return View();
}