Post: [C#] Open and Save Dialogs [Snippet]
02-18-2011, 03:50 AM #1
Rath
Today Will Be Different
(adsbygoogle = window.adsbygoogle || []).push({}); Well I recently have seen quite a few people start coding C#... and also seen a bit of people using Visual Basic to make C# Windows Forms. So I thought I'd post a Snippet of my code to open and save files.

Open File
    private void Open_Click(object sender, EventArgs e)
{
string Chosen_File = "";

openFD.InitialDirectory = "C:";
openFD.Title = "Choose your FF";
openFD.FileName = "";
openFD.Filter = "FF Files|*.ff";

if (openFD.ShowDialog() == DialogResult.Cancel)
{
MessageBox.Show("You have cancelled the operation");
}
else
{
Chosen_File = openFD.FileName;
}
}


Save File
     private void button5_Click(object sender, EventArgs e)
{
string Chosen_File = "";

saveFD.InitialDirectory = "C:";
saveFD.Title = "Save your FF";
saveFD.FileName = "";
saveFD.Filter = "FF Files|* .ff";

if (saveFD.ShowDialog() == DialogResult.Cancel)
{
MessageBox.Show("You have cancelled the operation");
}
else
{
Chosen_File = saveFD.FileName;
}
}


Now you can change values here. As in what type of files you want to open. Your title. And your directory.

This is a disclaimer... also I wouldn't include where its says things like "Open_Click" etc. Since your's might be a menu strip etc.. And change my "openFD" to the name of you save directory etc.
Not sure if you guys know this, but you can change names of buttons etc. If you don't know how, I will show you if that problem arises.

Hope some people find this useful.
Last edited by Rath ; 02-18-2011 at 04:53 AM.

The following 2 users say thank you to Rath for this useful post:

arab707, TheSpoken

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo