By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

How to get the current open file's path using C#

P: 2
Hi, all

I have a questions to obtain the current open file's path using C#.

And I try using the Process.GetProcesses().MainWindowTitle, it jsut get the opened file's name, not the opened file's path.

Dose anyone has any idea can help me to get the complete file path?

for example:

I'm open the "test.txt" in the "C:\Users\Public\TestFolder."

Now using the "Process.GetProcesses().MainWindowTitle" just can obtain the "test.txt", I have no idea to get the "C:\Users\Public\TestFolder."

Please help me.
Thanks in advance.
Apr 17 '12 #1
Share this Question
Share on Google+
2 Replies


Monomachus
Expert 100+
P: 127
Show us the code and by the way if it is about File and you use OpenFileDialog to choose the File than just use code sample below
Expand|Select|Wrap|Line Numbers
  1. OpenFileDialog ofd = new OpenFileDialog(); 
  2.  
  3. string filename = ""; 
  4. string path = ""; 
  5.  
  6.          if (ofd.ShowDialog() == DialogResult.OK) 
  7.          { 
  8.                     filename = System.IO.Path.GetFileName(ofd.FileName); 
  9.                     path = System.IO.Path.GetDirectoryName(ofd.FileName); 
  10.          } 
  11.  
  12.          MessageBox.Show(filename, "Filename"); 
  13.          MessageBox.Show(path, "Directory");
Apr 17 '12 #2

P: 2
Hi,

Sorry, I don't describe clear.
I'm open the file "test.txt" manual (click the mouse left button twice) and want to detect the opened file's path by programming.

Thanks in advance.
Apr 17 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.