Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > How to get the directory (folder) on which user has done right click
 

How to get the directory (folder) on which user has done right click

Hello,

I have developed one application, and added it to right click pop-up menu of the folder.

Whenever user right-clicks on folder and selects my application from pop-up menu, I want the path to that folder (on which user has done right click).

I am using Directory.GetCurrentDirectory(), but it gives me path to the parent directory of the user right clicked directory.

How can I get the path to the directory on which user has done right click?

Regards
Abhishek
Kulabhishek  Monday, February 23, 2009 5:57 AM

Hi Kulabhishek,

I don't know how you can open a folder with right click. I have done such case to right click a file to open with my own application. In achieve this, I should modify the Main method.

The Main method in a Winform application does not have any parameter, I should change it to "static void Main(string[] args)" just like it in a console application. When I right click a file to open it, the full name of the file will be transmitted to the Main method. Use this code

if(args.Length>0)
{
MessageBox.Show(args[0]);
}


You can get the path and file name.

[STAThread]
staticvoidMain(string[]args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if(args.Length>0)
{
//Getthepathandfilename
MessageBox.Show(args[0]);
}
Application.Run(newForm6());
}

As for the "Directory.GetCurrentDirectory()" method. The current directory is distinct from the original directory, which is the one from which the process was started. So it always show the parent folder.

If I misunderstand something, please feel free to tell me.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, February 25, 2009 3:18 AM

Hi Kulabhishek,

I don't know how you can open a folder with right click. I have done such case to right click a file to open with my own application. In achieve this, I should modify the Main method.

The Main method in a Winform application does not have any parameter, I should change it to "static void Main(string[] args)" just like it in a console application. When I right click a file to open it, the full name of the file will be transmitted to the Main method. Use this code

if(args.Length>0)
{
MessageBox.Show(args[0]);
}


You can get the path and file name.

[STAThread]
staticvoidMain(string[]args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if(args.Length>0)
{
//Getthepathandfilename
MessageBox.Show(args[0]);
}
Application.Run(newForm6());
}

As for the "Directory.GetCurrentDirectory()" method. The current directory is distinct from the original directory, which is the one from which the process was started. So it always show the parent folder.

If I misunderstand something, please feel free to tell me.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, February 25, 2009 3:18 AM

You can use google to search for other answers

Custom Search

More Threads

• 3-tier architecture code sample for c#.net
• Trouble with <Null> values in Date Fields
• Movie Collection Kit - Need Help
• how to create those dataset class files in web services?
• Insert/Update/Delete record with DataGridView... Plz Help!!!!
• Building a windows form application to import .wma files from digital voice recorder device
• 16 bit Windows Subsystem
• CImage Capture on Internet Explorer after
• TaskVision and Replication
• WebService tickets