System.IO.IOException Please help me
-
Dear friends, I am trying to upload one excel file to sqlserver database by using fileupload control. I am initially uploading the file and saving in a temporary folder and from this temporary folder I am copying the data to SqlServer Table. After copying the data, I want to delete the file in Temporary Folder. I wrote File.Delete(filename) code, but it is throwing following exception [System.IO.IOException] = {"The process cannot access the file 'E:\\SourceSafe\\ESSP\\Finance\\FinancePL\\uploadedfiles\\samplePS.xls' because it is being used by another process."} It is not allowing to delete the file. Please, can anyone help me in this. It's very urgent. Please.... Thanks, Dileep.
-
Dear friends, I am trying to upload one excel file to sqlserver database by using fileupload control. I am initially uploading the file and saving in a temporary folder and from this temporary folder I am copying the data to SqlServer Table. After copying the data, I want to delete the file in Temporary Folder. I wrote File.Delete(filename) code, but it is throwing following exception [System.IO.IOException] = {"The process cannot access the file 'E:\\SourceSafe\\ESSP\\Finance\\FinancePL\\uploadedfiles\\samplePS.xls' because it is being used by another process."} It is not allowing to delete the file. Please, can anyone help me in this. It's very urgent. Please.... Thanks, Dileep.
Lots of information missing though. The moment you uploaded it to temp folder, how do you upload it to database? Is the upload to DB process simultaneously going on? Immediately or afterwards? Is that process of uploading to DB is in progress when you try to delete it? Looks like the temporary folder is a Sourcesafe folder. Those are write protected. Lastly, you should directly upload it to DB instead of inserting an extra step in between and having a performance hit!
-
Dear friends, I am trying to upload one excel file to sqlserver database by using fileupload control. I am initially uploading the file and saving in a temporary folder and from this temporary folder I am copying the data to SqlServer Table. After copying the data, I want to delete the file in Temporary Folder. I wrote File.Delete(filename) code, but it is throwing following exception [System.IO.IOException] = {"The process cannot access the file 'E:\\SourceSafe\\ESSP\\Finance\\FinancePL\\uploadedfiles\\samplePS.xls' because it is being used by another process."} It is not allowing to delete the file. Please, can anyone help me in this. It's very urgent. Please.... Thanks, Dileep.
You have to release resources used during the first phase of your code, which is saving file into physical space/directory. For example:
fileObjectUsed.dispose();
OR
FileUpload1.dispose();
I would recommend you not to store file into your web server location as this will add extra overhead of saving and deleting files and of-course security problem. You can directly store it(file) into database by converting it to bytes. Check out the link Storing Binary Data to Database using ASP.NET 2.0[^] Observe the code lines...
Dim imageBytes(fileUpload1.PostedFile.InputStream.Length) As Byte
fileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length)puranonnet@hotmail.com BCS Technology