本文整理汇总了C#中System.IO.DirectoryInfo.CreateFolderResourceInfo方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.CreateFolderResourceInfo方法的具体用法?C# DirectoryInfo.CreateFolderResourceInfo怎么用?C# DirectoryInfo.CreateFolderResourceInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.CreateFolderResourceInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Creating_Item_From_Inexisting_Folder_Should_Provides_Names_And_Default_Properties
public void Creating_Item_From_Inexisting_Folder_Should_Provides_Names_And_Default_Properties()
{
DirectoryInfo di = new DirectoryInfo("test");
Assert.IsFalse(di.Exists);
VirtualFolderInfo item = di.CreateFolderResourceInfo();
Assert.AreEqual("test", item.Name);
Assert.AreEqual(di.FullName, item.FullName);
//timestamps should be null
Assert.IsNull(item.CreationTime);
Assert.IsNull(item.LastAccessTime);
Assert.IsNull(item.LastWriteTime);
//the item should not be hidden / readonly
Assert.IsFalse(item.IsHidden);
Assert.IsFalse(item.IsReadOnly);
//item is not root folder
Assert.IsFalse(item.IsRootFolder);
}
示例2: CreateFolder
/// <summary>
/// Creates a new folder in the file system.
/// </summary>
/// <param name="parentFolderPath">The qualified name of the designated parent folder, which
/// needs to exists, and provide write access.</param>
/// <param name="folderName">The name of the folder to be created.</param>
/// <returns>A <see cref="VirtualFileInfo"/> instance which represents
/// the created folder.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="parentFolderPath"/>
/// is a null reference.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="folderName"/>
/// is a null reference.</exception>
/// <exception cref="ResourceAccessException">In case of invalid or prohibited
/// resource access.</exception>
/// <exception cref="VirtualResourceNotFoundException">If no folder exists that
/// matches the submitted <paramref name="parentFolderPath"/>.</exception>
/// <exception cref="ResourceOverwriteException">If the folder already exists on the file
/// system.</exception>
public override VirtualFolderInfo CreateFolder(string parentFolderPath, string folderName)
{
if (parentFolderPath == null) throw new ArgumentNullException("parentFolderPath");
if (folderName == null) throw new ArgumentNullException("folderName");
string absoluteParentPath;
var parent = GetFolderInfoInternal(parentFolderPath, true, out absoluteParentPath);
if (RootDirectory == null && parent.IsRootFolder)
{
VfsLog.Debug("Blocked attempt to create a folder '{0}' at system root.", folderName);
throw new ResourceAccessException("Folders cannot be created at the system root.");
}
//create path of the child
string childPath = PathUtil.GetAbsolutePath(folderName, new DirectoryInfo(absoluteParentPath));
//make sure the folder name is not a relative path that points outside the scope
if (RootDirectory != null && !RootDirectory.IsParentOf(childPath))
{
string msg = "Blocked attempt to create folder outside of root through with parent '{0}' and folder name '{1}'";
VfsLog.Warn(msg, absoluteParentPath, folderName);
throw new ResourceAccessException("Invalid file path: " + folderName);
}
var directory = new DirectoryInfo(childPath);
if (directory.Exists)
{
//log and create exception if the directory already exists
VfsLog.Debug("Blocked attempt to recreate directory '{0}'", directory.FullName);
string relativePath = PathUtil.GetRelativePath(childPath, RootDirectory);
string msg = String.Format("The folder '{0}' already exists.", relativePath);
throw new ResourceOverwriteException(msg);
}
try
{
//create directory
directory.Create();
}
catch (Exception e)
{
const string msg = "Exception occurred when trying to create new folder '{0}' for parent '{1}'";
VfsLog.Debug(e, msg, folderName, parent.FullName);
throw new ResourceAccessException("Could not create folder", e);
}
var folder = directory.CreateFolderResourceInfo();
//adjust and return
if (UseRelativePaths) folder.MakePathsRelativeTo(RootDirectory);
return folder;
}
示例3: GetFolderInfoInternal
protected VirtualFolderInfo GetFolderInfoInternal(string virtualFolderPath, bool mustExist, out string absolutePath)
{
try
{
//make sure we operate on absolute paths
absolutePath = PathUtil.GetAbsolutePath(virtualFolderPath ?? "", RootDirectory);
if (IsRootPath(absolutePath))
{
return GetFileSystemRoot();
}
var di = new DirectoryInfo(absolutePath);
VirtualFolderInfo folderInfo = di.CreateFolderResourceInfo();
//convert to relative paths if required (also prevents qualified paths in validation exceptions)
if (UseRelativePaths) folderInfo.MakePathsRelativeTo(RootDirectory);
//make sure the user is allowed to access the resource
ValidateResourceAccess(folderInfo);
//verify folder exists on FS
if(mustExist) folderInfo.VerifyDirectoryExists(RootDirectory);
return folderInfo;
}
catch (VfsException)
{
//just bubble internal exceptions
throw;
}
catch (Exception e)
{
VfsLog.Debug(e, "Could not create directory based on path '{0}' with root '{1}'", virtualFolderPath,
RootDirectory);
throw new ResourceAccessException("Invalid path submitted: " + virtualFolderPath);
}
}
示例4: ResolveFolderResourcePath2
public FolderItem ResolveFolderResourcePath2(string submittedFolderPath, FileSystemTask context) {
//make sure we operate on absolute paths
string absolutePath = PathUtil.GetAbsolutePath(submittedFolderPath ?? "", RootDirectory);
if (IsRootPath(absolutePath)) {
return GetFileSystemRootImplementation() as FolderItem;
}
var di = new DirectoryInfo(absolutePath);
VirtualFolderInfo folderInfo = di.CreateFolderResourceInfo();
var item = new FolderItem(di, folderInfo);
//convert to relative paths if required (also prevents qualified paths in validation exceptions)
if (UseRelativePaths) item.MakePathsRelativeTo(RootDirectory);
ValidateFolderRequestAccess(item, submittedFolderPath, context);
return item;
}