Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create and write to file

Status
Not open for further replies.

lfc77

Programmer
Aug 12, 2003
218
GB
Can anybody tell me what is wrong with this code?

The error I am getting is:

'The process cannot access the file "c:\inetpub\ because it is being used by another process'


long lngNextNumber = Find_Next_File_Number();

//File.Create("C:\\inetpub\\ + lngNextNumber + ".xml");


//create the XMLTextWriter
string strNewFile = "c:\\inetpub\\ 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();


Thanks,

lfc77
 
Sorry, a few mistakes in my post - File.Create shouldn't be commented out and the next line should refer to this new file.
 
Tried this, but I get this error :

Access to the path "C:\WINNT\SYSTEM32\System.IO.FileStream" is denied.


long lngNextNumber = Find_Next_File_Number();


string strNewFile = Convert.ToString(File.Create("C:\\inetpub\\ + lngNextNumber + ".xml"));


//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();


lfc77
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top