Skip to main content
A newer version of this page is available. .
All docs
V21.2

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

Error Description:

The errors occur when you use the following controls:

Solution:

Use the following API to specify permissions for file (IO) operations:

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

using System.IO;  
...  

protected void Page_Init(object sender, EventArgs e) {  
    string dirVirtualPath = "~/TestDir";  
    string dirPhysicalPath = MapPath(dirVirtualPath);  
    if(!Directory.Exists(dirPhysicalPath)) {  
        Directory.CreateDirectory(dirPhysicalPath);  
    }  

    string fileName = "TestFile.txt";  
    string fileFullPath = Path.Combine(dirPhysicalPath, fileName);  

    File.WriteAllText(fileFullPath, "File Content Here...");  

}