C# - Open/Save file Dialog

By , 12/27/2012
(0 ratings)
Displays an Open/SaveFileDialog using filetype filters.

Author: Jan Welker, translation by Michael List
Translate to VB
/// <summary>
/// Shows an OpenFileDialog
/// </summary>
/// <returns>Path of the file to be opened</returns>
private string openFile()
{
    string path = string.Empty;
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "Textfiles (*.txt)|*.txt|All files (*.*)|*.*";
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
        path = openFileDialog1.FileName;
    return path;
}

/// <summary>
/// Shows a SaveFileDialog
/// </summary>
/// <returns>Path where the user wants the file to be saved to</returns>
private string saveFile()
{
    string path = string.Empty;
    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
    saveFileDialog1.Filter = "Textfiles (*.txt)|*.txt|All files (*.*)|*.*";
    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        path = saveFileDialog1.FileName;
    return path;
}

Comments

 

Log in, to comment!