Solved

Help with choosing path to save file

Posted on 2014-04-25
7
361 Views
Last Modified: 2014-04-26
Hi,

I'm using the code below to save my xml file to a specific path. How do I modify the code
to open a dialog box and give the users option to save the file in the path they choose.

        dtsetFiles.WriteXml(Application.StartupPath & "\LinkFiles\LinkFinal" & Trim(LoginForm1.username.Text) & ".xml")

Thanks,

Victor
0
Comment
Question by:vcharles
  • 4
  • 3
7 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 40024062
If you're not giving them an option for the file name, but just the path, then you should use the FolderBrowserDialog control to open a browse window to navigate to the folder the user wants.

Please note that if you normally install your application in the C:\Program Files folder tree, you should not store any files that are going to change in the installation folder or a subfolder. As of Windows 7, this folder tree is locked down, and you have to provide administrator privileges in response to User Access Control any time you want to make a change. It's better to use a folder like C:\ProgramData (take a look at My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData, though you may want to strip off the application version number from the end), with the caveat that it's a hidden folder by default, so that can make it harder to find the files--that could be a benefit or a drawback.
0
 

Author Comment

by:vcharles
ID: 40024087
Hi,

Thanks for the information. the code creates the filename with code below (i.e. LinkFinalBEL.xml), I  need to open a dialog box to give the user an option where to save it.

dtsetFiles.WriteXml(Application.StartupPath & "\LinkFiles\LinkFinal" & Trim(LoginForm1.username.Text) & ".xml")

Victor
0
 

Author Comment

by:vcharles
ID: 40024594
Hi,

After saving the data to my application's folder, how do I open a dialog box with the filename already included so users can choose another location to save it,

Victor
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 40025218
Create the FolderBrowserDialog control by double-clicking on the FolderBrowserDialog item in the designer toolbox. It appears in the box below the form. In your code, you can set it up and open it like this:
        FolderBrowserDialog1.SelectedPath = Application.StartupPath & "\LinkFiles"
        Dim dlgResult As DialogResult
        dlgResult = FolderBrowserDialog1.ShowDialog()
        If dlgResult = DialogResult.OK Then
            System.IO.File.Copy(Application.StartupPath & "\LinkFiles\LinkFinal" & Trim(LoginForm1.username.Text) & ".xml", _
                FolderBrowserDialog1.SelectedPath & "\LinkFinal" & Trim(LoginForm1.username.Text) & ".xml")
        End If

Open in new window

This is set up to simply continue on if someone clicks Cancel on the dialog box. You might want to have a separate test for a DialogResult.Cancel.
0
 

Author Comment

by:vcharles
ID: 40025309
Hi,

Thanks for the code. How do you test if the file exist before you execute the code.

Victor
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 40025376
If System.IO.File.Exists(strFileName)
0
 

Author Comment

by:vcharles
ID: 40025389
Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question