I would like to add here my code snippet that works well in Visual Studio 2015. (Just improved Jeremy Thompson's answer .)
(Remember to set the Excel Build Action Embedded Resource Property file in the properties window.)
public void launchExcel() { String resourceName = "Sample.xls"; String path = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); Assembly asm = Assembly.GetExecutingAssembly(); string res = string.Format("{0}.Resources." + resourceName, asm.GetName().Name); Stream stream = asm.GetManifestResourceStream(res); try { using (Stream file = File.Create(path + @"\" + resourceName)) { CopyStream(stream, file); } Process.Start(path + @"\" + resourceName); }catch (IOException ex) { MessageBox.Show(ex.Message); } } public void CopyStream(Stream input, Stream output) { byte[] buffer = new byte[8 * 1024]; int len; while ((len = input.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, len); } }
Hope this helps you with your problems.
Sincerely.
source share