Solved

File Choosers in C# Window Applications

Posted on 2004-10-04
3
540 Views
Last Modified: 2010-04-17
I am new to C# windows programming. I would like to knowhow to use a drop down menu, IE "File -> Open..." to open a file chooser dialog?
Thank you
James Lawson
0
Comment
Question by:jameslawson976
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
erin010 earned 50 total points
ID: 12265300
//adding a menu object to your project will create code similar to the following:
            private System.Windows.Forms.MainMenu mainMenu1;
            private System.Windows.Forms.MenuItem menuItemFile;
            private System.Windows.Forms.MenuItem menuItemNew;
            private System.Windows.Forms.MenuItem menuItemOpen;
//------------------------------------------------------------------------------------------

private string m_strFileName = "";

/Hold the DialogResult enum result
//Ok or Cancel
private DialogResult dlgResult;

private void menuItemOpen_Click(object sender, System.EventArgs e)
{

    // dlgOpenFile is an OpenFileDialog object
    dlgResult = dlgOpenFile.ShowDialog();
    if(dlgResult == DialogResult.Cancel)
        return;

    try
    {
                // get the file name
        m_strFileName = dlgOpenFile.FileName;
                // open to read that file
        StreamReader sr = new StreamReader(m_strFileName);
                //read the whole file
        txtBody.Text = sr.ReadToEnd();
        sr.Close();
        m_bModified = false;
    }
    catch(Exception err)
    {
        MessageBox.Show(err.Message,"Error",
                         MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
}
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question