Solved

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

Posted on 2004-08-15
5
555 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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.
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.
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…

832 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