C# 如何创建一个文件夹
2012-03-28 10:14
387 查看
先写这样一个类
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.AccessControl;
namespace AssetsCheckDN
{
public class Folder
{
string folderPath = "";
public string FolderPath
{
get { return folderPath; }
set { folderPath = value; }
}
public void createFolder(string path)
{
Directory.CreateDirectory(path);
addpathPower(path, "lucifer-PC", "FullControl");
}
public void checkFolder(string path)
{
if (Directory.Exists(path))
{
addpathPower(path, "lucifer-PC", "FullControl");
return;
}
else
{
createFolder(path);
}
}
public void addpathPower(string pathname, string username, string power)
{
DirectoryInfo dirinfo = new DirectoryInfo(pathname);
if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
{ dirinfo.Attributes = FileAttributes.Normal; }
//C#创建文件夹取得访问控制列表
//DirectorySecurity dirsecurity = dirinfo.GetAccessControl();
//switch (power)
//{
// case "FullControl": dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
// break;
// case "ReadOnly": dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
// break;
// case "Write": dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
// break;
// default:
// break;
//}
}
}
}
调用这个类创建文件夹,并写文件进入这个文件夹。
Folder folder = new Folder();
string backFileName = Application.StartupPath + "\\Data\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
folder.checkFolder(backFileName);
File.Copy(localDB, backFileName + "\\CheckAsset.sdf");
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.AccessControl;
namespace AssetsCheckDN
{
public class Folder
{
string folderPath = "";
public string FolderPath
{
get { return folderPath; }
set { folderPath = value; }
}
public void createFolder(string path)
{
Directory.CreateDirectory(path);
addpathPower(path, "lucifer-PC", "FullControl");
}
public void checkFolder(string path)
{
if (Directory.Exists(path))
{
addpathPower(path, "lucifer-PC", "FullControl");
return;
}
else
{
createFolder(path);
}
}
public void addpathPower(string pathname, string username, string power)
{
DirectoryInfo dirinfo = new DirectoryInfo(pathname);
if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
{ dirinfo.Attributes = FileAttributes.Normal; }
//C#创建文件夹取得访问控制列表
//DirectorySecurity dirsecurity = dirinfo.GetAccessControl();
//switch (power)
//{
// case "FullControl": dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
// break;
// case "ReadOnly": dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
// break;
// case "Write": dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
// break;
// default:
// break;
//}
}
}
}
调用这个类创建文件夹,并写文件进入这个文件夹。
Folder folder = new Folder();
string backFileName = Application.StartupPath + "\\Data\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
folder.checkFolder(backFileName);
File.Copy(localDB, backFileName + "\\CheckAsset.sdf");
相关文章推荐
- 如何用C#创建一个类并在其他Web页中调用该类的方法(2)
- C# 创建文件时,文件夹不存在,如何自动创建文件夹
- C#如何打开一个文件夹并定位到某个文件
- C# 如何创建一个xml文件?并写入指定内容?
- 如何用c#打开文件夹并选择文件夹内的一个文件 open folder and select file
- 如何使用C#创建一个三层的数据库应用程序
- c#打包,如何让安装程序把一个文件夹拷贝到特定路径
- C#如何遍历一个文件夹下面所有的文件、包括子文件夹里面的文件?
- 如何对一个文件夹进行创建和删除?
- asp.net(C#)中如何获得一个文件夹的大小值(字节)? [ZT]
- C# 如何创建一个Windows服务
- (转)用eclipse创建一个j2ee的web工程后,左面projects窗口中的项目如何没有显示webRoot文件夹,除了src的文件夹,其他都不显示
- HOWTO:如何通过脚本创建一个文件夹的快捷方式
- C#中如何创建文件夹
- 如何用C#为SQL Server数据库创建一个新表?
- 我在 VSAN 数据存储中创建了一个文件夹,如何删除它呢?
- 如何用C#为SQL Server数据库创建一个新表?
- 如何创建一个隐藏的文件夹,并且打开这个隐藏的文件夹
- 【Unity&C#&数组】如何创建一个存放任何类型变量的数组
- 如何使用C#创建一个三层的数据库应用程序