I have an application that works based on the current client process. I need to get the filename and its absolute path when opened. That is:
If for example the client opens the file "test.txt", I need to get the path "c: \ project \ test.txt" instead of "c: \ windows \ system32 \ notepad.exe". The same goes for .DOC, .XLS, etc ...
The code snippet below returns the process-related information, which includes the software path (... \ notepad.exe).
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int GetForegroundWindow();
[...]
public static string GetFilePathName()
{
uint procId = 0;
int hWnd = GetForegroundWindow();
GetWindowThreadProcessId(hWnd, out procId);
var proc = Process.GetProcessById((int)procId);
}
Through the class of the Process is it possible to acquire the path of the file being worked?