//资源类型需设定为内嵌。提前得到资源文件大小。
//命名空间 abc 资源文件名 readme.jpg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | string temp_file_name = Path.GetTempPath()+Guid.NewGuid().ToString().".jpg" try { System.Reflection.Assembly app = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream fsOpen = app.GetManifestResourceStream("abc.Resources.readme.jpg"); FileStream fsSave = new FileStream(temp_file_name, FileMode.OpenOrCreate); BinaryReader sr = new BinaryReader(fsOpen); BinaryWriter sw = new BinaryWriter(fsSave); sw.Write(sr.ReadBytes(827179)); //资源文件字节数,必须精确 sw.Flush(); sw.Close(); sr.Close(); fsSave.Close(); fsOpen.Close(); System.Diagnostics.Process.Start(temp_file_name); //用系统默认打开方式打开所读出的资源文件 } catch (IOException) { MessageBox.Show("无法创建临时文件!"); Application.Exit(); } |