Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves a stream for reading from a file in the specified parent folder.
        /// </summary>
        /// <param name="rootDirectory">The Windows Runtime IStorageFolder object that contains the file to read from.</param>
        /// <param name="relativePath">The path, relative to the root folder, to the file to read from.</param>
        /// <returns></returns>
        public static Task <Stream> OpenStreamForReadAsync(this IStorageFolder rootDirectory, string relativePath)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return(WindowsRuntimeStorageExtensions.OpenStreamForReadAsync((global::Windows.Storage.StorageFolder)((StorageFolder)rootDirectory), relativePath));
#elif __ANDROID__ || __UNIFIED__ || WIN32
            string newPath = Path.Combine(rootDirectory.Path, relativePath);
            return(Task.FromResult <Stream>(global::System.IO.File.OpenRead(newPath)));
#else
            throw new PlatformNotSupportedException();
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves a stream for reading from a specified file.
        /// </summary>
        /// <param name="windowsRuntimeFile"></param>
        /// <returns></returns>
        public static Task <Stream> OpenStreamForReadAsync(this IStorageFile windowsRuntimeFile)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return(WindowsRuntimeStorageExtensions.OpenStreamForReadAsync((global::Windows.Storage.StorageFile)((StorageFile)windowsRuntimeFile)));
#elif __ANDROID__ || __UNIFIED__ || WIN32
            if (windowsRuntimeFile == null)
            {
                throw new ArgumentNullException("windowsRuntimeFile");
            }

#if __ANDROID__
            if (windowsRuntimeFile.Path.StartsWith("content:"))
            {
                return(Task.FromResult <Stream>(Android.App.Application.Context.ContentResolver.OpenOutputStream(Android.Net.Uri.Parse(windowsRuntimeFile.Path))));
            }
#endif

            return(Task.FromResult <Stream>(global::System.IO.File.OpenRead(windowsRuntimeFile.Path)));
#else
            throw new PlatformNotSupportedException();
#endif
        }