Skip to content

Can't load XML File into DataGridView (VB.Net), please help

Rudi Chendra

Asked Feb 10, 2011, 5:52 PM EST4 answers
Share
LinkedInX
I generate my xml into "variable string str" by using "dataset.GetXml" and then I write the "xml which is contained in variable str" into "file.xml" by using "sFile.WriteLine(str) while 'sFile' is a stream reader"

My reason for using 'writeline' instead of 'dataset.WriteXml' because I need to encrypt the 'xml stored in 'str' before I store it into file.xml.

I got everything fine for the encrypted result, and so does the decrypted result as well.

Here's the decrypted result of my file.xml below (I have checked it the xml value which in str before encryption and which in decrypted file.xml. They are all match well)

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


        
                  Book 1
                 
                  2010-09-22T14:43:00.0000000+07:00
        



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

Here is my plain xml value before it got encrypted or decrypted which I stored it in variable str by using GetXml. I don't know for sure but my xml value doesn't contain declaration "" like common xml used to have.

All the xml file which I got from GetXml is just like below (No declaration like )


        
                  Book 1
                 
                  2010-09-22T14:43:00.0000000+07:00
        





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


And since I think it may not cause any problem then I keep coding and decrypt it which is going well and the decrypted result is perfectly same ofcourse.

My problem is, when I try to make my xml value show in Data GridView by using the code below, and run the debug, it prompt an error said "could not find the file c:\bla\File.xml ". Please help and thanks for any reviewing or suggestion too.

ds = New DataSet
path = System.IO.Path.GetFullPath(strFileToDecrypt)
ds.ReadXml(path)
DGV.DataSource = ds

(strFileToDecrypt is string which stored ".FileName" from SaveFileDialog)

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    After, I hurry in my effort, I got my own solving way which really working good. I never think to answer it mayself until I make a message box this is it just now and I got the answer hore. My problem just in the path and here's my code which worked. xmlDatadoc = New XmlDataDocument path = System.IO.Path.GetFullPath(pk) MsgBox("Ini Dia" & path) xmlDatadoc.DataSet.ReadXml(path) ds = New DataSet ds = xmlDatadoc.DataSet DGV.DataSource = ds.DefaultViewManager Happy to solve it.^^
    0
  • 0
    Finally, I got my own working path worked.^^ You know, since I changed the name of the xml file after encryption, I forget to use the same name for decryption. But know I got it, I called it a day.^^
    0
  • 0
    Thanks for helpful source. It's really a big help. thanks again.
    0