473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

create and write to file

I am trying to create a new file and write to it, but I keep getting the
error 'cannot access the file because it is being used by another
process'. Can anybody help me out?

long lngNextNumber = Find_Next_File_Number();

string strNewFile =
"C:\\inetpub\\wwwroot\\webapplication90\\xml_files \\test" +
lngNextNumber + ".xml";
File.Create(strNewFile);
//create the XMLTextWriter
XmlTextWriter tw = new XmlTextWriter(strNewFile, null);

//set the formatting to indented
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();

//start creating elements and attributes
tw.WriteStartElement("book");
tw.WriteElementString("title", "Case of the missing cookie");
tw.WriteEndElement();
tw.WriteEndDocument();

//clean up
tw.Flush();
tw.Close();
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
1 4286
Hi,
simply remove this line: File.Create(strNewFile);
If you create a File object, then it's being used, and u can't create an
XMLTextWriter with the same path and filename

--
Rami Saad
Microsoft GTSC Developer support for Middle East
"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to create a new file and write to it, but I keep getting the
error 'cannot access the file because it is being used by another
process'. Can anybody help me out?

long lngNextNumber = Find_Next_File_Number();

string strNewFile =
"C:\\inetpub\\wwwroot\\webapplication90\\xml_files \\test" +
lngNextNumber + ".xml";
File.Create(strNewFile);
//create the XMLTextWriter
XmlTextWriter tw = new XmlTextWriter(strNewFile, null);

//set the formatting to indented
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();

//start creating elements and attributes
tw.WriteStartElement("book");
tw.WriteElementString("title", "Case of the missing cookie");
tw.WriteEndElement();
tw.WriteEndDocument();

//clean up
tw.Flush();
tw.Close();
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2

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

Similar topics

4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
3
by: fripper | last post by:
When testing a VB .Net application on my system (with IIS installed) I get an error message when using the fileopen function and the file does not exist ... i.e. I want fileopen to create the file....
1
by: Mike | last post by:
I'm trying to create a text file and when i compile my code i keep getting invalid token FileInfo t = new FileInfo("test.txt"); StreamWriter Tex =t.CreateText(); Tex.WriteLine("test file");...
3
by: VB Programmer | last post by:
I have a server that is running Windows Server 2003. My web page is trying to create a file in the C:\inetpub\wwwroot\MyWeb\Secured directory. When it tries to create/write the file it gets...
0
by: shefali | last post by:
Hi, I need to use an HTTPHandler to create and write files. I wanted to create the file in the directory that has this handler, and other handlers. For me, this directory is:...
1
by: John Wright | last post by:
I want to create a file hash on my exe files and store the hash signature in a database so I can retrieve the value to compare the file hash to ensure I have an untampered file. How can this be...
1
by: Eran.Yasso | last post by:
Hi, Can anyone please tell me how can i create xls file? i then need to write to it. I am creating the file using File.Create(file.xls); but ican't acces the file. i gt error that the file is...
4
by: nano2k | last post by:
Hi For some purposes, I need to create a new binary file and to allocate a fixed length for that file on the disk. I need something like File.Create(string fileName, long initialSizeInBytes)....
3
by: brook | last post by:
hey all - i´m new to php and having trouble writing a simple code which should create a file. here is the most simplified version: <?php $content = "my content"; $path = "test.txt";...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.