Opening a file from TFS using the full TFS Path, from a web site

So I have a website running that displays full path of a TFS File on the page somewhere, I want the user to be able to click on it, which should then open up that file from TFS inside their Visual Studio.

The command to do this inside Visual Studio is "File.TfsOpenFromSourceControl" (DTE command) - it's basically the user manually going to that file using the Source control explorer and double clicking to open it up.

I am wanting to simulate that action from my web app inside the browser.

Update: The Web app is a pure ASPNet MVC app with Jquery available to it. I am already showing the file's content to the user in the web app. But I want the user to open the same file in Visual studio, by clicking on the file path in the web app. The question is more of Browser to VS integration and how to execute the DTE command in question, from within the web app context of the browser.

Any clues would be helpful

13.10.2009 22:48:27
Do you mean that you want to display the contents of that file within the browser window (i.e. directly from TFS server)? Or do you want an URL that, when clicked, would launch VS and make it open the file?
Pavel Minaev 13.10.2009 23:09:42
No. Launch VS and open the file, if VS is not already open. Else open it in existing VS window
Vin 14.10.2009 14:40:33
1 ОТВЕТ
РЕШЕНИЕ

I don't know the answer to Pavel's question, so I'll sketch an outline of both solutions.

  • If you want to display the file inside the browser, call the Item.DownloadFile() API. NB: in 2008 SP1 there is another overload of this method that allows streaming into a memory buffer instead of writing directly to the filesystem. If you don't already work with Item objects directly, you can retrieve them via the GetItem() / GetItems() APIs.

  • If you want to make the file open in VS, there are a couple approaches. Perhaps your web app already includes the concept of local workspace(s) for the user, similar to Source Control Explorer. If so, you'd simply call Workspace.GetLocalItemForServerItem() to find the local path of the item, then ShellExecute it. (Or maybe pass it as a command line parameter to devenv.exe, if it's not natively associated with VS.) If not, you can either create a temporary workspace on behalf of the user, or use the same DownloadFile() API shown before; stream the contents to the client over a web service, save to disk, then launch VS as before.

Naturally, the more involved scenarios under option #2 will require deeper OS integration than the DOM / Javascript can provide. Would help to know if this web app is already built on ActiveX, Flash, Silverlight, XBAP, or similar technology...

0
14.10.2009 05:27:15
Thanks for the response Richard, the app is a pure ASPNet MVC app with Jquery available to it. I am already showing the file's content to the user in the web app. But I want the user to open the same file in Visual studio, by clicking on the file path in the web app. The question is more of Browser to VS integration and how to execute the DTE command in question
Vin 14.10.2009 14:43:12
So basically you'd like Javascript to be able to execute arbitrary code on my computer? No thanks! I like my browser security, fragile as it sometimes is. Best you can do is push the file contents as a downloadable item, instruct the user to click "Open," and hope they have the file extension associated with VS.
Richard Berg 14.10.2009 14:49:26
Understand the security concern, but this would happen with user's giving permission to open the file in VS ("Dialog may popup") - Don't think of it as an internet app where I would never do such a thing. This is a specific application I am talking about. Forget browser, think of it as a BrowserControl inside a winform app. You know what I am saying? :)
Vin 14.10.2009 17:30:08