Search code examples
c#.netfile-uploadhttppostedfilelocked-files

File is locked after HttpPostedFile SaveAs(LocationOnServer)


I have an aspx webpage that uses as handler to save uploaded files via swfupload I am saving the file on the server like this:

HttpPostedFile uploadedFile = Request.Files["Filedata"];
uploadedFile.SaveAs(LocationOnServer);

the problem is that after I save the file the file remain locked (by w3wp.exe) until I restart the IIS. Is there any way to release the file after save? Thanks


Solution

  • I have dealt with the same situation in the past. You need to run your application pool under a domain account. That is, the app pool under which your web application is running should be setup to run as a domain user. That same domain user should then be given permissions to the folder you are trying to upload to. In order to assign a domain user to your application pool, select the appropriate pool from the application pools node in IIS, right click and select properties. From the properties dialog box select the identity tab and choose "Configurable" and then provide a domain account. Then you should give permissions to the same user on your folder.