Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a TFS WorkItem attachment in one shot?

Tags:

tfs

I open a work item and go into the Attachments tab. I double click on a .doc attachment. Instead of opening the file in Word, it instead kicks off the browser, which in turn brings down the file.

Is there a way to get TFS to run the attachment directly in Word?

like image 619
AngryHacker Avatar asked May 24 '12 22:05

AngryHacker


2 Answers

Attachments are accessed from the server through a given URL :

http://mytfs/tfs/default/WorkItemTracking/v1.0/AttachFileHandler.ashx?FileID=115&FileName=mydoc.doc

Visual Studio basically do a Shell Exec of this URL, which starts your default web browser.

You have two implementations of a Work Item form:

  • Desktop one: it does a shell exec
  • web one: you're already in the web browser

So there's no other way and I doubt there's a custom tool on the net to shorten that process...

like image 182
Nock Avatar answered Sep 30 '22 16:09

Nock


Looking at the HTTP Response Headers of AttachFileHandler.ashx the "problem" is because the content is being returned as file:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 11688
Content-Type: application/octet-stream
Server: Microsoft-IIS/7.0
X-AspNet-Version: 4.0.30319
content-disposition: filename=Screenshot.png
X-Powered-By: ASP.NET
Date: Fri, 17 Aug 2012 08:51:44 GMT

It's the content-disposition header that is forcing a Save As dialog even though the browser could just display the image directly. See the note on 19.5.1 Content-Disposition from w3.org:

If this header is used in a response with the application/octet- stream content-type, the implied suggestion is that the user agent should not display the response, but directly enter a 'save response as...' dialog.

I suspect TFS does it like this so that it can return any file regardless of whether the receiving browser can handle the content natively, e.g., uses a plug-in for PDFs. Maybe it would be possible to modify AttachFileHandler.ashx to change the way it returns content?

like image 27
staticboy Avatar answered Sep 30 '22 15:09

staticboy