Jul 19, 2011

SaveFileDialog in C# windows application

c#.net code to save an xml file using SaveFileDialog control but the xml i already been created i just want to save the xml file by opening the file dialog box on click of a button.


hi,
just try this...

// Create new SaveFileDialog object
SaveFileDialog DialogSave = new SaveFileDialog();

// Default file extension
DialogSave.DefaultExt = "xml";

// Available file extensions
DialogSave.Filter = "Text file (*.txt)|*.txt|XML file (*.xml)|*.xml|All files (*.*)|*.*";

// Adds a extension if the user does not
DialogSave.AddExtension = true;

// Restores the selected directory, next time
DialogSave.RestoreDirectory = true;

// Dialog title
DialogSave.Title = "Where do you want to save the file?";

// Startup directory
DialogSave.InitialDirectory = @"C:/";

// Show the dialog and process the result
if (DialogSave.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("You selected the file: " + DialogSave.FileName);
}
else {
MessageBox.Show("You hit cancel or closed the dialog.");
}

DialogSave.Dispose();
DialogSave = null;

Hope this may help you...


No comments:

Post a Comment