views:

66

answers:

3

Respected Sir,
my Question is that when I am Opening my txt file i.e abc.txt so I want to get full path of only running or opening file in my computer I have done this

Process prs=Process.GetProcessByName("notepad");
foreach(Process p in prs)
{
     p.Modules[0].FileName.ToString();
}

Which is giving me Notepad.exe path. I want my text file path like D:\abc.txt so i can get this.

Thank You

+2  A: 
string fullPath = Path.GetFullPath(strFileName);
0xA3
A: 

For notepad, you can get the name of the file like this:

Process[] prs = Process.GetProcessesByName("notepad");
foreach (Process p in prs)
{
    string title = p.MainWindowTitle;
    Console.WriteLine(title.Substring(0, title.IndexOf('-') -1));
}

The important part being:

title.Substring(0, title.IndexOf('-') -1)

Unfortunately this won't get you the full path.

Matt Ellen
+1  A: 

You could attach FileSystemEventHandler and check which files are opened, or changed.

Maybe this will help

http://www.codeguru.com/csharp/csharp/cs_network/article.php/c6043

Michal Franc