[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error "The process can't access the file because it is being used by another process.

Posted on 2010-01-06
6
Medium Priority
?
564 Views
Last Modified: 2012-05-08
hi,

When I am trying to read the xml text after it is transformed as follows it is throwing an exception
"The process can't access the file because it is being used by another process".

transformed.LoadXml(File.ReadAllText(strExportFile));

Could anybody help me why do I get this exception?
Thank you.
0
Comment
Question by:ipjyo
6 Comments
 
LVL 11

Accepted Solution

by:
princeatapi earned 400 total points
ID: 26192299
0
 
LVL 12

Assisted Solution

by:rajapandian_81
rajapandian_81 earned 400 total points
ID: 26192373
Hi,

Refer below link
http://bloggingabout.net/blogs/jschreuder/archive/2006/07/06/12886.aspx

In which FileUploadCompleted function will be called with parameter filepath with filename, and it will access the file once it is released.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 400 total points
ID: 26192405
I believe that problem is because you are not closing the XmlWriter, and the transform is not closing it either.

You want to try this:

     writer.Close();
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 11

Assisted Solution

by:lenordiste
lenordiste earned 400 total points
ID: 26192929
TheLearnedOne is probably right!

try this kind of construct in your code to ensure you are indeed closing your XMLWriter no matter the execution paths:
using (XmlWriter writer = XmlWriter.Create("myFile.xml")) {
        //YOUR CODE LOGIC
        writer.Flush();
}
0
 
LVL 12

Assisted Solution

by:williamcampbell
williamcampbell earned 400 total points
ID: 26192948
transformed.LoadXml(File.ReadAllText(strExportFile));

separate out to

String XML = File.ReadAllText(strExportFile);
transformed.LoadXml( XML);

Same Error?
0
 

Author Comment

by:ipjyo
ID: 26194811
hi,

Now it is working fine when I include
writer.Close()

Thanks very much for all your suggestions.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

873 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