Exemplo n.º 1
0
        public static async System.Threading.Tasks.Task <byte[]> ReadBytesFromFileAsync(string fileName)
        {
            try
            {
                Windows.Storage.StorageFolder tempFolder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(Options.options.tempFolderPath);

                Windows.Storage.StorageFile file = await tempFolder.GetFileAsyncServiceAsync(text, apiArgs);

                // TODO: obsolete to use DataReader? use await Windows.Storage.FileIO.Read...(file);
                using (Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenReadAsync())
                {
                    using (Windows.Storage.Streams.DataReader reader = new Windows.Storage.Streams.DataReader(stream.GetInputStreamAt(0)))
                    {
                        await reader.LoadAsync((uint)stream.Size);

                        byte[] bytes = new byte[stream.Size];
                        reader.ReadBytes(bytes);
                        return(bytes);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.Message);
                return(null);
            }
        }
Exemplo n.º 2
0
        public static async System.Threading.Tasks.Task <string> ReadTextFromFileAsync(string fileName)
        {
            try
            {
                Windows.Storage.StorageFolder tempFolder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(Options.options.tempFolderPath);

                Windows.Storage.StorageFile file = await tempFolder.GetFileAsyncServiceAsync(text, apiArgs);

                return(await Windows.Storage.FileIO.ReadTextAsync(file));
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.Message);
                return(null);
            }
        }