Solved

Help with choosing path to save file

Posted on 2014-04-25
7
360 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now