Question

I can't save a file on my webserver with FileUpload.SaveAs() or with File.WriteAllText(). The folder I save in is CHMOD 666.

My code is this:

File.WriteAllText(MapPath(".") + "\\Ads\\test.jpg", "test");

This code works perfectly in Dev. server.

Best regards, Lasse Espeholt

System.UnauthorizedAccessException: Access to the path *' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at System.Web.UI.WebControls.FileUpload.SaveAs(String filename) at *(Object sender, ListViewInsertEventArgs e)

Was it helpful?

Solution

You will need to give read write permissions to machine's ASPNET account for desired folder. You can do it by opening folder properties -> security tab.

OTHER TIPS

Your error message states:

System.UnauthorizedAccessException: Access to the path *' is denied.

This looks a little odd. Have you edited the path or is that exactly how it's displayed? If the latter then something is going wrong with your call to MapPath.

I know the following may seem obvious, but I've been bitten by assumptions too many times in the past.

Have you verified that the folder you think you're writing to is the one that MapPath(".") + "\\Ads\\test.jpg" actually resolves to?

Do you have full rights to the "Ads" sub folder as well?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top