How to retrieve a binary file from .NET assembly?
Posted
by Rahul Soni
on Stack Overflow
See other posts from Stack Overflow
or by Rahul Soni
Published on 2010-04-03T04:27:39Z
Indexed on
2010/04/03
4:33 UTC
Read the original article
Hit count: 388
I have an excel file that I want to embed in my C# assembly. I have changed the build action of the XLSX file to "Embedded Resource".
During runtime, I have to retrieve this XLSX file from the assembly.
Assembly assembly = Assembly.GetExecutingAssembly();
StreamReader sr = new StreamReader(assembly.GetManifestResourceStream("AssemblyName.Output.xlsx"), true);
StreamWriter sw = new StreamWriter(strPath);
sw.Write(sr.ReadToEnd());
sr.Dispose();
sw.Dispose();
System.Diagnostics.Process.Start(strPath);
As expected, this fails for the XLSX file since it is a binary data. This could works well with a text file.
I tried binary read/write, but I am not able to get the code running. Thoughts?
© Stack Overflow or respective owner