Solved

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

Posted on 2004-08-15
5
576 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 25 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 25 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Part One of the two-part Q&A series with MalwareTech.
Introduction to Processes
Starting up a Project

628 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