Solved

system.IO.IOException: the process cannot access the file

Posted on 2008-10-10
5
548 Views
Last Modified: 2013-12-17
Hi

I need to upload csv file to database after an update made by it and the filename is the same each time. However, it throws the system.IO.IOException: the process cannot access the file

here is the code

upfile.SaveAs(Server.MapPath(@"csv\temp.csv")); 

upfile.Dispose();

Open in new window

0
Comment
Question by:techques
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22688675
before you dispose, do you have to close anything?

can  you place a try/catch around code...

string str_Error;      
try{
upfile.SaveAs(Server.MapPath(@"csv\temp.csv"));
//close upfile here...
}
catch (Exception ex)
{
     str_Err = ex.StackTrace.ToString();   //gives BETTER ERROR message...
}
finally
{
      upfile.Dispose();
}
0
 

Author Comment

by:techques
ID: 22688781
However, it works on localhost. When I upload the web application to remote machine, it happens that error after upload the file first time.

It means it is ok to upload in the first time.
It throws such exception in 2nd time.  
0
 
LVL 21

Expert Comment

by:silemone
ID: 22688848
It's most likely because the filename is the same...if the file is not there, does it work?
0
 

Author Comment

by:techques
ID: 22692491
upfile.SaveAs(Server.MapPath(@"csv\temp.csv"));
System.IO.StreamReader strFile = new System.IO.StreamReader(Server.MapPath(@"csv\temp.csv"));

As I just need to read the data from the csv file and then insert to remote database.

Actually, there is no need to save the file.

However, how to handle this code?
System.IO.StreamReader(Server.MapPath(@"csv\temp.csv"));

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 50 total points
ID: 22698926
Why not create a stream from the uploaded file without saving it to the disk. Try this
strFile=upfile.postedfile.inputstream()
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now