Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-10
5
Medium Priority
?
576 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Screencast - Getting to Know the Pipeline

610 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