private static void TryOpenTagFile(string title, string postfix) { if (title != null && postfix != null) { string tag = title; string file = CfgPath.GetFileByTag(tag, postfix);//file可能为null //string file = System.IO.Path.Combine(MyPath.DocRoot, tag + GConfig.DefaultPostfix); //如果文件已经存在,直接打开 if (file != null && File.Exists(file)) { System.Diagnostics.Process.Start(file); } else { //如果文件不存在,尝试在其他路径上查找 string[] files = Directory.GetFiles(CfgPath.DocDir, tag + "." + postfix); string dir = CfgPath.GetDirByTag(tag); //如果目录不存在,就不要再这儿创建了。 string[] files2 = null; if (Directory.Exists(dir)) { files2 = Directory.GetFiles(dir, tag + "." + postfix); } if (files.Length > 0) { file = files[0]; System.Diagnostics.Process.Start(file); } else if (files2 != null && files2.Length > 0) { file = files2[0]; System.Diagnostics.Process.Start(file); } else // 否则新建一个文件 { if (File.Exists(TemplateHelper.GetTemplateByExtension(postfix))) { File.Copy(TemplateHelper.GetTemplateByExtension(postfix), file); } else { File.Create(file).Close(); } //db.AddTagFile(tag, file, tag); System.Diagnostics.Process.Start(file); } } } }
public static string GetTemplateFileByTag(string tag, string dotPostfix) { string file = CfgPath.GetFileByTag(tag, "note" + dotPostfix, true);//这儿保证目录创建,并且file不为null string tmplateFile = TemplateHelper.GetTemplateByExtension(dotPostfix); if (!File.Exists(file) && File.Exists(tmplateFile)) { File.Copy(tmplateFile, file); } if (File.Exists(file)) { return(file); } else { return(null); } }