protected void cmdUpload_Click(object sender, EventArgs e) { // Check if a file was submitted. if (Uploader.PostedFile.ContentLength != 0) { try { if (Uploader.PostedFile.ContentLength > 1048576... Read More
posted @ 2010-11-11 08:33 gull Views(386) Comments(0) Diggs(0) Edit
为了防止规范化错误之类的安全风险,也可以使用Path类例如,它从一个固定的文档目录返回文件数据,FileInfo file=new FileInfo(Server.MapPath(@"Document\"+TextBox1.Text));这里用的是客户端的路径,存在一个漏洞, 举个例子,当客户端输入..\fileName这个路径的时候,这样这个路径就变化了,其实他已经忽略了Document\这个路... Read More
posted @ 2010-11-10 22:09 gull Views(192) Comments(0) Diggs(0) Edit
这里的myFile是FileInfo的一个实例如果设置一个文件为只读,我们需要位运算符来操作if ((myFile.Attributes & FileAttributes.ReadOnly) != 0) { ... }可以设置文件的特性-增加文件的只读类型myFile.Attributes=myFile.Attributes|FileAttributes.ReadOnly;移除文件的只读类... Read More
posted @ 2010-11-10 20:07 gull Views(530) Comments(0) Diggs(0) Edit
#region 文件流写入 private void WriteFileInfo() { FileInfo myFile = new FileInfo(@"c:\tem\aa.txt"); FileStream stream=null; //if (!myFile.Exists()) //{ // stream = myFile.Create(); //} stream = myFile.Open... Read More
posted @ 2010-11-10 19:53 gull Views(320) Comments(0) Diggs(0) Edit
#region 用DirectoryInfo这个类实现查看目录下的每个文件 public void LookDirectoryInfo() { string directoryName = @"c:\tem"; DirectoryInfo directoryInfo = new DirectoryInfo(directoryName); FileInfo[] fileList = null; if... Read More
posted @ 2010-11-10 14:31 gull Views(395) Comments(0) Diggs(0) Edit
protected void Page_Load(object sender, EventArgs e){ string series, category; if (!IsPostBack) {string series1 = Series(out series); string category1 = Category(out category); string cseries = series... Read More
posted @ 2010-10-26 08:50 gull Views(366) Comments(0) Diggs(0) Edit
public delegate void Feedback(object value,Int32 item,Int32 numItems);当编译器遇到这段代码时,它会产生如下面所示的一个完整的类定义public class Feedback : MulticastDelegate { public Feedback(object target, Int32 methodPro); public ... Read More
posted @ 2010-10-23 12:58 gull Views(350) Comments(0) Diggs(0) Edit
class MailManager { //传递给事件接受者的类型定义信息 public class MailMsgEventAgs : EventArgs { public readonly String from, to, subject, body; public MailMsgEventAgs(String from, String to, String subject, String b... Read More
posted @ 2010-10-23 10:46 gull Views(419) Comments(0) Diggs(0) Edit
class ClassWithDelegate { public delegate int DelegateThatReturnsInt(); public DelegateThatReturnsInt theDelegate; public void Run() { for (; ; ) { Thread.Sleep(500); if (theDelegate != null) {//第一... Read More
posted @ 2010-10-21 21:11 gull Views(234) Comments(0) Diggs(0) Edit
这是一个委托排序的例子public enum Comparsion { theFirstComesFirst=1, theSecondComesFirst=2 } //来决定排序的顺序class Pair<T> //在下面我创建的两个类Student,Dog,都把他们保存在Pair里面{ private T[] thePair = new T[2]; public delegate... Read More
posted @ 2010-10-21 09:28 gull Views(249) Comments(0) Diggs(0) Edit