public static Stream OpenFileForWriting(string uri)
        {
            string             fileName = Path.GetFileName(uri);
            Task <StorageFile> task1    = WindowsRuntimeSystemExtensions.AsTask <StorageFile>(FileHelper.GetFolderForPathOrURI(uri).CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting));

            task1.Wait();
            if (task1.Status != TaskStatus.RanToCompletion)
            {
                throw new Exception("Failed to open the file");
            }
            Task <IRandomAccessStream> task2 = WindowsRuntimeSystemExtensions.AsTask <IRandomAccessStream>(task1.Result.OpenAsync(FileAccessMode.ReadWrite));

            task2.Wait();
            if (task2.Status != TaskStatus.RanToCompletion)
            {
                throw new Exception("Failed to open the file");
            }
            else
            {
                return(WindowsRuntimeStreamExtensions.AsStreamForWrite((IOutputStream)task2.Result));
            }
        }
 public static Stream OpenFileForReading(string uri)
 {
     return(FileHelper.OpenFileForReading(FileHelper.GetFileForPathOrURI(uri)));
 }