C# 如何检查wp7应用程序上是否存在url?
我想为我的应用加载图像。C# 如何检查wp7应用程序上是否存在url?,c#,windows-phone-7,windows-phone-8,C#,Windows Phone 7,Windows Phone 8,我想为我的应用加载图像。 我知道获取图像所需的确切URL。如何检查URL是否存在?您可以使用类似的方法 bool result = false; using (WebClient client = new WebClient()) { try { Stream stream = client.OpenRead(url); if (stream != null) {
我知道获取图像所需的确切URL。如何检查URL是否存在?您可以使用类似的方法
bool result = false;
using (WebClient client = new WebClient())
{
try
{
Stream stream = client.OpenRead(url);
if (stream != null)
{
result = true;
}
else
{
result = false;
}
}
catch
{
//Any exception will returns false.
result = false;
}
}
return result;
在使用WP7时,可能需要查看异步版本
来源:从请求中获取响应代码