.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

SaveFile Dialog Box

Posted By:Deepika Haridas       Posted Date: September 28, 2009    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

The code will demonstrate how to use the Save File Dialog Box to Save a File

private void btnSaveTextFile_Click(object sender, System.EventArgs e)
StreamWriter sw = null;

sdlgTextFile.AddExtension = true;

// Check to verify that the output path
// actually exists. Prompt before
// creating a new file? Prompt before
// overwriting?
// The default is true.

sdlgTextFile.CheckPathExists = true;

// The default is false.

sdlgTextFile.CreatePrompt = false;

// The default is true.

sdlgTextFile.OverwritePrompt = true;

// The default is true.

sdlgTextFile.ValidateNames = true;

// The default is false.

sdlgTextFile.ShowHelp = true;

// if the user doesn't supply an extension,
// and if the AddExtension property is
// true, use this extension.
// The default is "".

sdlgTextFile.DefaultExt = "txt";

// Prompt with the current file name
// if you've specified it.
// The default is "".

sdlgTextFile.FileName = FileName;

// The default is "".

sdlgTextFile.Filter = "Text files (*.txt)|*.txt|" + "All files|*.*";
sdlgTextFile.FilterIndex = 1;

if (sdlgTextFile.ShowDialog() == DialogResult.OK)
FileName = sdlgTextFile.FileName;

sw = new StreamWriter(FileName);
catch (Exception exp)
MessageBox.Show(exp.Message, this.Text);
if (sw != null)


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend