日期:2014-05-19  浏览次数:20759 次

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);
}