WinForm程序中如何在指定路径创建文件
Windows程序在E:\MyForm文件夹下运行
能不能E:\NewFile文件夹下面创建一个文件(如txt)。
如果NewFile文件夹不存在,就创建他。
[解决办法]
File.Create (String, Int32, FileOptions)
Creates or overwrites the specified file, specifying a buffer size and a FileOptions value that describes how to create or overwrite the file.
[解决办法]
using System.IO;
………………
if(!File.Exsit(_FilePath))
{
File.Creat(_FilePath);
}
[解决办法]
if(!Directory.Exits(path))
{
Directory.Create(path);
}
//do
[解决办法]
string dir = MapPath(DirectoryName);
try
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
[解决办法]
Exists
hoho 更正 更正 二师兄的也没写对 面壁10分钟
[解决办法]
又被标题误导了
[解决办法]
if(!File.Exsit(dir))
{
File.Creat(dir);
}