Posted By

krisdb on 01/30/09


Tagged

c-sharp


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

LeeRJohnson
leonbda
umang_nine
emregulcan
rageit
khouser


RemoteFileExists


 / Published in: C#
 

  1. /// <summary>
  2. /// checks if a file on a remote server exists
  3. /// </summary>
  4. /// <param name="url"></param>
  5. /// <returns></returns>
  6. private bool RemoteFileExists(string url)
  7. {
  8. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
  9.  
  10. try
  11. {
  12. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
  13.  
  14. if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
  15. return true;
  16. else
  17. return false;
  18. }
  19. catch
  20. {
  21. return false;
  22. }
  23. }

Report this snippet  

You need to login to post a comment.