为大家提供一个ASP.NET中用C#实现的采集代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using MSXML2;
using System.Text.RegularExpressions;
namespace wenweifeng
{
/**//// <summary>
/// CaiJi 的摘要说明
/// </summary>
public class CaiJi
{
public CaiJi()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
~CaiJi()
{
Dispose();
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
日期随机函数#region 日期随机函数
/**//**********************************
* 函数名称:DateRndName
* 功能说明:日期随机函数
* 参 数:ra:随机数
* 调用示例:
* GetRemoteObj o = new GetRemoteObj();
* Random ra = new Random();
* string s = o.DateRndName(ra);
* Response.Write(s);
* o.Dispose();
* ********************************/
/**//// <summary>
/// 日期随机函数
/// </summary>
/// <param name="ra">随机数</param>
/// <returns></returns>
public string DateRndName(Random ra)
{
DateTime d = DateTime.Now;
string s = null, y, m, dd, h, mm, ss;
y = d.Year.ToString();
m = d.Month.ToString();
if (m.Length < 2) m = "0" + m;
dd = d.Day.ToString();
if (dd.Length < 2) dd = "0" + dd;
h = d.Hour.ToString();
if (h.Length < 2) h = "0" + h;
mm = d.Minute.ToString();
if (mm.Length < 2) mm = "0" + mm;
ss = d.Second.ToString();
if (ss.Length < 2) ss = "0" + ss;
s += y + ’,’ + m + ’,’ + dd + ’,’ + h + "-" + mm + "-" + ss;
s += ra.Next(1000000, 9999999).ToString();
return s;
}
#endregion
取得文件后缀#region 取得文件后缀
/**//**********************************
* 函数名称:GetFileExtends
* 功能说明:取得文件后缀
* 参 数:filename:文件名称
* 调用示例:
* GetRemoteObj o = new GetRemoteObj();
* string url = @" * string s = o.GetFileExtends(url);
* Response.Write(s);
* o.Dispose();
* ********************************/
/**//// <summary>
/// 取得文件后缀
/// </summary>
/// <param name="filename">文件名称</param>
/// <returns></returns>
public string GetFileExtends(string filename)
{
string ext = null;
if (filename.IndexOf(’.’) > 0)
{
string[] fs = filename.Split(’.’);
ext = fs[fs.Length - 1];
}
return ext;
}
#endregion