Archive for the 'c#' Category

c# 获取当前系统用户的桌面代码

星期六, 七月 24th, 2010

string dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

一句话搞定。

统计蜘蛛访问痕迹 net版~

星期一, 六月 7th, 2010

很遗憾,在虚拟主机上只能统计到映射到 .NET 筛选上的文件,比如aspx 文件等。
html还是在通常情况下是不可以的,虽然在调试的时候可以~
解决办法也有。那就是在iis中映射html等需要统计的静态文件后缀到.net筛选上,但是,要是能修改这个的话,直接读IIS日志就OK了。就没有必要去专门耗资源的去使用此程序去统计啦~~~
也可能在web.config中定义出来,但是我没成功,希望成功的人能给我留言~
谢谢了~~~
code

.net aspx 利用smtp 发送邮件email 简单实用版

星期一, 四月 19th, 2010

前提是发件邮箱开启了smtp;
using System.Net.Mail;
if (!string.IsNullOrEmpty(Request.Form["email"]) && !string.IsNullOrEmpty(Request.Form["content"]) && !string.IsNullOrEmpty(Request.Form["title"]) && !string.IsNullOrEmpty(Request.Form["name"]))
{
string title = Request.Form["title"].ToString();
string mail = Request.Form["email"].ToString();
string content = Request.Form["content"].ToString();
string name = Request.Form["name"].ToString();
MailMessage message = new MailMessage();
message.From = new MailAddress(“mailsend@bordf.com”, name);
message.To.Add(new MailAddress(mail)); // the email you want to send email to
message.Subject = title;
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Body = content;
message.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient(“smtp.bordf.com”, 25);
client.Credentials = [...]

web.config来进行301定向和rewrite规则的使用~ 实例中包含discuz rewrite规则~

星期一, 四月 19th, 2010

<configuration>
<system.webServer>
<httpRedirect enabled=”true” destination=”http://blog.bordf.com” httpResponseStatus=”Permanent” />   //301永久重定向
//rewrite规则部分开始 ,用于discuz
<rewrite>
<rules>
<rule>
<match url=”faq.htm$” />
<action url=”faq.php” />
</rule>
<rule>
<match url=”tag-(.+).html$” />
<action url=”tag.php\?name={R:1}” />
</rule>
<rule >
<match url=”thread-([0-9]+)-([0-9]+)-([0-9]+).html$” />
<action url=”viewthread.php?tid={R:1}&amp;extra=page\%3D{R:3}&amp;page={R:2}” />
</rule>
<rule >
<match url=”forum-([0-9]+)-([0-9]+).html$” />
<action url=”forumdisplay.php?fid={R:1}&amp;page={R:2}” />
</rule>
</rules>
</rewrite>
//rewrite规则部分结束 ,用于discuz
<httpErrors errorMode=”DetailedLocalOnly” />
<asp scriptErrorSentToBrowser=”true” />
</system.webServer>
<appSettings/>
<connectionStrings/>
<system.web>
</system.web>
</configuration>

简单的图形验证系统.net代码 ~

星期四, 四月 1st, 2010

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class picture : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string checkCode = CreateRandomCode();
Session["CheckCode"] = checkCode;
CreateImage(checkCode);
}
private string CreateRandomCode()
{
//做个随机数库
string allChar = “0,1,2,3,4,5,6,7,8,9″;
//将库里的字符放到数组里去
string[] allCharArray = allChar.Split(‘,’);
//定义RandomCode变量,为了存放生成的随机数。
string RandomCode = “”;
int temp = -1;
//实例Random函数
Random rand = new Random();
//for循环,这里是四次循环,为了是产生四个随机数,如果要产生多个,自己定义循环次数
for (int i = 0; i < 4; i++)
{
if (temp != [...]

访客统计程序demo,框架完成,架构补充我就不爱做了~ 所以就这样~

星期四, 四月 1st, 2010

Spidertest.aspx
<form id=”form1″>
<div><img src=”http://stats.bordf.com/spider.aspx?site=test” border=”0″ alt=”” width=”0″ height=”0″ /></div>
</form>
spider.aspx

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.IO;
public partial class spider : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["site"]))
{
string site, ip, url, time, agent,content;
site = Request.QueryString["site"];
ip = Request.UserHostAddress.ToString();
if (!string.IsNullOrEmpty(Request.ServerVariables["HTTP_REFERER"]))
{
url = Request.ServerVariables["HTTP_REFERER"].ToString();
}
else
{
url = “null”;
}
time = DateTime.Now.ToString();
agent = Request.UserAgent.ToString();
agent = agen(agent);
content = time + ” [...]

DOS操作Sqlite命令大全

星期三, 十二月 30th, 2009

数据库、表的建立,记录的添加、查询、修改和删除
F:\>sqlite3 database.db
sqlite> create table admin(username text,age integer);
sqlite> insert into admin values(‘kuang’,25);
sqlite> select * from admin;
sqlite> update admin set username=’kk’,age=24 where username=’kuang’ and age=25;
sqlite> delete from admin where username=’kk’;
注:每条sql语句后必须以”;”号结尾!
2.Sqlite系统命令
.bail ON|OFF           Stop after hitting an error.  Default OFF
.databases             List names and files of attached databases(查看目前挂的数据库)
.dump ?TABLE? …      Dump the database in an SQL text format(以SQL格式输出表结构)
.echo ON|OFF           Turn command echo [...]

C# 向web网站GET、POST 数据

星期三, 十二月 30th, 2009

HttpWebRequest 是 .net 基类库中的一个类,在命名空间 System.Net 下面,用来使用户通过 HTTP 协议和服务器交互。

HttpWebRequest 对 HTTP 协议进行了完整的封装,对 HTTP 协议中的 Header, Content, Cookie 都做了属性和方法的支持,很容易就能编写出一个模拟浏览器自动登录的程序。
程序使用 HTTP 协议和服务器交互主要是进行数据的提交,通常数据的提交是通过 GET 和 POST 两种方式来完成,下面对这两种方式进行一下说明:
1. GET 方式。 GET 方式通过在网络地址附加参数来完成数据的提交,比如在地址 http://www.google.com/webhp?hl=zh-CN 中,前面部分 http://www.google.com/webhp 表示数据提交的网址,后面部分 hl=zh-CN 表示附加的参数,其中 hl 表示一个键(key), zh-CN 表示这个键对应的值(value)。程序代码如下:
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create( “http://www.google.com/webhp?hl=zh-CN” );
req.Method = “GET”;
using (WebResponse wr = req.GetResponse())
{
//在这里对接收到的页面内容进行处理
}
2. POST 方式。 POST 方式通过在页面内容中填写参数的方法来完成数据的提交,参数的格式和 GET 方式一样,是类似于 [...]

C#模拟Post和Get方式发送数据

星期三, 十二月 30th, 2009

通过应用程序读取网页信息的时候,通常需要抓取网页的数据,但是有一个问题就是很多网页需要登录后才能够获得页面数据,那么就需要保存当前的 cookie,在.NET中可以使用CookieContainer 对象来保存登录后的Cookie信息,每次发送数据的时候加上Cookie信息,就可以解决这个问题了。
#region 同步通过POST方式发送数据
/// <summary>
/// 通过POST方式发送数据
/// </summary>
/// <param name=”Url”>url</param>
/// <param name=”postDataStr”>Post数据</param>
/// <param name=”cookie”>Cookie容器</param>
/// <returns></returns>
public string SendDataByPost(string Url,string postDataStr,ref CookieContainer cookie)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
if (cookie.Count == 0)
{
request.CookieContainer = new CookieContainer();
cookie = request.CookieContainer;
}
else
{
request.CookieContainer = cookie;
}
request.Method = “POST”;
request.ContentType = “application/x-www-form-urlencoded”;
request.ContentLength = postDataStr.Length;
Stream myRequestStream = request.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding(“gb2312″));
myStreamWriter.Write(postDataStr);
myStreamWriter.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = [...]

C#中PictureBox异步加载图片~

星期三, 十二月 30th, 2009

在PictureBox加载图片时,能不能显示等待,加载完毕后再显示真正的图片…
void Button1Click(object sender, EventArgs e)
{
//图片异步加载完成后的处理事件
pictureBox1.LoadCompleted += new AsyncCompletedEventHandler(pictureBox1_LoadCompleted);
//图片加载时,显示等待光标
pictureBox1.UseWaitCursor = true;
//采用异步加载方式
pictureBox1.WaitOnLoad = false;
//开始异步加载,图片的地址,请自行更换
pictureBox1.LoadAsync(“图片地址”);
}
void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
//图片加载完成后,将光标恢复
pictureBox1.UseWaitCursor = false;
}

留着备用~

.net C#获得网页完整代码函数.. WebRequest方式的…前面有webclient方式的~

星期四, 十月 29th, 2009

webclient 的延时并不好, 所以后来使用的是 WebRequest方式获得代码~
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
using System.IO;
private string getHtml(string url)
{
HttpWebRequest myRequest;
HttpWebResponse myResp = null;
[...]

.net读取mssql基础语句– 使用web.config保存数据库字符串

星期一, 十月 26th, 2009

web.config 中 加入

Connect Timeout=300 是连接超时时间!
程序中读取:
using System.Configuration;
using System.Data.SqlClient;
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["datastr"]);
SqlCommand cmd = new SqlCommand(“sql语句”, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
[...]

提交获得到的cookie来获取需要登录的网页代码~

星期一, 十月 12th, 2009

using System.Net;
private string getHtml(string url)
{
WebClient myWebClient = new WebClient();
myWebClient.Headers.Add(“Cookie”, “cookie内容″);
[...]

c#使用ftp上传多线程技术实现 progressBar显示不卡死代码

星期六, 十月 10th, 2009

using System.Net;
using System.IO;
using System.Threading;
记得添加他们~
public string doc, fname, tname;
private FtpStatusCode UploadFun(string fileName, string uploadUrl)
{
Stream requestStream = null;
FileStream fileStream = null;
[...]

c# 正则搜索匹配+ 读取txt +OpenFileDialog+进度条progressBar应用实例 绝对原创

星期五, 九月 18th, 2009

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
[...]