The main function realizes whether remote files (pictures, etc.) exist. And this function, using a string URL as its parameters (a remote image URL), through the WebRequest and WebResponse objects to achieve this function, the specific code is as follows:
1 Private BOOLGetserverfileexists (stringURL)2 {3 Try4 {5 //The response used to put a request will be placed in a WebRequest object6System.Net.WebRequest s =System.Net.WebRequest.Create (URL); 7S.timeout =16000;//Set connection request time (in milliseconds)8 //the GetResponse object is then used to create a stream to fetch the value of the XML9System.Net.WebResponse A =s.getresponse ();Ten One //Close Request A a.close (); - S.abort (); - return true; the } - Catch - { - return false; + } -}
This completes the ability to determine whether a remote file (image, etc.) exists. The rest of the job is to call this function, do not introduce!
C # Implementation Determines whether a remote file (picture, etc.) exists