ASP.NET(C#)经典采集代码

using System;
None.gif using System.Data;
None.gif using System.Configuration;
None.gif using System.Web;
None.gif using System.Web.Security;
None.gif using System.Web.UI;
None.gif using System.Web.UI.WebControls;
None.gif using System.Web.UI.WebControls.WebParts;
None.gif using System.Web.UI.HtmlControls;
None.gif using System.Drawing;
None.gif using MSXML2;
None.gif using System.Text.RegularExpressions;
None.gif namespace wenweifeng
ExpandedBlockStart.gifContractedBlock.gif dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif/**////
InBlock.gif/// CaiJi 的摘要说明
ExpandedSubBlockEnd.gif///

InBlock.gif public class CaiJi
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifpublic CaiJi()
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif//
InBlock.gif// TODO: 在此处添加构造函数逻辑
InBlock.gif//
ExpandedSubBlockEnd.gif }

InBlock.gif~CaiJi()
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif Dispose();
ExpandedSubBlockEnd.gif }

InBlock.gifpublic void Dispose()
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif GC.SuppressFinalize(this);
ExpandedSubBlockEnd.gif }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif日期随机函数#region 日期随机函数
ExpandedSubBlockStart.gifContractedSubBlock.gif/**//**********************************
InBlock.gif * 函数名称:DateRndName
InBlock.gif * 功能说明:日期随机函数
InBlock.gif * 参 数:ra:随机数
InBlock.gif * 调用示例:
InBlock.gif * GetRemoteObj o = new GetRemoteObj();
InBlock.gif * Random ra = new Random();
InBlock.gif * string s = o.DateRndName(ra);
InBlock.gif * Response.Write(s);
InBlock.gif * o.Dispose();
ExpandedSubBlockEnd.gif * ********************************/

ExpandedSubBlockStart.gifContractedSubBlock.gif/**////
InBlock.gif/// 日期随机函数
InBlock.gif///
InBlock.gif/// 随机数
ExpandedSubBlockEnd.gif///

InBlock.gif public string DateRndName(Random ra)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif DateTime d = DateTime.Now;
InBlock.gifstring s = null, y, m, dd, h, mm, ss;
InBlock.gif y = d.Year.ToString();
InBlock.gif m = d.Month.ToString();
InBlock.gifif (m.Length < 2) m = "0" + m;
InBlock.gif dd = d.Day.ToString();
InBlock.gifif (dd.Length < 2) dd = "0" + dd;
InBlock.gif h = d.Hour.ToString();
InBlock.gifif (h.Length < 2) h = "0" + h;
InBlock.gif mm = d.Minute.ToString();
InBlock.gifif (mm.Length < 2) mm = "0" + mm;
InBlock.gif ss = d.Second.ToString();
InBlock.gifif (ss.Length < 2) ss = "0" + ss;
InBlock.gif s += y + ',' + m + ',' + dd + ',' + h + "-" + mm + "-" + ss;
InBlock.gif s += ra.Next(1000000, 9999999).ToString();
InBlock.gifreturn s;
ExpandedSubBlockEnd.gif }

ExpandedSubBlockEnd.gif#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif取得文件后缀#region 取得文件后缀
ExpandedSubBlockStart.gifContractedSubBlock.gif/**//**********************************
InBlock.gif * 函数名称:GetFileExtends
InBlock.gif * 功能说明:取得文件后缀
InBlock.gif * 参 数:filename:文件名称
InBlock.gif * 调用示例:
InBlock.gif * GetRemoteObj o = new GetRemoteObj();
InBlock.gif * string url = @"http://www.baidu.com/img/logo.gif";
InBlock.gif * string s = o.GetFileExtends(url);
InBlock.gif * Response.Write(s);
InBlock.gif * o.Dispose();
ExpandedSubBlockEnd.gif * ********************************/

ExpandedSubBlockStart.gifContractedSubBlock.gif/**////
InBlock.gif/// 取得文件后缀
InBlock.gif///
InBlock.gif/// 文件名称
ExpandedSubBlockEnd.gif///

InBlock.gif public string GetFileExtends(string filename)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifstring ext = null;
InBlock.gifif (filename.IndexOf('.') > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifstring[] fs = filename.Split('.');
InBlock.gif ext = fs[fs.Length - 1];
ExpandedSubBlockEnd.gif }

InBlock.gifreturn ext;
ExpandedSubBlockEnd.gif }

ExpandedSubBlockEnd.gif#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif获取远程文件源代码#region 获取远程文件源代码
ExpandedSubBlockStart.gifContractedSubBlock.gif/**//**********************************
InBlock.gif * 函数名称:GetRemoteHtmlCode
InBlock.gif * 功能说明:获取远程文件源代码
InBlock.gif * 参 数:Url:远程url
InBlock.gif * 调用示例:
InBlock.gif * GetRemoteObj o = new GetRemoteObj();
InBlock.gif * string url = @"http://www.baidu.com";
InBlock.gif * string s = o.GetRemoteHtmlCode(url);
InBlock.gif * Response.Write(s);
InBlock.gif * o.Dispose();
ExpandedSubBlockEnd.gif * ********************************/

ExpandedSubBlockStart.gifContractedSubBlock.gif/**////
InBlock.gif/// 获取远程文件源代码
InBlock.gif///
InBlock.gif/// 远程url
ExpandedSubBlockEnd.gif///

InBlock.gif public string GetRemoteHtmlCode(string Url)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifstring s = "";
InBlock.gif MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
InBlock.gif _xmlhttp.open("GET", Url, false, null, null);
InBlock.gif _xmlhttp.send("");
InBlock.gifif (_xmlhttp.readyState == 4)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif s = System.Text.Encoding.Default.GetString((byte[])_xmlhttp.responseBody);
ExpandedSubBlockEnd.gif }

InBlock.gifreturn s;
ExpandedSubBlockEnd.gif }

InBlock.gif
ExpandedSubBlockEnd.gif#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif保存远程文件#region 保存远程文件
ExpandedSubBlockStart.gifContractedSubBlock.gif/**//**********************************
InBlock.gif * 函数名称:RemoteSave
InBlock.gif * 功能说明:保存远程文件
InBlock.gif * 参 数:Url:远程url;Path:保存到的路径
InBlock.gif * 调用示例:
InBlock.gif * GetRemoteObj o = new GetRemoteObj();
InBlock.gif * string s = "";
InBlock.gif * string url = @"http://www.baidu.com/img/logo.gif";
InBlock.gif * string path =Server.MapPath("Html/");
InBlock.gif * s = o.RemoteSave(url,path);
InBlock.gif * Response.Write(s);
InBlock.gif * o.Dispose();
ExpandedSubBlockEnd.gif * ******************************/

ExpandedSubBlockStart.gifContractedSubBlock.gif/**////
InBlock.gif/// 保存远程文件
InBlock.gif///
InBlock.gif/// 远程url
InBlock.gif/// 保存到的路径
ExpandedSubBlockEnd.gif///

InBlock.gif public string RemoteSave(string Url, string Path)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif
InBlock.gif Random ra = new Random();
InBlock.gifstring newfilename = string.Empty;
InBlock.gifstring StringFileName = DateRndName(ra) + "." + GetFileExtends(Url);
InBlock.gifif (GetFileExtends(Url).Trim().ToLower() != "jpg")
InBlock.gif newfilename = StringFileName;
InBlock.gifelse
InBlock.gif newfilename = DateRndName(ra) + "Addpic." + GetFileExtends(Url);
InBlock.gifstring StringFilePath = Path + StringFileName;
InBlock.gifstring newfilepath = Path + newfilename;
InBlock.gifstring retname = string.Empty;
InBlock.giftry
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
InBlock.gif _xmlhttp.open("GET", Url, false, null, null);
InBlock.gif _xmlhttp.send("");
InBlock.gifif (_xmlhttp.readyState == 4)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifif (System.IO.File.Exists(StringFilePath))
InBlock.gif System.IO.File.Delete(StringFilePath);
InBlock.gif System.IO.FileStream fs = new System.IO.FileStream(StringFilePath, System.IO.FileMode.CreateNew);
InBlock.gif System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
InBlock.gif w.Write((byte[])_xmlhttp.responseBody);
InBlock.gif w.Close();
InBlock.gif fs.Close();
InBlock.gifif (GetFileExtends(Url).Trim().ToLower() == "jpg")
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif function myfunction = new function();
InBlock.gif//myfunction.AddShuiYinWord(StringFilePath, newfilepath);
InBlock.gif service myserver=new service();
InBlock.gif myfunction.AddShuiYinPic(StringFilePath, newfilepath, HttpContext.Current.Server.MapPath(myserver.myweblogo));
ExpandedSubBlockEnd.gif }

InBlock.gif
ExpandedSubBlockEnd.gif }

InBlock.gifelse
InBlock.gifthrow new Exception(_xmlhttp.statusText);
ExpandedSubBlockEnd.gif }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7192349/viewspace-968973/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7192349/viewspace-968973/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值