0

I developed some integration between Jira and TFS.

Some bugs in TFS have image in Description like this:

 <span style="color:black;font-family:&quot;Segoe UI&quot;,sans-serif;font-size:9pt;"><img style="width:606px;" src="http://server:8080/tfs/IT_Systems/WorkItemTracking/v1.0/AttachFileHandler.ashx?FileNameGuid=7d796b11-588f-4266-a783-8d3fa61cb4bd&amp;FileName=temp1465385989194.png"><br>&nbsp;</span>

How can I download this image programmatically using c#?

I know I should parse HTML and so on. But problem is I don't know how to extract data from URL.

In TFS web part I select image, copy it, open for example Paint, past image and save it as jpg-file.

I need the same in my c# code.

Can anyone help me?

Ilya
  • 141
  • 2
  • 14

1 Answers1

0

I would use Regex to parse the HTML description and pull out the img URL then download the image using a HttpWebRequest.

You could use the following Regex:

(?<=<img.*src=")[^"]*
chief7
  • 14,263
  • 14
  • 47
  • 80
  • I use this too. But my problem is I wanna download image, not detect it in HTML – Ilya Jun 09 '16 at 14:16
  • Use a HttpWebRequest to download the image. – chief7 Jun 09 '16 at 15:48
  • Could you give me an example how i can download it by follow url? http://server:8080/tfs/IT_Systems/WorkItemTracking/v1.0/AttachFileHandler.ashx?FileNameGuid=7d796b11-588f-4266-a783-8d3fa61cb4bd&FileName=temp1465385989194.png – Ilya Jun 10 '16 at 10:51
  • http://stackoverflow.com/questions/2368115/how-to-use-httpwebrequest-to-pull-image-from-website-to-local-file – chief7 Jun 10 '16 at 14:49
  • it won't work, because in my example it's not direct link. And as I know it's impossible to download it using HttpWebRequest only. That's why I copied/pasted image and not to download in TFS Web client. There isn't opportunity to do it directly – Ilya Jun 19 '16 at 16:41