Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with choosing path to save file

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
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

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.
Avatar of Victor  Charles

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

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

Victor
If System.IO.File.Exists(strFileName)
Thanks