Your asp.net account {MACHINE}\ASPNET
does not have write access to that location. That is the reason why its failing.
Consider granting access rights to the resource to the ASP.NET request identity.
Right click on downloading folder Properties > Security Tab > Edit > Add > locations > choose your local machine > click OK > Type ASPNET below "Enter the object name to select" > Click Check Names
Check the boxes for the desired access (Full Control
). If it will not work for you do the same with Network Service
Now this should show your local {MACHINENAME}\ASPNET
account, then you set the write permission to this account.
Otherwise if the application is impersonating via <identity impersonate="true"/>
, the identity will be the anonymous user (typically IUSR_MACHINENAME
) or the authenticated request user.
Or just use dedicated location for storing files in ASP.NET which is App_Data
. To create it right click on your ASP.NET Project (in Visual Studio) Add > Add ASP.NET Folder > App_Data
. Then you'll be able to save data to this location:
var path = Server.MapPath("~/App_Data/file.txt");
System.IO.File.WriteAllText(path, "Hello World");