Solved

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

Posted on 2004-08-15
5
571 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 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