public int num = 0;
<summary>///Determine if the image file in the server path exists or not, accumulate statistics///</summary> private int Getacount (string nam e) {for (int i = 1; i < i + 1; i++) {String url = "http://IP/Image/" + name + "/" + Name + i + ". jpg"; HttpWebRequest request = (HttpWebRequest) webrequest.create (new Uri (URL)); Servicepointmanager.expect100continue = false; try {(HttpWebResponse) request. GetResponse ()). Close (); } catch (WebException exception) {if (exception. Status! = webexceptionstatus.protocolerror) {num++; } if (exception. Message.indexof ("$") > 0) {Response.Write ("<script>alert (' Server internal error, unable to complete the request, please contact the administrator! ');</script> ");} if (exception. Message.indexof ("401") > 0) {Response.Write ("<script>alert" Requires authentication, you don't have permission! ');</script> ");} if (exception. Message.indexof ("404") > 0) {return num; }} num++; } return num; }
Determine whether a server picture exists in C #