为了防止规范化错误之类的安全风险,也可以使用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(531) 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(322) 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(396) Comments(0) Diggs(0) Edit