Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I'm trying to create an add-in for Visual Studio 2012 and I'm stuck. So here's where I'm stuck.

Let's say in Visual Studio I'm working on a file. Assume it's called Default.aspx . My add-in works like this: When you press the button on the toolbar, it will copy everything on the file to a string variable and do some stuff with it.

So which function can I use to find the path of the current open file? I could have 4-5 tabs open in visual studio but I only want to find the path of the file which is currently being worked on which would be Default.aspx in this context. Is there a way to do this?
Posted
Updated 2-Jul-13 22:21pm
v2

You want to use the application parameter, cast as an _DTE class:
C#
applicationObject = (_DTE)application;

You can then use the ActiveDocument[^] Property.


"Couldn't really understand your answer could you elaborate?"

When you write an addin, VS calls your method, and provides a number of parameters: one of these is the application as an object.
(see this, it might help: How to Create a Visual Studio Add-in that Launches from the Project Window[^])

You need to cast that object to a _DTE, and you can then access the ActiveDocument property - should give you access to your Default.aspx file.
 
Share this answer
 
v2
Comments
Cardslash 3-Jul-13 7:19am    
Couldn't really understand your answer could you elaborate?
Cardslash 3-Jul-13 7:33am    
Okay nevermind! I solved it thanks a lot!
OriginalGriff 3-Jul-13 7:38am    
:laugh: While I was updating the answer!
Well done! :thumbsup:
If you are using Desktop application you can try
var lstFormCollection = Application.OpenForms;--Will return all active page


In web
string currentPageFileName = new FileInfo(this.Request.Url.LocalPath).Name;
----Will return current page only
 
Share this answer
 

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