Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I am creating an application that would keep a track of how much time is spent on every file.

Example:-
https://www.dropbox.com/s/bcocp5stn0pzvwe/Untitled.png?dl=0[^]

above is the image of the problem i am facing. now what i need here is i want the current or active file which is Program.cs file's location.

Till now i googled and was only able to find an answer which did not work for me Answer found after googling.please help by sending a code snippet


Thanks in advance
Posted
Updated 6-May-15 7:06am
v2
Comments
Sergey Alexandrovich Kryukov 6-May-15 15:04pm    
There is no such concept as "active file". The whole think makes no sense.
Why? why?!
—SA
agent_kruger 6-May-15 15:46pm    
sir what i am asking for that if my focus is on program.cs i can get the location of that and if my location is form1 then i should get location of form1. now is it clear?
Sergey Alexandrovich Kryukov 6-May-15 16:42pm    
I don't understand why. Do you mean that your file in on top during the working session of VS? But what's the difference what is there and how long it takes to stay there?
—SA
agent_kruger 8-May-15 9:35am    
i need to get the file's location where i am currently working on ("Program.cs" as in the image) from the visual studio instance.
Sergey Alexandrovich Kryukov 8-May-15 10:15am    
And isn't that enough to see this location? VS shows it... You did not explain why.
—SA

1 solution

There's no such thing as an "active file" in any sense of what you're saying.

If you're talking about if the file in Visual Studio is being actively changed in the code editor, you're really not going to get anything reliably accurate. I can have as many as 15 files open at a time and making changes to all of them. So are you going to say that the 4 seconds I spend in one editor window, then change to another window for 5 seconds, and another for another few seconds, ..., is going to count for something?

That's meaningless.
 
Share this answer
 
Comments
agent_kruger 7-May-15 11:26am    
sir, at the current stage i mean to get all files location that are opened in the current "Visual Studio 2008" or "devenv.exe". For example we take the image in question. there are 2 files opened "Program.cs" and "Form1.cs". i need to get location of the file which is active viz. "Program.cs".
Dave Kreskowiak 7-May-15 11:29am    
Are you writing a Visual Studio plugin/extension?
agent_kruger 8-May-15 9:33am    
no, i am writing in windows form (i know windows form will be "visible=false" the whole time but need some features of it) and will act as a service as soon as the computer is switched on.
Dave Kreskowiak 8-May-15 9:43am    
Well, that makes it extremely difficult to write because there is way to tell which process has a file open in an editor. When Visual Studio has a file open in an editor, it opens the file on disk, reads it and closes it. The file is not held open so there is no way for your code to determine if the file is being worked on.

You have to constantly poll the handle table to see which processes are opening which files. The problem with what you're doing is that you cannot determine why the file was opened. There is no way for you to determine which file "is being worked on".

Again, you're trying to do something that is completely worthless as a data point in process tracking.
agent_kruger 8-May-15 13:57pm    
see the link i searched on google and see if you can help me out with that code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900