3
I have an application that works based on the client’s current process. I need to get the name of the file and its absolute path when opened. That is to say:
If for example the client opens the "test.txt" file, 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 Process class it is possible to acquire the file path that is being worked?
The execution environment only has information about the process, not about files the application is manipulating. This is the context of the application, not the process. What object do you have to manipulate the file?
– MFedatto