Plugin.EmbeddedResource/ResourceWriter.cs
/// <summary>
/// Writes an embedded resource to the file system 
/// </summary>
/// <param name="assembly"><see cref="Assembly"/> containing embedded resources.</param>
/// <param name="fileName">Path and name to write the resource to the filesystem.</param>
/// <param name="resource">Full name of embedded resource in <see cref="Assembly"/>.</param>
/// <returns>
/// A <see cref="Task"/> which will complete after the file is written
/// </returns>
Writes an embedded resource to the file system
Writes an embedded resource to the file system
public static async Task WriteResource (Assembly assembly, string fileName, string resource, CreationCollisionOption option =  CreationCollisionOption.ReplaceExisting) {
			var folderName = fileName.Substring (
				0, 
				fileName.LastIndexOf (PortablePath.DirectorySeparatorChar));
			var folder = GetStorageFromPath (folderName);
			if (folder == null)
				folder = FileSystem.Current.LocalStorage;
			else
			if (folderName != folder.Path)
				folder = await folder.CreateFolderAsync (
					folderName.Substring (folder.Path.Length + 1),
					CreationCollisionOption.OpenIfExists);
			var file = await folder.CreateFileAsync(
				fileName.Substring(fileName.LastIndexOf (PortablePath.DirectorySeparatorChar) + 1),
				option);
			using (var input = ResourceLoader.GetEmbeddedResourceStream(assembly, resource))
			using (var output = await file.OpenAsync(FileAccess.ReadAndWrite)) {
				byte[] buffer = new byte[1024];
				int length;
				while ((length = input.Read (buffer, 0, 1024)) > 0)
					output.Write (buffer, 0, length);
				output.Flush ();
			}
		}
public static async Task WriteResource ( Assembly assembly , string fileName , string resource , CreationCollisionOption option = CreationCollisionOption . ReplaceExisting ) { var folderName = fileName . Substring ( 0 , fileName . LastIndexOf ( PortablePath . DirectorySeparatorChar ) ) ; var folder = GetStorageFromPath ( folderName ) ; if ( folder == null ) folder = FileSystem . Current . LocalStorage ; else if ( folderName != folder . Path ) folder = await folder . CreateFolderAsync ( folderName . Substring ( folder . Path . Length + 1 ) , CreationCollisionOption . OpenIfExists ) ; var file = await folder . CreateFileAsync ( fileName . Substring ( fileName . LastIndexOf ( PortablePath . DirectorySeparatorChar ) + 1 ) , option ) ; using ( var input = ResourceLoader . GetEmbeddedResourceStream ( assembly , resource ) ) using ( var output = await file . OpenAsync ( FileAccess . ReadAndWrite ) ) { byte [ ] buffer = new byte [ 1024 ] ; int length ; while ( ( length = input . Read ( buffer , 0 , 1024 ) ) > 0 ) output . Write ( buffer , 0 , length ) ; output . Flush ( ) ; } }
Writes an embedded resource to the file system
Writes an embedded resource to the file system
// need to create subfolder
A  which will complete after the file is written
A which will complete after the file is written
assembly
Assembly
containing embedded resources.
containing embedded resources .
fileName
string
Path and name to write the resource to the filesystem.
Path and name to write the resource to the filesystem .
resource
string
Full name of embedded resource in .
Full name of embedded resource in .
option
CreationCollisionOption