Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save file dialogue

Status
Not open for further replies.

MJV57

Programmer
Apr 18, 2009
87
CA
I have a button that I want to have open a dialogue box to select a file and then rename it and save it in a specific directory. I have the following code which opens a dialogue box but it is not setting the pick directory and when I try to save it tries to save in the same directory as the file I picked.


private void attachfileBN_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.ShowDialog();
sfd.InitialDirectory = "C";
sfd.FileName = "//server1/common/estimatedocs/estimatenoTextBox.Text";

}
 
You're setting the value for the initial directory after you've displayed the dialog box (your code won't get control back until the dialog box is closed after you call sfd.ShowDialog();). You've also not included the code for saving the file, I imagine that you're getting the message that the file exists already? This is catered for in the code below (which should help you on the right track):
Code:
SaveFileDialog sfd = new SaveFileDialog();
            
            sfd.InitialDirectory = "C:\\";

            sfd.OverwritePrompt = false;

            if (sfd.ShowDialog() == DialogResult.OK)
            {

                string Filename = sfd.FileName;
                string NewFile = "//server1/common/estimatedocs/" + estimatenoTextBox.Text;

                // your code to save the file goes here

            }

            sfd.Dispose();
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top