Solved

Help with choosing path to save file

Posted on 2014-04-25
7
364 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Numbers in JQuery file 11 66
Upgrading my SSIS package in VS 2012 6 62
Looping through datagridview and dataset ? 6 24
Visual Studio npm 1 12
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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