473,756 Members | 3,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"The process cannot access the file" when trying to write to filethe second time...

The first time I called this function, everything went well, but the
second time I called it. An Exception thrown, do you know why?

An unhandled exception of type 'System.IO.IOEx ception' occurred in
mscorlib.dll

Additional information: The process cannot access the file
"E:\......\bin\ Debug\test.xml" because it is being used by another process.

----------------------------------------------
public void updateXMLFile()
{
string AppPath = System.Windows. Forms.Applicati on.StartupPath;
System.Xml.XmlT extWriter XMLWriter = new
System.Xml.XmlT extWriter(AppPa th + "/test.xml", System.Text.Enc oding.UTF8);

XMLWriter.Forma tting = System.Xml.Form atting.Indented ;
XMLWriter.Inden tation = 1;

/// <summary>
/// <?xml version="1.0" encoding="UTF-8"?>
/// </summary>
XMLWriter.Write StartDocument() ;

/// <summary>
/// <root>
/// </summary>
XMLWriter.Write StartElement("r oot");

/// <summary>
/// </root>
/// </summary>
XMLWriter.Write EndElement();

XMLWriter.Write EndDocument();

XMLWriter.Flush ();
XMLWriter.Close ();
}
----------------------------------------------
Nov 16 '05 #1
2 3529
Jax
Are you accessing the file elsewhere
It sounds like your standard filestream left open exception. I used to get them all the time
Logging out and back in will fix it without having to restart. You want to use try, and finally to ensure you always close the connection
I can see that you are following the protocol in the example (by closing the XMLWriter) so i'd suggest looking elsewhere in the code, or checking the documentation on the XMLWriter object to see if you have to close it another way
I don't know much about the object myself so i'm afraid I cant be of any more use, if I have been of any. :

Hope that help

jax
Nov 16 '05 #2
Origin Problem:

The first time I called this function, everything went well, but the
second time I called it. An Exception thrown, do you know why?

An unhandled exception of type 'System.IO.IOEx ception' occurred in
mscorlib.dll

Additional information: The process cannot access the file
"E:\......\bin\ Debug\test.xml" because it is being used by another process.

----------------------------------------------
public void updateXMLFile()
{
string AppPath = System.Windows. Forms.Applicati on.StartupPath;
System.Xml.XmlT extWriter XMLWriter = new
System.Xml.XmlT extWriter(AppPa th + "/test.xml", System.Text.Enc oding.UTF8);

XMLWriter.Forma tting = System.Xml.Form atting.Indented ;
XMLWriter.Inden tation = 1;

/// <summary>
/// <?xml version="1.0" encoding="UTF-8"?>
/// </summary>
XMLWriter.Write StartDocument() ;

/// <summary>
/// <root>
/// </summary>
XMLWriter.Write StartElement("r oot");

/// <summary>
/// </root>
/// </summary>
XMLWriter.Write EndElement();

XMLWriter.Write EndDocument();

XMLWriter.Flush ();
XMLWriter.Close ();
}
----------------------------------------------
Jax wrote:
Are you accessing the file elsewhere?
It sounds like your standard filestream left open exception. I used to get them all the time.
Logging out and back in will fix it without having to restart. You want to use try, and finally to ensure you always close the connection.
I can see that you are following the protocol in the example (by closing the XMLWriter) so i'd suggest looking elsewhere in the code, or checking the documentation on the XMLWriter object to see if you have to close it another way.
I don't know much about the object myself so i'm afraid I cant be of any more use, if I have been of any. :)

Hope that helps

jax


I've solved the problem. I changed the class which this function belong
to to a singleton (and it should be a singleton), everything work as
expected.

BTW, I still don't know why the XmlTextWriter didn't close properly...
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2048
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since the thread is over a month old, I decided to start a new one with my response. Please see my comments inline.
0
2041
by: Sugapablo | last post by:
I have two ASP pages. They basically query a database, and spit out the information as plain text in CSV format. The first has the SQL query hardcoded into it. The second takes a SQL query from a webform. Now, the hardcoded results, I can click "Save Page As" when the results come up and save it as a text file. The other, while it seems to be the same results exactly, gives me an
2
2062
by: Mark | last post by:
Hi, I'm running visual studio 2003, and am now receiving the error "The Operation Could Not Be Completed" when attempting to add a form / control or component class to a project. I can add any other type of item without a problem. This is the second time this has happened to my machine, last time I reinstalled VS and it fixed it. I havent installed anything since that time, so I guess it must be some sort of corruption in the system.
145
6323
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two programs: /*** a.c ***/
2
518
by: FrzzMan | last post by:
The first time I called this function, everything went well, but the second time I called it. An Exception thrown, do you know why? An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll Additional information: The process cannot access the file "E:\......\bin\Debug\test.xml" because it is being used by another process. ----------------------------------------------
2
4617
by: SammyBar | last post by:
Hi all, I'm trying to send a message from ASP.NET to another PC by using MSMQ. I created my ASP.NET project by using Visual Studio 2005 but I initially set the project to be located on the File System. Then I could successfully send, receive and purge the public queries I use to exchange information with the another PC. But when I realized I can not reach the file system created project from a third PC then I recreated the project as...
9
9698
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
2
4726
by: Wimpie van Lingen | last post by:
Hey I have some more questions with regards to Remoting in .NET 2. I'm using TCP with the Binary formatter. My solution consists of 4 projects: - Class Library containing the server classes which Inherits MarshalByRefObject (ok, at this stage it only contains one class... but its gonna grow) - Class Library containing common classes and interfaces that will be shared between all projects. This include interfaces for the server...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.