Results 1 to 6 of 6

Thread: OpenFileDialog & DataSets

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    5

    Question OpenFileDialog & DataSets

    I have a problem with using the OpenFileDialog object and datasets. Whenever I use the OpenFileDialog when the application is in run mode, it will change the current working directory of all datasets in use. So if I use a relative path when reading an XML file into the dataset, that path will change to the last folder browsed using the OpenFileDialog. This will cause an error when I go to use dataset.WriteXml() because the path has changed. Can someone please tell me a work around for this problem?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    First off, I find it very strange that the CommonDialog would have an effect on a dataset. Can you post some code so that I can try it out here?

    Second, the .WriteXML() method can take a filename argument which can contain the path, so that you can specify where to write it.

  3. #3
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    This is probably because the dialog changes the current directory in windows, thus all relative paths are changed.

    There's a property on the dialog called "RestoreDirectory".
    If I understand correctly, setting this property to TRUE would cause the dialog to change the directory back when closing.

    I hope this is what you need.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    5
    Hi, thanks for the help but it is still causing the same error even when using RestoreDirectory = True

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hmmm, strange...

    Well instead of using relative paths maybe you should use absolute.

    Like this
    VB Code:
    1. MyAbsolutePath=IO.Path.Combine(Application.StartupPath,MyRelativePath)
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    5
    Yes that method works, thanks for your help. I still cannot understand why the error occurs in the first place though!

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