?
Solved

Help with choosing path to save file

Posted on 2014-04-25
7
Medium Priority
?
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

 
LVL 20

Accepted Solution

by:
ElrondCT earned 2000 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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

762 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