新手,问一个关于文件保存的问题…… 本帖最后由 showland 于 2011-02-17 20:28:26 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string path = @"C:/download/a/b/c/d/e/f/g/h/1.txt";string dir = Path.GetDirectory(path);if (!Directory.Exists(dir)) Directory.Create(dir);File.WriteAllText(path, "内容"); Directory.Create 创建目录 string str = "C:/download/a/b/c/d/e/f/g/h/1.txt"; while (Directory.Exists(Path.GetDirectoryName(str))) { //substring 截取. } 可以这样写:private static void 创建目录(string path){ 创建目录(new DirectoryInfo(path));}private static void 创建目录(DirectoryInfo directoryInfo){ if (directoryInfo.Exists) return; var parent = directoryInfo.Parent; if (parent != null) 创建目录(parent); directoryInfo.Create();} 可以把 private 改为 public。当然,要“using System.IO;”。 在Word中可输入的特殊字符拷入.cs文件中看不见? 怎么让窗体和里面所有的控件在鼠标点击的时候不获得焦点 关于用户授权的问题 vs2005如何自定义格式化源代码? sql 2000 用企业管理器导出数据表的问题 能否在运行期间 根据数据库中记录中的类型 建立不同的类实例 如何将二进制转换为字符? 求刷卡考勤系统设计的概要方案 100分求qq通讯协议! 在C#中ListView控件的疑问??????急急急!!!!!!! 【求助】单机应用程序,不使用数据库,如何管理数据 webbrowser newwindow 事件问题。。。
string dir = Path.GetDirectory(path);
if (!Directory.Exists(dir))
Directory.Create(dir);
File.WriteAllText(path, "内容");
string str = "C:/download/a/b/c/d/e/f/g/h/1.txt";
while (Directory.Exists(Path.GetDirectoryName(str)))
{
//substring 截取.
}
{
创建目录(new DirectoryInfo(path));
}private static void 创建目录(DirectoryInfo directoryInfo)
{
if (directoryInfo.Exists)
return; var parent = directoryInfo.Parent;
if (parent != null)
创建目录(parent);
directoryInfo.Create();
}