protected void Sub_click (object sender, EventArgs e)
{
int i = 0;
string url = this.url.Text;
Directory.CreateDirectory ("d:/aspnetjia/" +url);
string result = GetWebRequest (URL);
This.content.InnerText = result;
MatchCollection results = regex.matches (result, @ "]*src= ([" "']* ') (? <src>[^ '" "]*) \1[^>]*> ", regexoptions.ignorecase);
String[] D = new string[results. Count];
foreach (Match m in results)
{
D[i] = m.groups["src"]. Value;
i++;
}
for (int j = 0; J < D.length; J + +)
{
String Jieguo = "";
int JJ = j + 1;
String jie = d[j]. ToString ();
if (Jie. Contains (URL))
//{
Jie. Replace (URL, "");
//}
if (Jie. Contains ("www.") | | Jie. Contains ("http"))
{
Jieguo = "<a href= '" +jie+ "' ></a>";
}
Else
{
Jieguo = "<a href=" + URL + "/" + Jie + "' ></a>";
}
Random rand = new Random ();//define a random number, in order to prevent you from uploading the picture duplicate name
string[] Strspil = Jie. Split ('. '); /This address is split with a. Number (img/1.jpg)
String strend = Strspil[strspil.length-1]. ToLower ();//Get Back ("jpg", "gif", "BMP", "PNG", "JPEG", "JPG", "gif", "BMP", "PNG", "JPEG")
String strName = DateTime.Now.ToString ("YYYYMMMDDHHSS") + Rand. Next (100, 9999). ToString ();//Get a different name
String strpointend = strname+ "." +strend;
System.Net.WebClient mywebclient = new System.Net.WebClient ();
if (Jie. Contains ("http"))
{
Mywebclient.downloadfile (Jie, "d:/aspnetjia/" +url+ "/" +strpointend);
}
Else
{
Mywebclient.downloadfile (URL + "/" +jie, "d:/aspnetjia/" +url + "/" +strpointend);
}
Response.Write ("Downloading section" +j+ "...");
}
Response.Write ("Please check your D-disk under Aspnetjia folder");
}
private string GetWebRequest (string url)
{
Uri uri = new uri (URL);
WebRequest myreq = WebRequest.Create (URI);
WebResponse result = Myreq.getresponse ();
Stream Recevicestream = result. GetResponseStream ();
StreamReader Readerofstream = new StreamReader (Recevicestream, System.Text.Encoding.GetEncoding ("Utf-8"));
String strhtml = Readerofstream.readtoend ();
Readerofstream.close ();
Recevicestream.close ();
Result. Close ();
return strhtml;
}
Reprinted from: http://www.aspnetjia.com
Extract site Pictures