Hi All,
Hope you are doing well.
I am using file upload control to upload pdf file in asp.net.
I've one specific document folder under root directory, like ~/PaperDocument.
For each new upload I am creating sub directory under the "PaperDocument".
I am getting error in following piece of code:
public void SaveAttachment(string Year, string FileName)
{
if (!Directory.Exists(Server.MapPath("~/PaperDocument/" + Year)))
{
Directory.CreateDirectory(Server.MapPath("~/PaperDocument/" + Year));
}
fuAttachment.SaveAs(Server.MapPath("~/PaperDocument/" + Year + "/" + FileName));
}
This code is working on my local but throwing an error on shared hosting server.
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I believe that this is the security issue. If I set full control(read/write permission) for Everyone on the hosting Panel then it is working. but I don't want to do this.
How can I permit my application to create folder.
Is anyone have idea about this.