Solved

File Choosers in C# Window Applications

Posted on 2004-10-04
3
535 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Advice on Xojo as a development tool over VB. 4 90
Android development question 2 109
programming a polycom voip phone 3 84
Oracle programming for starter 14 75
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 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