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

浙公网安备 33010602011771号