随笔分类 -  asp.net文件操作

摘要:这些是主要的代码文件上传的protected void 学生上传信息_upfile_Click(object sender, EventArgs e)//文件上传 { 学生上传信息.Text = upfile(学生上传信息_file, MapPath("..") + "/uploadfile/", "uploadfile/"); 教师下载信息.Text = 学生上传信息.Text; }protec... 阅读全文
posted @ 2010-11-11 09:07 gull 阅读(174) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2010-11-11 08:33 gull 阅读(400) 评论(0) 推荐(0)
摘要:为了防止规范化错误之类的安全风险,也可以使用Path类例如,它从一个固定的文档目录返回文件数据,FileInfo file=new FileInfo(Server.MapPath(@"Document\"+TextBox1.Text));这里用的是客户端的路径,存在一个漏洞, 举个例子,当客户端输入..\fileName这个路径的时候,这样这个路径就变化了,其实他已经忽略了Document\这个路... 阅读全文
posted @ 2010-11-10 22:09 gull 阅读(212) 评论(0) 推荐(0)
摘要:这里的myFile是FileInfo的一个实例如果设置一个文件为只读,我们需要位运算符来操作if ((myFile.Attributes & FileAttributes.ReadOnly) != 0) { ... }可以设置文件的特性-增加文件的只读类型myFile.Attributes=myFile.Attributes|FileAttributes.ReadOnly;移除文件的只读类... 阅读全文
posted @ 2010-11-10 20:07 gull 阅读(569) 评论(0) 推荐(0)
摘要:#region 文件流写入 private void WriteFileInfo() { FileInfo myFile = new FileInfo(@"c:\tem\aa.txt"); FileStream stream=null; //if (!myFile.Exists()) //{ // stream = myFile.Create(); //} stream = myFile.Open... 阅读全文
posted @ 2010-11-10 19:53 gull 阅读(337) 评论(0) 推荐(0)
摘要:#region 用DirectoryInfo这个类实现查看目录下的每个文件 public void LookDirectoryInfo() { string directoryName = @"c:\tem"; DirectoryInfo directoryInfo = new DirectoryInfo(directoryName); FileInfo[] fileList = null; if... 阅读全文
posted @ 2010-11-10 14:31 gull 阅读(408) 评论(0) 推荐(0)