日期:2014-05-18 浏览次数:21297 次
添加一个Resource1.resx文件,然后使用“添加资源”--》“添加现在文件”
我这里把系统自带的Notepad.exe加了进来
private bool WriteFile(byte[] pReadByte, string FileName)
{
FileStream fs = null;
try
{
fs = new FileStream(FileName, FileMode.OpenOrCreate);
fs.Write(pReadByte, 0, pReadByte.Length);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
finally
{
if (fs != null)
fs.Close();
}
return true;
}
private void button1_Click(object sender, EventArgs e)
{
System.Reflection.Assembly myAssembly;
myAssembly = this.GetType().Assembly;
//WindowsApplication1.Resource1 得修改成你的工程名称.资源文件名称
System.Resources.ResourceManager myManager = new System.Resources.ResourceManager("WindowsApplication1.Resource1", myAssembly);
try
{
byte[] byteNotepad = (byte[])myManager.GetObject("notepad");
WriteFile(byteNotepad, @"d:\\Notepad.exe");
System.Diagnostics.Process.Start(@"d:\\Notepad.exe");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
------解决方案--------------------
增加资源后,可以在Resource1.Designer.cs生成相对应的方法,也可以直接使用这些方法
谁可以试试啊