Hi all...

How to get the full path of a file which is currently running?? suppose from cmd or directly someone starts an application or any kind of file( text file, word file, mp3 etc) my C# application need to get the path of the opened file... For eg: if someone opens c:\dir\a.txt , then my C# program need to get that path directly...??? How to do that???

Plz help me ....

Application.ExecutablePath - Get the path of executable file that started the application.

See.. i dnt need the path of my C# application.... i need the full path of the other running processess... suppose if i opened a text file or a word file then since my C# application is working in background , this pgm must get the path of the opened text file...

private void button2_Click(object sender, EventArgs e)
    {
      foreach (Process p in Process.GetProcesses())
      {
        string procFile;
        try
        {
          procFile = p.Modules[0].FileName;
        }
        catch (Win32Exception)
        {
          procFile = "n/a";
        }
        Console.WriteLine(string.Format("Process {0}: {1}", p.ProcessName, procFile));
      }
    }

If you open a text file with notepad then this happens:

  • Notepad.exe opens
  • notepad opens your text file
  • notepad reads the text file in to memory
  • notepad closes the text file
  • notepad sits there waiting for user interaction

You can use the win32 API to see what files a process has open, but it won't give you the information you want in every case.

open task manager, you dont need c# to see process execution paths.

serkan -- I think windows only started showing execution paths in Vista and later operating systems. AFAIK you can't see that information in XP with the task manager.

I use SIW for all process inspection tasks and various other windows issues. You can tell what proc has what files open, what libraries, what proc is listening on what port, see named pipes, and many other things.

Upgrade to Vista then :)

No thanks :P I'll wait on windows 7 to mature!

there is a microsoft event in miami on 24th of september, they are giving away free windows 7 license to attendees. the registration is free from microsoft website. i was going to go with coworkers but i am too lazy to install it to my laptop. i want to stay with vista for another year unfortunately.
it is 4:30 am dude, you gotta sleep.

My day begins at 2am, Its time to work! I work 7 days a week :(. I have classes during the day on most days so I get in early and get most of my work done before people get in the office and it gets crazy.

Hello, in addition to what this thread was about I was wondering if it's possible for a C# application to know what application is active. Suppose I have opened a .doc, .xls, .mdb, .ppt and I move from to another by Alt+Tab or click on the taskbar. Can I know to which one I moved to, when I moved to it?
Thanks

Hello, in addition to what this thread was about I was wondering if it's possible for a C# application to know what application is active. Suppose I have opened a .doc, .xls, .mdb, .ppt and I move from to another by Alt+Tab or click on the taskbar. Can I know to which one I moved to, when I moved to it?
Thanks

You should create your own thread to ask questions, not append them to someone elses'.

sorry, im not getting dat... still im getting only the path of the notepad.exe ie c:\windows\systm32 not the path of the opened notepad..!!!!!

Listen if you open notepad.exe, then you open "File.txt" it opens the file -- reads it in to memory -- and closes it. The file does not remain open thus you cannot find it. What are you really trying to do here?

Some applications like Word will hold a lock on the file I believe.

See.. i dnt need the path of my C# application.... i need the full path of the other running processess... suppose if i opened a text file or a word file then since my C# application is working in background , this pgm must get the path of the opened text file...

It occurred to me, because this thread has not been marked SOLVED, you might be trying to figure out what process has a file open: investigating who has my file locked

@sknake
You said very weel:

If you open a text file with notepad then this happens:

  • Notepad.exe opens
  • notepad opens your text file

I want to find out what is the path of the TextFile opened with the NotePad. Is this posible?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.