//资源类型需设定为内嵌。提前得到资源文件大小。
//命名空间 abc 资源文件名 readme.jpg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | string temp_file_name = Path.GetTempPath()+Guid.NewGuid().ToString()+".jpg" try { //abc.Properties.Resources.readme 此处利用Visual Studio自动代码功能选择需要的资源文件 if (ByteArrayToFile(temp_file_name, abc.Properties.Resources.readme)) System.Diagnostics.Process.Start(temp_file_name); //用系统默认打开方式打开所读出的资源文件 else throw (new ArgumentException()); } catch (Exception ex) { MessageBox.Show("无法调用帮助文件!" + ex.Message); } // 将byte[]写成文件 public bool ByteArrayToFile(string fileName, byte[] byteArray) { try { using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { fs.Write(byteArray, 0, byteArray.Length); return true; } } catch (Exception ex) { return false; } } |