Created
July 23, 2018 16:24
-
-
Save ranveeraggarwal/4b17b3789ae42bd6c38b108581f76937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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