Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding a dialogopen windows form refence to my C# console application

Posted on 2004-08-15
5
Medium Priority
?
580 Views
Last Modified: 2008-02-01
Hi
on making a part of my console application I wanted to add a OpenFileDialog to it
I alread chose new Console Application from the C# projects window.
I typed:
using System; // (this was already typed)
using System.Windwos.Forms;

then  afterward nomatter what else
OpenFileDialog dlgOpen = new OpenFileDialog

there came a compilation error and the System.Windows.Forms wasn't imported. I copied and pasted the same code on notepad and compiled the file with csc commad line compiler , everything worked well !!! That got me mad.
I checked the help and it clued me to add reference to what I wanted. I want somebody to tell me how exactly I can do that and the file name of the required reference or dll . I wanted to use VS.net interface for wrtiting my code coz the notepad is highlty annoying to me.


0
Comment
Question by:drtoto82
[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
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
shovavnik earned 100 total points
ID: 11805027
First of all, your second using statement is misspelled.  (System.Windows.Forms and not System.Windwos.Forms)

If that's just a typo here, then in VS.NET:

Open your project.
In the Solutions Explorer, expand your Project, then right-click "References", and click "Add Reference".
In the .NET tab, select System.Windows or System.Windows.Forms (can't remember the exact dll name - it's one or the other).
Confirm.
Compile.
0
 
LVL 3

Assisted Solution

by:bigjim2000
bigjim2000 earned 100 total points
ID: 11805717
First add a reference to System.Windows.Forms

Then use the following code:
using System;

namespace ConsoleOpenDialog
{
      class ConsoleDialog
      {
            private static System.Windows.Forms.OpenFileDialog dlgOpenFile;

            [STAThread]
            static void Main(string[] args)
            {
                  dlgOpenFile = new System.Windows.Forms.OpenFileDialog();      
            
                  dlgOpenFile.ShowDialog();

                  string fileName = dlgOpenFile.FileName;

                  Console.WriteLine(fileName);

                  Console.WriteLine("\n\nHit enter to continue...");
                  Console.ReadLine();
            }
      }
}


That should give you what you are looking for :-)

-Eric
0
 
LVL 3

Expert Comment

by:bigjim2000
ID: 11805727
Sorry, I forgot to mention how to add a reference.

In visual studio, just right click on the references folder for your project, then select "Add Reference...".  Then scroll down to System.Windows.Forms.dll, and double click that and hit ok.

-Eric
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project

705 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