Re: unable to write to file
Why are you creating XML file with the streamwriter.
Have you looked at System.XML and the XMLWriter???? this is really what you should use for creating xml files
however to create and write to file:
VB Code:
Dim l_sWriter As New StreamWriter(target)
Dim l_writeLine As String
l_writeLine = "<info class=""1A"" indexno=""01"" date=""10/10/2005"" time=""10:18:00""/>"
l_sWriter.WriteLine(l_writeLine)
l_sWriter.Close()
Re: unable to write to file
ya.
I tried using the xmltextwriter, but i am very cofused because when I add the codes:
Dim w As XmlTextWriter = New XmlTextWriter(target, )
in the brackets (target is my filename, after the commer as stated in the constructor there shlould be (encoding As System.text.Encoding) but i don't need that)
So, i am not sure how to place the codes such that it will write to my xml file using the xmlwriter or xmltextwriter.... :cry:
Thanxs 4 helping...
:)
Re: unable to write to file
there is no need for encoding, all you need to do is pass "Nothing" into it.
here is a sample
VB Code:
Try
Dim l_xmlWriter As New XmlTextWriter(p_file, Nothing)
l_xmlWriter.Indentation = 1
l_xmlWriter.Formatting = Formatting.Indented
l_xmlWriter.WriteStartDocument(True)
l_xmlWriter.WriteComment("Created: " & Date.Now.ToString)
l_xmlWriter.WriteStartElement("Config")
l_xmlWriter.WriteStartElement("DeviceLocations")
l_xmlWriter.WriteStartElement("HHImport")
l_xmlWriter.WriteAttributeString("Value", p_settings.HandheldImportDirectory)
l_xmlWriter.WriteEndElement()
l_xmlWriter.WriteStartElement("HHExport")
l_xmlWriter.WriteAttributeString("Value", p_settings.HandheldExportDirectory)
l_xmlWriter.WriteEndElement()
l_xmlWriter.WriteEndElement() 'End Device Locations
l_xmlWriter.WriteStartElement("ServerLocations")
l_xmlWriter.WriteStartElement("PCImport")
l_xmlWriter.WriteAttributeString("Value", p_settings.PCImportDirectory)
l_xmlWriter.WriteEndElement()
l_xmlWriter.WriteStartElement("PCExport")
l_xmlWriter.WriteAttributeString("Value", p_settings.PCExportDirectory)
l_xmlWriter.WriteEndElement()
l_xmlWriter.WriteEndElement() 'End Server Locations
l_xmlWriter.WriteEndDocument() 'end node
l_xmlWriter.Close()
Catch ex As IO.IOException
Throw New Exception(ex.Message)
Catch ex As XmlException
Throw New Exception(ex.Message)
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
Re: unable to write to file
Why have you got so many catch in there?
you trying to catch a fish? ;)
Re: unable to write to file
ok..thanxs 4 the sample codes..i got the picture of how it works...
:)
Re: unable to write to file
Quote:
Originally Posted by dinosaur_uk
Why have you got so many catch in there?
you trying to catch a fish? ;)
sorry dude, must have got carried away
its a bit of overdosing on catches alright
Re: unable to write to file
lol....
anyway.....isn't try and catch strongly discouraged because it uses up alot of resources?
Re: unable to write to file
never knew that is used up so much resources i've seen how something it can take a while for it to throw the exception alright
i generally use then a lot with files because i always find that there is always some error with some data in them
really there should only be one catch in the code above....