Last post Mar 28, 2017 04:31 PM by PatriceSc
Mar 28, 2017 03:58 PM|fahrabh|LINK
I am trying to save an uploaded photograph to the server. but it throws an exception :
Here is the code snippet :
if (student.ClassID == DataAccess.Stream.BA)
imgPath = "/Administration/Photographs/BA/";
else if (student.ClassID == DataAccess.Stream.BCom)
imgPath = "/Administration/Photographs/BCom/";
imgPath = "/Administration/Photographs/BSc/";
FileName = student.StudentName + fileExtention;
The same code works well on local machine but not on the server where it's deployed..
Can someone guide me if something is missing in this ?
Mar 28, 2017 04:15 PM|SheldonS|LINK
When I have encountered this error I needed to give the IIS user account the appropriate permissions to that folder. It has been a while since I needed to do it, and I know the user names have changes over the years. This might help you find the proper
user name or group, then give that user/group the read/write permissions.
Mar 28, 2017 04:18 PM|PatriceSc|LINK
It seems the Exists and CreateDirectory calls are done with the virtual path rather than with a physical path. It should be likely :
My personal preference would be likely to have imgPath=Server.MapPath(imgPath); once for all at the point where I don't care any more about the virtual path and want to start working with the corresponding physical path.
And then once done the account unders which your app runs may not have a write access to those folders (as pointed by SheldonS). IMO it's best to always clearly distingusih what is really part of your app and what should be considered as data.
Mar 28, 2017 04:25 PM|fahrabh|LINK
I have hosted the site on GoDaddy.I don't have access to IIS user accounts.
Mar 28, 2017 04:27 PM|fahrabh|LINK
Checked with your code. same error.
Access to the path is denied.
Mar 28, 2017 04:31 PM|PatriceSc|LINK
So if you have now the correct path in the error message you can now try :
https://therelentlessfrontend.com/2010/03/14/setting-write-permission-to-app_data-for-a-godaddy-hosted-site/ to give write access to
the needed folder(s).