我创建了一个wpf应用程序,因为我需要创建一个文件夹,并且在该文件夹中我希望在应用程序安装的文件夹中动态创建文本文件
明智的。C:\ Program Files(x86)\ MyApplication \ NewFolder \ Mytext.txt \
我已经尝试了以下代码,但它没有得到
using System.IO;
private void CreateIfMissing(string path)
{
bool folderExists = Directory.Exists(Server.MapPath(path));//Here i don't understand what is server i think this will work in ASP.NET
if (!folderExists)
Directory.CreateDirectory(Server.MapPath(path));
}
如何实现这一目标?
答案 0 :(得分:1)
首先导入C#/ .NET的IO库
using System.IO;
检查是否存在,如果不是,则使用以下内容创建。
if (!Directory.Exists(@"C:\Program Files (x86)\MyApplication\NewFolder")
Directory.CreateDirectory(@"C:\Program Files (x86)\MyApplication\NewFolder");
老实说,如果你做了一些研究,伙计你会发现它!祝你的项目好运