C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Winforms Controls »

Save File Dialog Control


Posted Date: 09 Apr 2009    Resource Type: Code Snippets    Category: Winforms Controls
Author: Deepika HaridasMember Level: Diamond    
Rating: 1 out of 5Points: 6



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;

try
{
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);
sw.Write(txtFileContents.Text);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, this.Text);
}
finally
{
if (sw != null)
{
sw.Close();
}
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Winforms  .  Saving file  .  Save file dialog  .  Dialog boxes  .  Controls  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Open a new window by button click in parent form in winforms application
Previous Resource: Get the Text of Dynamically Created Text Box
Return to Discussion Resource Index
Post New Resource
Category: Winforms Controls


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use