Windows Develop Bookmark and Share   
 index > Windows Forms General > Open directory with C#
 

Open directory with C#

How can i open a file directory with through Windows Explorer with C#?I mean i know how to open the Windows Explorer but the default directory is my documents.I want to be different directory...How to do this?
vendir  Wednesday, April 11, 2007 3:51 PM
Try something like this:

string path = @"c:\";
System.Diagnostics.Process.Start(path);

nobugz  Wednesday, April 11, 2007 4:39 PM

Use the OpenFile Dialog to open files.

Something like this:

OpenFileDialog dlgOpenReciprocityFile = new OpenFileDialog ( );dlgOpenReciprocityFile.InitialDirectory = @"C:\";

dlgOpenReciprocityFile.Filter = "text Files (*.txt)|*.txt|All Files (*.*)|*.*";

dlgOpenReciprocityFile.FilterIndex = 1;

dlgOpenReciprocityFile.RestoreDirectory = true;if ( dlgOpenReciprocityFile.ShowDialog ( ) == DialogResult.Cancel )

{

comboStateList.Visible = false;

this.labelCurrentStatus.Text = "Ready . . .";

ResetButtons ( true, false, true );

dlgOpenReciprocityFile.Dispose ( );

}

else

{

try

{

//* initialize the file path variable

fileControl.m_InFilePath = dlgOpenReciprocityFile.FileName; //* open the file

fi_inputFile = new FileInfo ( fileControl.m_InFilePath ); //* create a text reader

srReciprocityReader = fi_inputFile.OpenText ( );

}

catch

{

<your message box.show statements here>

}

insertthe aboveinto your button click method (using your own variable names).

Rhubarb  Wednesday, April 11, 2007 3:57 PM
Try something like this:

string path = @"c:\";
System.Diagnostics.Process.Start(path);

nobugz  Wednesday, April 11, 2007 4:39 PM

You can use google to search for other answers

Custom Search

More Threads

• Drawing/painting control
• Real World Applications
• Scrollbar Problem
• Newbie - Using Panels
• Tables in C#?
• Highlight border of a control on selection
• Graphics.drawString() looks terrible
• Validating event not fired
• Bug in VisualStudio - DesignerFrame
• copying one object to another,..