c#文件夹操作(编辑计算机本地文件)(删、重命名、移动)
根据完整物理路径获取文件file
//获取文件 FileInfo fileinfo = new FileInfo(fullurl);
判断服务器文件存在,C# 判断服务器上文件是否存在(对应文件内是否有该文件)
https://blog.csdn.net/weixin_33515785/article/details/119284418
var path = " FramePath" ; var filePath = Server.MapPath(path); if (System.IO.File.Exists(filePath)) { var fileName = Path.GetFileName(filePath); FileInfo info = new FileInfo(filePath); Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FrameName + ".zip", System.Text.Encoding.UTF8).Replace("+", "%20")); Response.AppendHeader("Content-Length", info.Length.ToString()); Response.WriteFile(filePath); Response.Flush(); Response.End(); return new EmptyResult(); }
View Code
C# 重命名文件方法
C# 重命名文件方法 – enych – 博客园 (cnblogs.com)
复制代码 1. //重命名文件 // 改名方法 FileInfo fi = new FileInfo("旧路径"); //xx/xx/aa.rar fi.MoveTo("新路径"); //xx/xx/xx.rar 2. 文件流方式 using (FileStream fsw = new FileStream(path + newName, FileMode.Create, FileAccess.Write)) //打开文件,用于只写 { BinaryWriter bw = new BinaryWriter(fsw); //编写器指向这个文件流 // 遍历文件合并 for (int i = 0; i < chunks; i++) { bw.Write(System.IO.File.ReadAllBytes(path + i.ToString() + "_" + filename)); //打开一个文件读取流信息,将其写入新文件 System.IO.File.Delete(path + i.ToString() + "_" + filename); //删除指定文件信息 bw.Flush(); //清理缓冲区 } }
View Code
C# 移动文件方法
https://www.cnblogs.com/xielong/p/6187308.html (参考文档仅供参考,本人尝试文档中的移动方法没有实现)
//本地移动 //获取媒体文件路径 string fileurl = res.getfileurl(MGUID, out string fullurl); //获取文件 FileInfo fileinfo = new FileInfo(fullurl); //获取放置新目录 string sBaseDir = getsaveDirPath(FolderID, LoginUserInfo.sUserID); //新文件路径 string newpath = sBaseDir +"/"+fileinfo.Name; //移动 fileinfo.MoveTo(Path.Combine(fullurl, newpath));
View Code
文件删除
//获取文件 FileInfo fileinfo = new FileInfo(fullurl); fileinfo.Delete(); //删除文件
原文地址:http://www.cnblogs.com/ZhuMeng-Chao/p/16930313.html
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请务用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性