本文整理汇总了C#中Windows.Storage.StorageFolder类的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder类的具体用法?C# StorageFolder怎么用?C# StorageFolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StorageFolder类属于Windows.Storage命名空间,在下文中一共展示了StorageFolder类的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: Init
async Task Init()
{
if (isInitialized != null)
return;
cacheFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.OpenIfExists);
try
{
isInitialized = InitializeWithJournal();
await isInitialized;
}
catch
{
StorageFolder folder = null;
try
{
folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(cacheFolderName);
}
catch (Exception)
{
}
if (folder != null)
{
await folder.DeleteAsync();
await ApplicationData.Current.LocalFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.ReplaceExisting);
}
}
await CleanCallback();
}
示例3: SaveAsync
/// <summary>
/// Writes a string to a text file.
/// </summary>
/// <param name="text">The text to write.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="folder">The folder.</param>
/// <param name="options">
/// The enum value that determines how responds if the fileName is the same
/// as the name of an existing file in the current folder. Defaults to ReplaceExisting.
/// </param>
/// <returns></returns>
public static async Task SaveAsync(
this string text,
string fileName,
StorageFolder folder = null,
CreationCollisionOption options = CreationCollisionOption.ReplaceExisting)
{
folder = folder ?? ApplicationData.Current.LocalFolder;
var file = await folder.CreateFileAsync(
fileName,
options);
using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
{
using (var outStream = fs.GetOutputStreamAt(0))
{
using (var dataWriter = new DataWriter(outStream))
{
if (text != null)
dataWriter.WriteString(text);
await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
await outStream.FlushAsync();
}
}
}
示例4: LimitedStorageCache
/// <summary>
/// Creates new LimitedStorageCache instance
/// </summary>
/// <param name="isf">StorageFolder instance to work with file system</param>
/// <param name="cacheDirectory">Directory to store cache, starting with two slashes "\\"</param>
/// <param name="cacheFileNameGenerator">ICacheFileNameGenerator instance to generate cache filenames</param>
/// <param name="cacheLimitInBytes">Limit of total cache size in bytes, for example 10 mb == 10 * 1024 * 1024</param>
/// <param name="cacheMaxLifetimeInMillis">Cache max lifetime in millis, for example two weeks = 2 * 7 * 24 * 60 * 60 * 1000; default value == one week; pass value <= 0 to disable max cache lifetime</param>
public LimitedStorageCache(StorageFolder isf, string cacheDirectory,
ICacheGenerator cacheFileNameGenerator, long cacheLimitInBytes, long cacheMaxLifetimeInMillis = DefaultCacheMaxLifetimeInMillis)
: base(isf, cacheDirectory, cacheFileNameGenerator, cacheMaxLifetimeInMillis)
{
_cacheLimitInBytes = cacheLimitInBytes;
BeginCountCurrentCacheSize();
}
示例5: 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();
}
}
示例6: GetAllVideos
private async void GetAllVideos(StorageFolder KnownFolders, QueryOptions QueryOptions)
{
StorageFileQueryResult query = KnownFolders.CreateFileQueryWithOptions(QueryOptions);
IReadOnlyList<StorageFile> folderList = await query.GetFilesAsync();
// Get all the videos in the folder past in parameter
int id = 0;
foreach (StorageFile file in folderList)
{
using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.VideosView, 200, ThumbnailOptions.UseCurrentScale))
{
// Get video's properties
VideoProperties videoProperties = await file.Properties.GetVideoPropertiesAsync();
BitmapImage VideoCover = new BitmapImage();
VideoCover.SetSource(thumbnail);
Video video = new Video();
video.Id = id;
video.Name = file.Name;
video.DateCreated = file.DateCreated.UtcDateTime;
video.FileType = file.FileType;
video.VideoPath = file.Path;
video.Duration = videoProperties.Duration;
video.VideoFile = file;
video.VideoCover = VideoCover;
// Add the video to the ObservableCollection
Videos.Add(video);
id++;
}
}
}
示例7: Inflate
private static async Task Inflate(StorageFile zipFile, StorageFolder destFolder)
{
if (zipFile == null)
{
throw new Exception("StorageFile (zipFile) passed to Inflate is null");
}
else if (destFolder == null)
{
throw new Exception("StorageFolder (destFolder) passed to Inflate is null");
}
Stream zipStream = await zipFile.OpenStreamForReadAsync();
using (ZipArchive zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Read))
{
//Debug.WriteLine("Count = " + zipArchive.Entries.Count);
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
//Debug.WriteLine("Extracting {0} to {1}", entry.FullName, destFolder.Path);
try
{
await InflateEntryAsync(entry, destFolder);
}
catch (Exception ex)
{
Debug.WriteLine("Exception: " + ex.Message);
}
}
}
}
示例8: GetPictures
public GetPictures(StorageFolder folder)
{
Pictures = new ObservableCollection<Picture>();
allPictures = new ObservableCollection<StorageFile>();
GetAllPictures(folder);
}
示例9: GetFiles
public async Task<IEnumerable<IFile>> GetFiles()
{
if (m_files == null)
{
m_files = new List<IFile>();
foreach (StorageFile file in await m_folder.GetFilesAsync())
{
//don't ping the network
//make the configurable later
if (!file.Attributes.HasFlag(FileAttributes.LocallyIncomplete))
{
IFile f = await File.GetNew(file, m_root);
m_files.Add(f);
}
}
}
//we want to clear out the StorageFolder so that it can be
//garbage collected after both the files and directories
//have been retrieved
if (m_dirs != null)
{
m_folder = null;
}
return m_files;
}
示例10: Directory
public Directory(StorageFolder folder, StorageFolder root)
{
m_folder = folder;
m_root = root;
m_path = folder.Path;
}
示例11: Init
async Task Init()
{
try
{
cacheFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.OpenIfExists);
await InitializeEntries().ConfigureAwait(false);
}
catch
{
StorageFolder folder = null;
try
{
folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(cacheFolderName);
}
catch (Exception)
{
}
if (folder != null)
{
await folder.DeleteAsync();
await ApplicationData.Current.LocalFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.ReplaceExisting);
}
}
finally
{
var task = CleanCallback();
}
}
示例12: FileSnapshotTarget
static FileSnapshotTarget()
{
// create a task to load the folder...
_setupTask = Task<Task<StorageFolder>>.Factory.StartNew(async () =>
{
// get...
var root = ApplicationData.Current.LocalFolder;
try
{
await root.CreateFolderAsync(LogFolderName);
}
catch (FileNotFoundException ex)
{
SinkException(ex);
}
// load...
return await root.GetFolderAsync(LogFolderName);
}).ContinueWith(async (t, args) =>
{
// set...
LogFolder = await t.Result;
}, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.LongRunning);
}
示例13: FileDbCache
public FileDbCache(string name = null, StorageFolder folder = null)
{
if (string.IsNullOrEmpty(name))
{
name = TileImageLoader.DefaultCacheName;
}
if (string.IsNullOrEmpty(Path.GetExtension(name)))
{
name += ".fdb";
}
if (folder == null)
{
folder = TileImageLoader.DefaultCacheFolder;
}
this.folder = folder;
this.name = name;
Application.Current.Resuming += async (s, e) => await Open();
Application.Current.Suspending += (s, e) => Close();
var task = Open();
}
示例14: 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
}
}
示例15: RegisterUnhandledErrorHandler
private async Task RegisterUnhandledErrorHandler()
{
logUploadFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("MyLogFile",
CreationCollisionOption.OpenIfExists);
CoreApplication.UnhandledErrorDetected += CoreApplication_UnhandledErrorDetected;
}