Back to Devexpress

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

aspnet-403758-troubleshooting-server-side-issues-no-access-for-file-and-image-controls.md

latest2.9 KB
Original Source

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

  • Jan 19, 2024

Error Description

The errors occur when you use the following controls:

Solution

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

ControlProperty
ASPxImageSliderASPxImageSlider.SettingsAutoGeneratedImages.ImageCacheFolder
ASPxImageGalleryASPxImageGallery.SettingsFolder.ImageCacheFolder
ASPxUploadControlASPxUploadControl.AdvancedModeSettings.TemporaryFolder
ASPxSpreadsheetASPxSpreadsheet.SettingsDocumentSelector.EditingSettings.TemporaryFolder,
ASPxSpreadsheet.WorkDirectory
ASPxRichEditASPxRichEdit.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:

csharp
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...");  

}
vb
Imports System.IO  
...  

Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)  
    Dim dirVirtualPath As String = "~/TestDir"  
    Dim dirPhysicalPath As String = MapPath(dirVirtualPath)  
    If (Not Directory.Exists(dirPhysicalPath)) Then  
        Directory.CreateDirectory(dirPhysicalPath)  
    End If  

    Dim fileName As String = "TestFile.txt"  
    Dim fileFullPath As String = Path.Combine(dirPhysicalPath, fileName)  

    File.WriteAllText(fileFullPath, "File Content Here...")  
End Sub