本帖最后由 showland 于 2011-02-17 20:28:26 编辑

解决方案 »

  1.   

    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, "内容");
      

  2.   

    Directory.Create 创建目录
     string str = "C:/download/a/b/c/d/e/f/g/h/1.txt";
                while (Directory.Exists(Path.GetDirectoryName(str)))
                {
                 //substring 截取.
                }
      

  3.   

    可以这样写: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();
    }
      

  4.   

    可以把 private 改为 public。当然,要“using System.IO;”。