简体   繁体   English

如何检查URL是否存在于wp7应用程序上?

[英]How to check url exists or not on wp7 apps?

I want to load a image for my apps. 我想为我的应用加载图像。 I know the exact URL that I need to acquire the image. 我知道获取图像所需的确切URL。 How to check URL exists or not ? 如何检查URL是否存在?

You use something like this. 您使用类似这样的东西。

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;

As you are using WP7, you may need to look the async versions. 在使用WP7时,您可能需要查看异步版本。

Source : http://www.dotnetthoughts.net/how-to-check-remote-file-exists-using-c/ 资料来源: http : //www.dotnetthoughts.net/how-to-check-remote-file-exists-using-c/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM