Results 1 to 4 of 4

Thread: Can't seem to open XML file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203

    Can't seem to open XML file

    xmlFileName = "c:\ghana.xml"
    Dim FsXML As New FileStream(xmlFileName, FileMode.Open)

    I have tried giving it all sorts of paths for file names, but It just can't find the file\ directory

    stuff I've tried

    xmlFileName = "ghana.xml"
    xmlFileName = "\ghana.xml"
    xmlFileName = "\..\ghana.xml"
    I've tried putting the XML file in the solution folder, in the root C Folder and all...but I guess Im missing out on something.
    thanks
    Udit

  2. #2
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Can't seem to open XML file

    1.first of all if your are readin and writing to XML use the XmlTextWriter and XmlTextReader classes.

    2. are you trying to find the file on you device. or on a pc. if you are looking for a folder on the device its simple file.

    Dim myXmlWriter As XmlTextWriter
    myXmlWriter = New XmlTextWriter("\My Documents\TestFolder\myxml.xml", Nothing)
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203

    Re: Can't seem to open XML file

    Right Now, Im trying to run the program on the emulator. Im actually using the XMLTextReader and XMLTextWriter Classes to get data from a form and put it into an XML file..Im using this Quickstart example:

    VB Code:
    1. ' Set file names and create file streams.
    2. ' The XSD, XML, and EXE must be in the same directory.
    3. statesDS = New DataSet
    4. xmlFileName = "\program files\databindingdemo\states.xml"
    5. xsdFileName = "\program files\databindingdemo\states.xsd"
    6. Dim FsXML As New FileStream(xmlFileName, FileMode.Open)
    7. Dim FsXSD As New FileStream(xsdFileName, FileMode.Open)
    8.  
    9. ' Load the schema into the DataSet.
    10. Dim xtrXSD As New XmlTextReader(FsXSD)
    11. statesDS.ReadXmlSchema(xtrXSD)
    12. xtrXSD.Close()
    13. FsXSD.Close()
    14.  
    15. ' Load the data into the DataSet.
    16. Dim xtrXML As New XmlTextReader(FsXML)
    17. statesDS.ReadXml(xtrXML)
    18. xtrXML.Close()
    19. FsXML.Close()
    20.  
    21. ' Get a DataTable to conveniently use for binding.
    22. Dim dt As DataTable = statesDS.Tables("state")
    23.  
    24. 'Bind the list box to state abbreviations.
    25. lstState.DataSource = dt
    26. lstState.DisplayMember = "abv"
    27.  
    28. 'Bind the label to show the name of the state.
    29. lblState.DataBindings.Add(New Binding("Text", dt, "name"))
    30.  
    31. 'Bind the text box for entering data.
    32. txtData.DataBindings.Add(New Binding("Text", dt, "data"))

    1) firstly, why can't I hardcode a path such as c:\states.xml
    2) secondly, Since I'm not deploying the solution right now, what relative path do I give....Im doing the following right now

    VB Code:
    1. Dim xtrXSD As New XmlTextReader("\My Documents\Visual Studio Projects\SmartDeviceApplication5\states.xsd")
    2.         statesDS.ReadXmlSchema(xtrXSD)
    3.         xtrXSD.Close()

    I'v also tried
    ("\My Documents\Visual Studio Projects\SmartDeviceApplication5\bin\states.xsd")

    and

    ("\My Documents\Visual Studio Projects\SmartDeviceApplication5\obj\states.xsd")


    It still doesnt work

  4. #4
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Can't seem to open XML file

    1. You realise that their is no such directory called C:\ on the device. This path only exists on PCs never on devices. Locations on devices are of the form \Programs Files\some folder or \My Documents\some folder

    2. Since you are using it on the emulator you give it any of the locations available on the emulator. These folders NEED to exist before you can write to the so you need to use Directory class and the create/new method.

    so example
    system.io.directory.create("\My Documents\My New Folder\")
    Dim xtrXSD As New XmlTextReader("\My Documents\My New Folder\states.xsd")
    statesDS.ReadXmlSchema(xtrXSD)
    xtrXSD.Close()
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width