We have a webpage that allows users to upload a file to shared folder. There is a gridview which contains the list of uploded file names. Once the file is uploaded, the filename is added with a hyperlink in gridview. On click of hyperlink, FileDownload window should appear which allows users either to open the file or save the file. File should be opened only in ReadOnly format.So, we are using below code in btnUpload_Click method FileUpLoad1.SaveAs(attachmentSharePath + "\\" + attachmentnID + "." + extension); //Applying read-only attribute to the uploaded file so that it is Read-Only formatFile.SetAttributes(attachmentSharePath + "\\" + attachmentID + "." + extension, FileAttributes.ReadOnly); A check box is present beside every attachment which allows users to delete attachment from the grid view and the shared folder. Updating the attributes of the file to Normal is necessary in order to delete it (since the attributes earlier was ReadOnly)//btnDelete_Click method - Setting File attribute of the attachment to normal so that it can be deleted File.SetAttributes(attachmentSharePath + "\\" + AttachmentNameInSharedFolder, FileAttributes.Normal);//Delete the attachment from the attachment share File.Delete(attachmentSharePath + "\\" + attachmentnID + "." + extension);This is working fine when we run it locally (within VS2008). File is getting uploaded. When I deploy the website to the webserver (Win 2008 R2) and try to upload the file through the webpage, it doesn't work!. Below is the error logged in eventvwr: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 btnUpload_Click(Object sender, EventArgs e)</StackTrace><Parameters>UploadClick method Error while Uploading</Parameters><SourceCode>System.UnauthorizedAccessException</SourceCode><ErrorMessage>Access to the path '\\aitdsql34\PC\1.docx' is denied.</ErrorMessage>We have given full permissions to ASPNET account on the shared folder. Please let me know if anything else need to be done.
Just add one important thing that is make sure you have to give domain user in given web.config tab. Because that have share filder persmission and also add that domain user in User group of your web server.
Note : User group having all relvant permission related to your aspnet preocess so you no need to specially given any permission. you just need take care about share folder permission.
Let me know if this not working.....
FileUpload.
My Tech Blogs MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
sravanig17
Member
16 Points
10 Posts
Access denied while File Upload (permissions given to ASPNET account)
Mar 24, 2011 04:19 AM|LINK
sarathi125
Star
13599 Points
2691 Posts
Re: Access denied while File Upload (permissions given to ASPNET account)
Mar 24, 2011 04:51 AM|LINK
Hi,
Add this tag in the web config file
<authentication mode="Windows"/>
<identity impersonate="true" userName="Admin" password="Password"/>
You need to give the admin userid and password.
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
amitpatel.it
Star
7966 Points
1865 Posts
Re: Access denied while File Upload (permissions given to ASPNET account)
Mar 24, 2011 04:57 AM|LINK
I am agree with sarathi...
Just add one important thing that is make sure you have to give domain user in given web.config tab. Because that have share filder persmission and also add that domain user in User group of your web server.
Note : User group having all relvant permission related to your aspnet preocess so you no need to specially given any permission. you just need take care about share folder permission.
Let me know if this not working.....
FileUpload.
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
sravanig17
Member
16 Points
10 Posts
Re: Access denied while File Upload (permissions given to ASPNET account)
Mar 24, 2011 05:58 AM|LINK
FileUpload.
sohaam.gupta
Member
4 Points
2 Posts
Re: Access denied while File Upload (permissions given to ASPNET account)
Feb 21, 2012 04:53 PM|LINK
Great Post, it really helped a lot.
Thanks