Skip to content

Instantly share code, notes, and snippets.

@ranveeraggarwal
Created July 23, 2018 16:24
Show Gist options
  • Save ranveeraggarwal/4b17b3789ae42bd6c38b108581f76937 to your computer and use it in GitHub Desktop.
Save ranveeraggarwal/4b17b3789ae42bd6c38b108581f76937 to your computer and use it in GitHub Desktop.
public static void WriteToFile(string writeData, string fileExtension)
{
string defaultExtension, extensionFilter;
switch (fileExtension)
{
case "json":
defaultExtension = "json";
extensionFilter = "json files (*.json)|*.json";
break;
default:
defaultExtension = "txt";
extensionFilter = "text files (*.txt)|*.txt";
break;
}
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog
{
Title = "Select Destination File",
DefaultExt = defaultExtension,
Filter = extensionFilter
};
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string fileName = saveFileDialog.FileName;
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
{
file.WriteLine(writeData);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment