Friday, July 31, 2009

Microsoft IIS File Contention?

Hi All,


I am breaking my head for two days with a simple problem.


I have created a web method using .Net web services and I am creating a text file inside the web method. when I call the webmethod for the first time, the text file is getting created without any issues, but when I call the webmethod again,I am getting "file in use exception", while monitoring the file I found out that the file is being used by aspnet_wp.exe process.





The IIS process is holding the text file untill it is restarted, Please find the code snipet below :


[WebMethod]


public string HelloWorld()


{


try


{


File.Create(@"C:\Testing\ControlEnd.tx...


return "File created successfuly";


}


catch(Exception ex)


{


return "Error in file creation"+ex.ToString();


}


}





Could someone help me in getting this resolved?

Microsoft IIS File Contention?
I believe that File.Create returns a FileStream object, that must be closed after you are done with the file. Because you are not closing the file, the file remains open and locked.


No comments:

Post a Comment