本文整理汇总了C#中Windows.Storage.StorageFolder.GetFolderAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.GetFolderAsync方法的具体用法?C# StorageFolder.GetFolderAsync怎么用?C# StorageFolder.GetFolderAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.GetFolderAsync方法的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: AddDownload
public static async Task<bool> AddDownload(string filename, string url, DownloadType type, StorageFolder folder = null)
{
try
{
var down = new BackgroundDownloader();
down.TransferGroup = BackgroundTransferGroup.CreateGroup("other");
if (folder == null)
{
folder = await KnownFolders.MusicLibrary.GetFolderAsync("kgdownload");
switch (type)
{
case DownloadType.song:
folder = await folder.GetFolderAsync("song");
down.TransferGroup = BackgroundTransferGroup.CreateGroup("song");
break;
case DownloadType.mv:
folder = await folder.GetFolderAsync("mv");
down.TransferGroup = BackgroundTransferGroup.CreateGroup("mv");
break;
case DownloadType.other:
folder = await folder.GetFolderAsync("other");
down.TransferGroup = BackgroundTransferGroup.CreateGroup("other");
break;
default:
break;
}
}
var files= (await folder.GetFilesAsync()).ToList();
foreach (var item in files)
{
await item.DeleteAsync();
}
var file = await folder.CreateFileAsync(filename);
down.FailureToastNotification = DownloadToast(filename, DownloadResult.Failure);
down.SuccessToastNotification = DownloadToast(filename, DownloadResult.Success);
var opera= down.CreateDownload(new Uri(url), file);
opera.CostPolicy = BackgroundTransferCostPolicy.Always;
opera.StartAsync();
return true;
}
catch (Exception)
{
return false;
}
}
示例3: copyToLocal
//-------------------------------------------------------------------------------
#region +[static]copyToLocal 選択フォルダからローカルへコピー
//-------------------------------------------------------------------------------
//
public async static void copyToLocal(StorageFolder rootDir, Action<int, int, int, int> progressReportFunc = null) {
var localDir = Windows.Storage.ApplicationData.Current.LocalFolder;
var dataDir_dst = await localDir.CreateFolderAsync(DATA_FOLDER_NAME, CreationCollisionOption.OpenIfExists);
var dataDir_src = await rootDir.GetFolderAsync("CDATA");
var fileList = await dataDir_src.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.DefaultQuery);
if (progressReportFunc != null) { progressReportFunc(0, 2, 0, fileList.Count); }
int count = 0;
foreach (var file in fileList) {
await file.CopyAsync(dataDir_dst, file.Name, NameCollisionOption.ReplaceExisting);
count++;
if (progressReportFunc != null) { progressReportFunc(0, 2, count, fileList.Count); }
}
var imageDir = await localDir.CreateFolderAsync(IMAGES_FOLDER_NAME, CreationCollisionOption.OpenIfExists);
var imgFile = await rootDir.GetFileAsync("C084CUTL.CCZ");
MemoryStream ms = new MemoryStream();
using (Stream stream = (await imgFile.OpenReadAsync()).AsStream()) {
byte[] buf = new byte[0x10000000];
while (true) {
int r = stream.Read(buf, 0, buf.Length);
if (r <= 0) { break; }
ms.Write(buf, 0, r);
}
}
var zipArchive = new ZipArchive(ms);
if (progressReportFunc != null) { progressReportFunc(1, 2, 0, zipArchive.Entries.Count); }
count = 0;
foreach (var entry in zipArchive.Entries) {
string name = entry.Name;
using (Stream dstStr = await imageDir.OpenStreamForWriteAsync(name, CreationCollisionOption.ReplaceExisting))
using (Stream srcStr = entry.Open()) {
int size;
const int BUF_SIZE = 0x100000;
byte[] buf = new byte[BUF_SIZE];
size = srcStr.Read(buf, 0, BUF_SIZE);
while (size > 0) {
dstStr.Write(buf, 0, size);
size = srcStr.Read(buf, 0, BUF_SIZE);
}
count++;
if (progressReportFunc != null) { progressReportFunc(1, 2, count, zipArchive.Entries.Count); }
}
}
if (progressReportFunc != null) { progressReportFunc(2, 2, count, zipArchive.Entries.Count); }
ms.Dispose();
zipArchive.Dispose();
}
示例4: GetFolder
// Working
/// <summary>
/// Gets a folder from the file system.
/// </summary>
/// <param name="folder">The folder that contains the folder.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns>The folder if it exists, null otherwise.</returns>
public static StorageFolder GetFolder(StorageFolder folder, string folderName)
{
try
{
return folder.GetFolderAsync(folderName).AsTask().Result;
}
catch (Exception)
{
return null;
}
}
示例5: checkFileSystem
/// <summary>
/// check file system
/// </summary>
/// <param name="rootFolder"></param>
private async Task checkFileSystem(StorageFolder rootFolder)
{
try
{
StorageFile metaFile = await rootFolder.GetFileAsync(CoreDriver.META_DATA);
StorageFolder mdFolder = await rootFolder.GetFolderAsync(
MasterDataManagement.MASTER_DATA_FOLDER);
StorageFolder transFolder = await rootFolder.GetFolderAsync(
TransactionDataManagement.TRANSACTION_DATA_FOLDER);
IReadOnlyList<StorageFile> files = await mdFolder.GetFilesAsync();
Assert.AreEqual(Enum.GetValues(typeof(MasterDataType)).Length, files.Count);
files = await transFolder.GetFilesAsync();
Assert.AreEqual(1, files.Count);
}
catch (Exception e)
{
Assert.Fail(e.ToString());
}
}
示例6: 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();
}
}
}
}
}
示例7: 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);
}
示例8: ReadCsvFile
public async Task ReadCsvFile(StorageFolder folder, string filename)
{
// assuming a folder named Data exists
var folderContents = await folder.GetFolderAsync("Data");
var file = await folderContents.GetFileAsync(filename);
IList<string> content = await Windows.Storage.FileIO.ReadLinesAsync(file);
string headings = content[0];
_columnHeadings = headings.Split(',');
for (int i = 1; i < content.Count; i++)
{
string line = content[i];
string[] csvLine = line.Split(',');
_dataset.Add(csvLine);
}
}
示例9: GetStorageFileFromPathList
async Task<StorageFile> GetStorageFileFromPathList(StorageFolder sf, List<string> filepath)
{
if (sf == null || filepath == null) return null;
bool getFileCrawler = true;
while (getFileCrawler || filepath.Count > 1)
{
sf = await sf.GetFolderAsync(filepath.FirstOrDefault<string>());
if (sf != null)
{
filepath.RemoveAt(0);
}
else
{
getFileCrawler = false;
}
}
if (sf != null && filepath.Count == 1)
{
return await sf.GetFileAsync(filepath.FirstOrDefault<string>());
}
return null;
}
示例10: accessfolder
public async void accessfolder(StorageFolder folder)
{
if (string.Equals(this.folder.Path, folder.Path))
{
return;
}
writetext = false;
StorageApplicationPermissions.FutureAccessList.Clear();
StorageApplicationPermissions.FutureAccessList.Add(folder);
//image 文件夹
string str = "image";
StorageFolder image = null;
try
{
image = await folder.GetFolderAsync(str);
}
catch
{
}
if (image == null)
{
image = await folder.CreateFolderAsync(str, CreationCollisionOption.OpenIfExists);
}
//if (!this.folder.Path.Equals(folder.Path))
//{
await storage();
//}
this.folder = folder;
}
示例11: DeleteFolderAsync
/// <summary>
/// Deletes folder.
/// </summary>
/// <param name="folderPath">Folder to be deleted.</param>
/// <param name="rootFolder">Parental Folder contains to-be-deleted folder.</param>
/// <returns>TRUE if successful, else FALSE.</returns>
public async Task<bool> DeleteFolderAsync(string folderPath, StorageFolder rootFolder = null)
{
if (string.IsNullOrEmpty(folderPath))
{
return false;
}
rootFolder = rootFolder ?? AntaresBaseFolder.Instance.RoamingFolder;
StorageFolder deleteFolder;
try
{
deleteFolder = await rootFolder.GetFolderAsync(Path.GetDirectoryName(folderPath));
}
catch (Exception ex)
{
LogManager.Instance.LogException(ex.ToString());
return false;
}
if (deleteFolder != null)
{
await deleteFolder.DeleteAsync();
}
return true;
}
示例12: GetFolder
public static async Task<StorageFolder> GetFolder(StorageFolder baseFolder, string folderName)
{
var found = true;
StorageFolder folder = null;
try {
if (String.IsNullOrEmpty(folderName))
folder = baseFolder;
else
folder = await baseFolder.GetFolderAsync(folderName);
} catch (FileNotFoundException) {
found = false;
}
if (!found && folderName != null)
folder = await baseFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists);
return folder;
}
示例13: FileProvider
public FileProvider(StorageFolder resourceLocation, String location, string fileType)
{
_fileType = fileType;
_fileFolder = resourceLocation.GetFolderAsync(location).AsTask().WaitAndUnwrapException();
}
示例14: _createFolder
async Task<bool> _createFolder(List<string> path, StorageFolder currentFolder)
{
if (path.Count == 0)
{
return false;
}
var current = path.FirstOrDefault();
if (current == null)
{
return false;
}
path.RemoveAt(0);
try
{
if (!await _folderExists(current, currentFolder))
{
await currentFolder.CreateFolderAsync(current);
}
}
catch { }
if (path.Count == 0)
{
return await _folderExists(current, currentFolder);
}
return await _createFolder(path, await currentFolder.GetFolderAsync(current));
}
示例15: IfFolderExistsAsync
/// <summary>
/// It checks if the specified folder exists.
/// </summary>
/// <param name="storageFolder">The container folder</param>
/// <param name="subFolderName">The sub folder name</param>
/// <returns></returns>
private static async Task<bool> IfFolderExistsAsync(StorageFolder storageFolder, string subFolderName)
{
try
{
await storageFolder.GetFolderAsync(subFolderName);
}
catch (FileNotFoundException)
{
return false;
}
catch (Exception)
{
throw;
}
return true;
}