Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 21, 2012 04:53 PM by sohaam.gupta
Mar 24, 2011 04:19 AM|LINK
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.
Mar 24, 2011 04:51 AM|LINK
Add this tag in the web config file
<identity impersonate="true" userName="Admin" password="Password"/>
You need to give the admin userid and password.
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.....
Mar 24, 2011 05:58 AM|LINK
Added MachineName\IIS_IUSRS permission to the shared folder.
Now its working fine.Issue Solved.
Feb 21, 2012 04:53 PM|LINK
Great Post, it really helped a lot.