'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:
- ASPxImageSlider: ImageCacheFolder (ASPxImageSlider.SettingsAutoGeneratedImages.ImageCacheFolder);
- ASPxImageGallery: ImageCacheFolder (ASPxImageGallery.SettingsFolder.ImageCacheFolder);
- ASPxUploadControl in Advanced or Auto upload mode (UploadMode): TemporaryFolder (ASPxUploadControl.AdvancedModeSettings.TemporaryFolder);
- ASPxSpreadsheet: TemporaryFolder (ASPxSpreadsheet.SettingsDocumentSelector.EditingSettings.TemporaryFolder) and WorkDirectory;
- ASPxRichEdit: WorkDirectory.
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...");
}