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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW DO YOU SAVE AN .XML FILE WITH A STRING 2

Status
Not open for further replies.

Domino2006

Programmer
Jan 13, 2007
20
0
0
GB
Ok i have a database im writing the database contents into an .XML file
but in my program i have 2 text boxes which hte user enters his or her name and an id which is an int32 i would like to be able to use the persons name and id as the filename when the xml file gets written plzz could you help guys im stumped on this. any help with code we be brilliant thanx in advance you guys are gr8.

Domino2006
 
For the XML, you must be using an XML writter to write to it.

*** Suppose that the file name will be: Name_Id, so:

Dim f As String = String.Format("{0}_{1}.xml", txtName.Text, ID.ToString())
Dim xmlw As New Xml.XmlTextWriter(f, System.Text.Encoding.Unicode)


*** NOTES
1. The txtName i suppose that is the textbox's name
2. The ID i suppose that is the Int32 or whatever - variable name
3. I used Unicode encoding.

Hope this helps
 
Domino2006,

You could also use the String.Concat method, something similar to
Code:
Dim sFile As String = "C:\Temp\"
sFile = String.Concat(sFile, Me.txtClientName.Text, "-", Me.txtInventoryID.Text, ".xml)
Dim oXmlWriter As New Xml.XmlTextWriter(sPath,System.Text.Encoding.UTF8)

This would give you the document: C:\Temp\Name-ID.xml

Hope this helps.

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT * FROM Users WHERE clue > 0
0 Rows Returned

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Hello PsychoCoder,

String concatenation -hope this is the right word- can lead many times to errors (mistakes while 'building' the string). I would either prefer to concat:

the (path) with the (file name)

OR better:

Format.String("{0}\{1}-{2}.xml", ..., ..., ...)
WHERE {0} is the path, {1} the name and {2} the ID.


*** NOTE for Domino2006,
1. I did not include any path, so the file will be created in the same path as the calling assembly's one.
2. You may want to check first if the file exists. (System.IO.File.Exists("filepath\file.something"))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top