aspnet-403758-troubleshooting-server-side-issues-no-access-for-file-and-image-controls.md
The errors occur when you use the following controls:
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...");
}
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