本文整理汇总了C#中Windows.Storage.StorageFolder.CreateFolderAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.CreateFolderAsync方法的具体用法?C# StorageFolder.CreateFolderAsync怎么用?C# StorageFolder.CreateFolderAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.CreateFolderAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitFolders
public async void InitFolders()
{
_localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var folderName = "";
try
{
folderName = "medium";
if (Directory.Exists($"{_localFolder.Path}\\{folderName}")) _mediumFolder = await _localFolder.GetFolderAsync(folderName);
else _mediumFolder = await _localFolder.CreateFolderAsync(folderName);
folderName = "thumb";
if (Directory.Exists($"{_localFolder.Path}\\{folderName}")) _thumbFolder = await _localFolder.GetFolderAsync(folderName);
else _thumbFolder = await _localFolder.CreateFolderAsync(folderName);
folderName = "original";
if (Directory.Exists($"{_localFolder.Path}\\{folderName}")) _originalFolder = await _localFolder.GetFolderAsync(folderName);
else _originalFolder = await _localFolder.CreateFolderAsync(folderName);
folderName = "tile";
if (Directory.Exists($"{_localFolder.Path}\\{folderName}")) _tileFolder = await _localFolder.GetFolderAsync(folderName);
else _tileFolder = await _localFolder.CreateFolderAsync(folderName);
}
catch //(System.IO.FileNotFoundException ex)
{
//todo: what would ever cause this ??! need to work out how to handle this type of error
}
}
示例2: Start
/// <summary>
/// 要下载调用这个方法
/// </summary>
/// <param name="url">下载的文件网址的来源</param>
/// <returns></returns>
public static async Task Start(string filename,string url,DownloadType type,StorageFolder folder=null)
{
try
{
Uri uri = new Uri(Uri.EscapeUriString(url), UriKind.RelativeOrAbsolute);
BackgroundDownloader downloader = new BackgroundDownloader();
if (folder==null)
{
folder = await KnownFolders.MusicLibrary.CreateFolderAsync("kgdownload", CreationCollisionOption.OpenIfExists);
switch (type)
{
case DownloadType.song:
folder = await folder.CreateFolderAsync("song", CreationCollisionOption.OpenIfExists);
downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("song");
break;
case DownloadType.mv:
folder = await folder.CreateFolderAsync("mv", CreationCollisionOption.OpenIfExists);
downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("mv");
break;
case DownloadType.other:
folder = await folder.CreateFolderAsync("other", CreationCollisionOption.OpenIfExists);
downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("other");
break;
default:
break;
}
}else
{
downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("other");
}
//string name = uri.ToString().Substring(uri.ToString().LastIndexOf("/"), uri.ToString().Length);
string name = filename;
StorageFile file = await folder.CreateFileAsync(name, CreationCollisionOption.GenerateUniqueName);
downloader.FailureToastNotification = DownloadedToast.Done(filename, DownloadedToast.DownResult.Fa);
downloader.SuccessToastNotification = DownloadedToast.Done(filename, DownloadedToast.DownResult.Su);
var download = downloader.CreateDownload(new Uri(url), file);
TransferModel transfer = new TransferModel();
transfer.DownloadOperation = download;
transfer.Source = download.RequestedUri.ToString();
transfer.Destination = download.ResultFile.Path;
transfer.BytesReceived = download.Progress.BytesReceived;
transfer.TotalBytesToReceive = download.Progress.TotalBytesToReceive;
transfer.Progress = 0;
transfers.Add(transfer);
Progress<DownloadOperation> progressCallback = new Progress<DownloadOperation>(DownloadProgress);
download.StartAsync().AsTask(cancelToken.Token, progressCallback);
}
catch
{
await new MessageDialog("链接已失效!").ShowAsync();
}
}
示例3: StorageCacheBase
protected StorageCacheBase(StorageFolder sf, string cacheDirectory, ICacheGenerator cacheFileNameGenerator, long cacheMaxLifetimeInMillis = DefaultCacheMaxLifetimeInMillis)
{
if (sf == null)
{
throw new ArgumentNullException("isf");
}
if (string.IsNullOrEmpty(cacheDirectory))
{
throw new ArgumentException("cacheDirectory name could not be null or empty");
}
if (cacheDirectory.StartsWith("\\"))
{
throw new ArgumentException("cacheDirectory name shouldn't starts with double slashes: \\");
}
if (cacheFileNameGenerator == null)
{
throw new ArgumentNullException("cacheFileNameGenerator");
}
SF = sf;
CacheDirectory = cacheDirectory;
CacheFileNameGenerator = cacheFileNameGenerator;
CacheMaxLifetimeInMillis = cacheMaxLifetimeInMillis;
// Creating cache directory if it not exists
SF.CreateFolderAsync(CacheDirectory).AsTask();
}
示例4: ExtractTarArchiveAsync
public async static Task ExtractTarArchiveAsync( Stream archiveStream, StorageFolder destinationFolder )
{
using( TarReader reader = TarReader.Open( archiveStream ) )
{
while( reader.MoveToNextEntry() )
{
if( !reader.Entry.IsDirectory )
{
using( var entryStream = reader.OpenEntryStream() )
{
string fileName = Path.GetFileName( reader.Entry.Key );
string folderName = Path.GetDirectoryName( reader.Entry.Key );
StorageFolder folder = destinationFolder;
if( string.IsNullOrWhiteSpace( folderName ) == false )
{
folder = await destinationFolder.CreateFolderAsync( folderName, CreationCollisionOption.OpenIfExists );
}
StorageFile file = await folder.CreateFileAsync( fileName, CreationCollisionOption.OpenIfExists );
using( Stream fileStream = await file.OpenStreamForWriteAsync().ConfigureAwait( false ) )
{
await entryStream.CopyToAsync( fileStream );
}
}
}
}
}
}
示例5: Init
public async Task Init(string appname) {
var devices = Windows.Storage.KnownFolders.RemovableDevices;
var sdCards = await devices.GetFoldersAsync();
if (sdCards.Count == 0) return;
_SDCard = sdCards[0];
string foldername = string.Format("{0}_Log", appname);
_LogFolder = await _SDCard.CreateFolderAsync(foldername, CreationCollisionOption.OpenIfExists);
_FileName = string.Format("{0:yyyy-MM-dd}.txt", DateTime.Now);
_Stream = await _LogFolder.OpenStreamForWriteAsync(_FileName, CreationCollisionOption.OpenIfExists);
}
示例6: MergeFolders
internal async static Task MergeFolders(StorageFolder source, StorageFolder target)
{
foreach (StorageFile sourceFile in await source.GetFilesAsync())
{
await sourceFile.CopyAndReplaceAsync(await target.CreateFileAsync(sourceFile.Name, CreationCollisionOption.OpenIfExists));
}
foreach (StorageFolder sourceDirectory in await source.GetFoldersAsync())
{
StorageFolder nextTargetSubDir = await target.CreateFolderAsync(sourceDirectory.Name, CreationCollisionOption.OpenIfExists);
await MergeFolders(sourceDirectory, nextTargetSubDir);
}
}
示例7: UnzipZipArchiveEntryAsync
/// <summary>
/// Unzips ZipArchiveEntry asynchronously.
/// </summary>
/// <param name="entry">The entry which needs to be unzipped</param>
/// <param name="filePath">The entry's full name</param>
/// <param name="unzipFolder">The unzip folder</param>
/// <returns></returns>
public static async Task UnzipZipArchiveEntryAsync(ZipArchiveEntry entry, string filePath, StorageFolder unzipFolder)
{
if (IfPathContainDirectory(filePath))
{
// Create sub folder
string subFolderName = Path.GetDirectoryName(filePath);
bool isSubFolderExist = await IfFolderExistsAsync(unzipFolder, subFolderName);
StorageFolder subFolder;
if (!isSubFolderExist)
{
// Create the sub folder.
subFolder =
await unzipFolder.CreateFolderAsync(subFolderName, CreationCollisionOption.ReplaceExisting);
}
else
{
// Just get the folder.
subFolder =
await unzipFolder.GetFolderAsync(subFolderName);
}
// All sub folders have been created. Just pass the file name to the Unzip function.
string newFilePath = Path.GetFileName(filePath);
if (!string.IsNullOrEmpty(newFilePath))
{
// Unzip file iteratively.
await UnzipZipArchiveEntryAsync(entry, newFilePath, subFolder);
}
}
else
{
// Read uncompressed contents
using (Stream entryStream = entry.Open())
{
byte[] buffer = new byte[entry.Length];
entryStream.Read(buffer, 0, buffer.Length);
// Create a file to store the contents
StorageFile uncompressedFile = await unzipFolder.CreateFileAsync
(entry.Name, CreationCollisionOption.ReplaceExisting);
// Store the contents
using (IRandomAccessStream uncompressedFileStream =
await uncompressedFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (Stream outstream = uncompressedFileStream.AsStreamForWrite())
{
outstream.Write(buffer, 0, buffer.Length);
outstream.Flush();
}
}
}
}
}
示例8: GetOrCreateSubFolder
private static async Task<StorageFolder> GetOrCreateSubFolder(StorageFolder pOutFolder, string pDirectoryName)
{
try
{
var folder = await pOutFolder.GetFolderAsync(pDirectoryName);
if (folder != null)
return folder;
}
catch (Exception)
{
}
return await pOutFolder.CreateFolderAsync(pDirectoryName, CreationCollisionOption.ReplaceExisting);
}
示例9: InflateEntryAsync
private static async Task InflateEntryAsync(ZipArchiveEntry entry, StorageFolder destFolder, bool createSub = false)
{
string filePath = entry.FullName;
if (!string.IsNullOrEmpty(filePath) && filePath.Contains("/") && !createSub)
{
// Create sub folder
string subFolderName = Path.GetDirectoryName(filePath);
StorageFolder subFolder;
// Create or return the sub folder.
subFolder = await destFolder.CreateFolderAsync(subFolderName, CreationCollisionOption.OpenIfExists);
string newFilePath = Path.GetFileName(filePath);
if (!string.IsNullOrEmpty(newFilePath))
{
// Unzip file iteratively.
await InflateEntryAsync(entry, subFolder, true);
}
}
else
{
// Read uncompressed contents
using (Stream entryStream = entry.Open())
{
byte[] buffer = new byte[entry.Length];
entryStream.Read(buffer, 0, buffer.Length);
// Create a file to store the contents
StorageFile uncompressedFile = await destFolder.CreateFileAsync(entry.Name, CreationCollisionOption.ReplaceExisting);
// Store the contents
using (IRandomAccessStream uncompressedFileStream =
await uncompressedFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (Stream outstream = uncompressedFileStream.AsStreamForWrite())
{
outstream.Write(buffer, 0, buffer.Length);
outstream.Flush();
}
}
}
}
}
示例10: copyFolder
async public static void copyFolder(StorageFolder from, StorageFolder _to)
{
StorageFolder to = await _to.CreateFolderAsync(from.Name, CreationCollisionOption.OpenIfExists);
IReadOnlyList<StorageFile> storageFiles = await from.GetFilesAsync();
foreach (var storageFile in storageFiles)
{
await storageFile.CopyAsync(to, storageFile.Name, NameCollisionOption.ReplaceExisting);
}
//IReadOnlyList<StorageFolder> storageFolders = await from.GetFoldersAsync();
var queryResult = from.CreateFolderQuery();
IReadOnlyList<StorageFolder> storageFolders = await queryResult.GetFoldersAsync();
foreach (var storageFolder in storageFolders)
{
copyFolder(storageFolder, to);
}
}
示例11: ImageFileCache
public ImageFileCache(string name = null, StorageFolder folder = null)
{
if (string.IsNullOrEmpty(name))
{
name = TileImageLoader.DefaultCacheName;
}
if (folder == null)
{
folder = TileImageLoader.DefaultCacheFolder;
}
this.name = name;
folder.CreateFolderAsync(name, CreationCollisionOption.OpenIfExists).Completed = (o, s) =>
{
rootFolder = o.GetResults();
Debug.WriteLine("Created ImageFileCache in {0}.", rootFolder.Path);
};
}
示例12: OpenComicCollection
private async void OpenComicCollection(StorageFolder chosenFolder, StorageFolder collections)
{
LoadingGridVisible(true);
List<StorageFile> files = await RecursivelySearchForFiles(chosenFolder);
StorageFolder collectionFolder = (StorageFolder)await collections.TryGetItemAsync(chosenFolder.Name);
if (collectionFolder == null)
{
collectionFolder = await collections.CreateFolderAsync(chosenFolder.Name);
}
else
{
ShowWarning("Collection already exist!", "Adding new comics");
}
foreach (StorageFile sourceFile in files)
{
StorageFolder destFolder = (StorageFolder)await collectionFolder.TryGetItemAsync(sourceFile.Name);
if (destFolder == null)
{
destFolder = await collectionFolder.CreateFolderAsync(sourceFile.Name);
try
{
DefaultViewModel["LoadingFile"] = sourceFile.Name;
if (sourceFile.FileType.Equals("cbz") || sourceFile.FileType.Equals(".cbz"))
await FolderZip.UnZipFile(sourceFile, destFolder);
else if (sourceFile.FileType.Equals("cbr") || sourceFile.FileType.Equals(".cbr"))
await FolderZip.UnRarFile(sourceFile, destFolder);
}
catch (InvalidFormatException exception)
{
ShowWarning("Error opening file:" + sourceFile.Name, "Please try again");
}
}
LoadingBar.Value += (1.0 / files.Count()) * 100;
}
await CreateCollectionTiles();
CollectionViews.Clear();
foreach (CollectionTile tile in CollectionTiles)
{
CollectionViews.Add(new CollectionView(tile));
}
defaultViewModel["ComicTiles"] = ComicTiles;
defaultViewModel["CollectionViews"] = CollectionViews;
LoadingGridVisible(false);
}
示例13: CreateFolder
/// <summary>
/// Create a folder in the current rootFolder.
/// </summary>
/// <param name="folderName">Name of the folder to be created. This does not have to be an immediate sub-folder of the current folder.</param>
/// <param name="rootFolder">The current folder.</param>
/// <returns>None.</returns>
public async Task<StorageFolder> CreateFolder(string folderName, StorageFolder rootFolder)
{
if (string.IsNullOrEmpty(folderName))
{
return rootFolder;
}
rootFolder = rootFolder ?? AntaresBaseFolder.Instance.RoamingFolder;
folderName = NormalizePath(folderName);
var startIndex = folderName.IndexOf('\\');
if (startIndex == -1)
{
return await rootFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists);
}
rootFolder = await rootFolder.CreateFolderAsync(folderName.Substring(0, startIndex), CreationCollisionOption.OpenIfExists);
folderName = folderName.Substring(startIndex + 1);
return await CreateFolder(folderName, rootFolder);
}
示例14: CreateDirectory
/// <summary>
/// Creates a directory into a specified <see cref="StorageFolder"/> by creating all missing <see cref="StorageFolder"/>
/// </summary>
/// <param name="storageFolder">the folder where the function has to check</param>
/// <param name="path">the directory path</param>
/// <returns>true in case of success. false otherwise</returns>
public async Task<bool> CreateDirectory(StorageFolder storageFolder, string path)
{
using (await InstanceLock.LockAsync())
{
var isCreated = true;
try
{
var folderNames = path.Split(new []{'/'}, StringSplitOptions.RemoveEmptyEntries).ToList();
// Cleans ".." in uri
while (folderNames.Any(f => f.Equals("..")) == true)
{
var index = folderNames.FindIndex(f => f.Equals(".."));
if (index == 0)
{
throw new ArgumentException("Invalid specified path, can't access of the parent of the source folder.");
}
folderNames.RemoveRange(index - 1, 2);
}
// Creates all missing folders
foreach(var folderName in folderNames)
{
storageFolder = await storageFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists);
}
}
catch
{
isCreated = false;
}
return isCreated;
}
}
示例15: storage
private async Task storage(StorageFolder folder)
{
if (string.IsNullOrEmpty(name))
{
string str = "请输入标题.md";
file = await folder.CreateFileAsync(str, CreationCollisionOption.GenerateUniqueName);
//name = file.Name;
int n;
n = name.IndexOf(".md");
if (n > 0)
{
str = name.Substring(0, n);
}
this.folder = await folder.CreateFolderAsync(str, CreationCollisionOption.GenerateUniqueName);
}
else
{
if (name == "README.md")
{
this.folder = await folder.CreateFolderAsync("image", CreationCollisionOption.OpenIfExists);
}
else
{
this.folder = await folder.CreateFolderAsync(name, CreationCollisionOption.OpenIfExists);
}
}
}