Created
August 1, 2018 16:13
-
-
Save Plus1XP/ca5da6432d1e8679115d4438d7d599ca to your computer and use it in GitHub Desktop.
WinForms Open/Save Dialogue Box
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
private void buttonLoadFile_Click(object sender, EventArgs e) | |
{ | |
OpenFileDialog ofd = new OpenFileDialog(); | |
ofd.Title = "Open File"; | |
ofd.Filter = "All Files (*.*)|*.*"; | |
textBoxName.Text = ofd.SafeFileName; | |
textBoxLocation.Text = ofd.FileName; | |
if (ofd.ShowDialog() == DialogResult.OK) | |
{ | |
byte[] saveData = File.ReadAllBytes(ofd.FileName); | |
//string saveFile = Encoding.Default.GetString(saveData); | |
string saveFile = Encoding.UTF8.GetString(saveData, 0, saveData.Length); | |
textBoxContents.Text = saveFile; | |
} | |
} | |
private void buttonSaveFile_Click(object sender, EventArgs e) | |
{ | |
SaveFileDialog sfd = new SaveFileDialog(); | |
sfd.Title = "Save File"; | |
sfd.Filter = "All Files (*.*)|*.*"; | |
if (sfd.ShowDialog() == DialogResult.OK) | |
{ | |
string file = textBoxContents.Text; | |
byte[] data = Encoding.UTF8.GetBytes(file); | |
File.WriteAllBytes(sfd.FileName, data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment