I'm developing wp8 app, using TweetSharp. All the links in tweets are look like t.co/aBRaKadABra. Part of links - pictures, rest - redirect to external pages. So, how can I detect that link is image? I want to put it in <Image>
, and if it just link - put in <HyperLink>
.
Asked
Active
Viewed 174 times
0

spender
- 117,338
- 33
- 229
- 351

Dima Serdechnyi
- 707
- 2
- 10
- 19
1 Answers
1
How about a HEAD request?
public static async Task<bool> IsUriImageAsync(Uri uri)
{
try
{
System.Net.WebRequest wc = System.Net.WebRequest.Create(uri);
//masquerade as a browser
((HttpWebRequest)wc).UserAgent =
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.2.153.1 Safari/525.19";
wc.Timeout = 1000;
wc.Method = "HEAD";
using(WebResponse res = await wc.GetResponseAsync())
{
return
res.ContentType
.StartsWith("image/",StringComparison.InvariantCulture);
}
}
catch (Exception ex)
{
return false;
}
}

spender
- 117,338
- 33
- 229
- 351