本文整理汇总了C#中Windows.Storage.StorageFolder.GetFileAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.GetFileAsync方法的具体用法?C# StorageFolder.GetFileAsync怎么用?C# StorageFolder.GetFileAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.GetFileAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadFile
/// <summary>
/// Loads file from path
/// </summary>
/// <param name="filepath">path to a file</param>
/// <param name="folder">folder or null (to load from application folder)</param>
/// <returns></returns>
protected XDocument LoadFile(string filepath, StorageFolder folder)
{
try
{
StorageFile file;
//load file
if (folder == null)
{
var uri = new Uri(filepath);
file = StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
}
else
{
file = folder.GetFileAsync(filepath).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
}
//parse and return
var result = FileIO.ReadTextAsync(file).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
return XDocument.Parse(result);
}
catch
{
return null;
}
}
示例2: GetCachedUserPreference
public async Task< string> GetCachedUserPreference()
{
roamingFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file = await roamingFolder.GetFileAsync(filename);
string response = await FileIO.ReadTextAsync(file);
return response;
}
示例3: loadTextFile
public async Task<string> loadTextFile(StorageFolder folder, string key = null)
{
StorageFile myFile;
try
{
if (key == null)
{
myFile = await folder.GetFileAsync("myData.txt");
}
else
{
myFile = await folder.GetFileAsync(key + ".txt");
}
}
catch
{
myFile = null;
}
string text = "";
if (myFile != null)
{
text = await FileIO.ReadTextAsync(myFile);
}
return text;
}
示例4: GetFileAsync
/// <summary>
/// Gets File located in Local Storage,
/// Input file name may include folder paths seperated by "\\".
/// Example: filename = "Documentation\\Tutorial\\US\\ENG\\version.txt"
/// </summary>
/// <param name="filename">Name of file with full path.</param>
/// <param name="rootFolder">Parental folder.</param>
/// <returns>Target StorageFile.</returns>
public async Task<StorageFile> GetFileAsync(string filename, StorageFolder rootFolder = null)
{
if (string.IsNullOrEmpty(filename))
{
return null;
}
var semaphore = GetSemaphore(filename);
await semaphore.WaitAsync();
try
{
rootFolder = rootFolder ?? AntaresBaseFolder.Instance.RoamingFolder;
return await rootFolder.GetFileAsync(NormalizePath(filename));
}
catch (Exception ex)
{
LogManager.Instance.LogException(ex.ToString());
return null;
}
finally
{
semaphore.Release();
}
}
示例5: GetFile
// Working
/// <summary>
/// Gets a file from the file system.
/// </summary>
/// <param name="folder">The folder that contains the file.</param>
/// <param name="fileName">Name of the file.</param>
/// <returns>The file if it exists, null otherwise.</returns>
public static StorageFile GetFile(StorageFolder folder, string fileName)
{
try
{
return folder.GetFileAsync(fileName).AsTask().Result;
}
catch (Exception)
{
return null;
}
}
示例6: CopyNecessaryFilesFromCurrentPackage
internal async static Task CopyNecessaryFilesFromCurrentPackage(StorageFile diffManifestFile, StorageFolder currentPackageFolder, StorageFolder newPackageFolder)
{
await FileUtils.MergeFolders(currentPackageFolder, newPackageFolder);
JObject diffManifest = await CodePushUtils.GetJObjectFromFile(diffManifestFile);
var deletedFiles = (JArray)diffManifest["deletedFiles"];
foreach (string fileNameToDelete in deletedFiles)
{
StorageFile fileToDelete = await newPackageFolder.GetFileAsync(fileNameToDelete);
await fileToDelete.DeleteAsync();
}
}
示例7: 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();
}
示例8: ValidateFile
/// <summary>
/// Check to see if the file exists or not
/// </summary>
/// <param name="storagefolder">StorageFolder</param>
/// <param name="filename">string</param>
/// <returns>StorageFile or null</returns>
public static async Task<StorageFile> ValidateFile(StorageFolder storagefolder, string filename)
{
try
{
return await storagefolder.GetFileAsync(filename);
}
catch (FileNotFoundException)
{
return null;
}
}
示例9: Launch
public static async Task<bool> Launch(string filename, StorageFolder folder)
{
IStorageFile file = await folder.GetFileAsync(filename);
LauncherOptions options = new LauncherOptions();
//options.DisplayApplicationPicker = true;
//options.FallbackUri = GetUri(cole_protocol);
bool result = await Launcher.LaunchFileAsync(file, options);
return result;
}
示例10: FileExists
private static bool FileExists(StorageFolder folder, string fileName)
{
try
{
var task = folder.GetFileAsync(fileName).AsTask();
task.Wait();
return true;
}
catch { return false; }
}
示例11: DoesFileExistAsync
public static async Task<bool> DoesFileExistAsync(StorageFile file, StorageFolder folder, string fileName)
{
try
{
file = await folder.GetFileAsync(fileName);
return true;
}
catch
{
return false;
}
}
示例12: fileExistAsync
//public static async Task<bool> fileExistAsync(StorageFolder folder, string fileName)
public static async Task<bool> fileExistAsync(StorageFolder folder, string fileName)
{
try
{
await folder.GetFileAsync(fileName);
return true;
}
catch( Exception e )
{
return false;
}
}
示例13: DoesFileExistAsync
public static async Task<bool> DoesFileExistAsync(StorageFolder folder, string filename)
{
var folders = (await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFoldersAsync()).ToList();
try
{
await folder.GetFileAsync(filename);
return true;
}
catch
{
return false;
}
}
示例14: Setup
public async void Setup()
{
Folder = ApplicationData.Current.LocalFolder;
//połącz do pliku jesli istnieje
try
{
File = await Folder.GetFileAsync("json.txt");
}
//utwórz gdy go nie ma
catch
{
File = await Folder.CreateFileAsync("json.txt");
}
}
示例15: IsFileExists
/// <summary>
/// Checks if a file exists into the <see cref="StorageFolder"/>
/// </summary>
/// <param name="storageFolder">the folder where the function has to check</param>
/// <param name="fileName">the name of the file</param>
/// <returns>true if the file exists, false otherwise</returns>
public async Task<bool> IsFileExists(StorageFolder storageFolder, string fileName)
{
using (await InstanceLock.LockAsync())
{
try
{
fileName = fileName.Replace("/", "\\");
var file = await storageFolder.GetFileAsync(fileName);
return (file != null);
}
catch
{
return false;
}
}
}