Solved

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

Posted on 2004-08-15
5
533 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
EvenOdd challenge 10 81
endX challenge 2 48
mapBully challenge 6 88
C# DataGridView_RowsAdded event not firing 1 36
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now