文件保存到指定位置(无弹窗)

上传者: zengzhengyou | 上传时间: 2021-11-26 22:05:15 | 文件大小: 1KB | 文件类型: -
private string savefile(string content) { try { #region 保存文章内容为html文件 DateTime dt = DateTime.Now; //设置文件夹路径 string directory = @"D:\"; //文件名称 以时间命名 避免重名 string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString() + dt.Millisecond.ToString(); //文件扩展名 可根据具体需要修改 string othername = @".html"; //文件保存完整路径 string path = directory + filename + othername; //验证文件夹是否存在 不存在则创建 if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } //以创建文件的方式写入内容 FileStream fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); sw.WriteLine(content); sw.Close(); fs.Close(); return @"D:/" + filename + othername;//返回文件存储路径 #endregion } catch (Exception ex) { //错误处理 return ""; } }

文件下载

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明