Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

HttpWebRequest to check file is exist or not on web asynchronously

$
0
0

Hi,

I have created app in Xamarin.Forms. On one page we are showing images in ListView by weburl. We are checking whether file is exists or not on web by using below code.
This function is executing synchronously but we need not wait upto the execution of this code we want to it run asynchronously.

Is there anyone know how to convert below code that can run this function asynchronously?

Thanks in advance.

public bool IsFileExist(string filePath)
{
bool isExist = false;
try
{
if (!string.IsNullOrEmpty(filePath))
{
//Creating the HttpWebRequest
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(filePath);
//Setting the Request method HEAD, you can also use GET too.
request.Method = "HEAD";
//Getting the Web Response.

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    if (response != null)
                    {
                        if (response.StatusCode == HttpStatusCode.OK) //Returns TURE if the Status code == 200
                            isExist = true;
                    }
                }
            }
        }
        catch
        {

        }
        return isExist;
    }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>