The file is being used by some other process

hi ,

Am trying to read from and write to a same xml file.i have no prob when
reading the xml file.but when i write to the same file i get the following
error even after closing the reader object(which is open).

The file is being used by some other process.

---------------------------------------------------

This is what am doing in the code:

 i have used the XmlTextReader and loaded the file to an XmlDocument
object and closed the Reader object.  and after the processing of the
documnet, am writing to the file by passing a XmltextWriter obj to the
save() method in XmlDocument class. [more over I came to know that the
reader.close() only changes the read state to closed]

-------------------------------------------------------

Code Block here:

xdoc.Load(fs);           //Loading the file

try

{fs.Close();         //Closing the file

Thread.Sleep(1000);

}

catch

{Thread.Sleep(1000);}

xmltagfinder();

XmlNode unode;

nodelist=xdoc.GetElementsByTagName(xnode.Name);

unode=nodelist[0].FirstChild;


count=nodelist.Count;i=0;

while(i!=count)

{

if(unode.ParentNode.ParentNode.Name!="LIST_ITEMS")

{

if(Convert.ToInt32(unode.InnerText)==Convert.ToInt32(id1))

{

unode.NextSibling.InnerText="";

unode.NextSibling.InnerText=name;

}

else

{

unode=nodelist[i].FirstChild;


}

}

i++;

xtr=null

xdoc.Save("d:/Dash2.xml");                      //i also tried
xdoc.Save(fs);



}






regards
Jagadeesh


0
jagamsc (4)
1/14/2004 7:07:46 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
509 Views

Similar Articles

[PageSpeed] 59

Jagadeesh wrote:

> Am trying to read from and write to a same xml file.i have no prob when
> reading the xml file.but when i write to the same file i get the following
> error even after closing the reader object(which is open).
> 
> The file is being used by some other process.

I cannot reproduce the problem. After calling to XmlReader.Close() the 
doc can be saved into the same file.

> try
> 
> {fs.Close();         //Closing the file
> 
> Thread.Sleep(1000);
> 
> }
....
> xdoc.Save(fs);

This is weird. fs has been closed already.

-- 
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
0
Oleg
1/14/2004 3:14:17 PM
Reply:

Similar Artilces: