//this code requires System.Reflection namespace//get names of resources in the assembly string[] myassembly = Assembly.GetExecutingAssembly().GetManifestResourceNames();//create stream from the resource. Stream theResource = Assembly.GetExecutingAssembly().GetManifestResourceStream(myassembly[0]); //Create binary reader from the streamBinaryReader br = new BinaryReader(theResource); //then filestream FileStream fs = new FileStream(Environment.GetEnvironmentVariable("TEMP") + +"\\test.xls" , FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); //and then binary writer byte[] bt = new byte[theResource.Length]; //read the resource theResource.Read(bt,0, bt.Length); //and then write to the file bw.Write(bt); //don't forget to close all streams br.Close(); bw.Close();
string[] myassembly
= Assembly.GetExecutingAssembly().GetManifestResourceNames();//create stream from the resource.
Stream theResource
= Assembly.GetExecutingAssembly().GetManifestResourceStream(myassembly[0]);
//Create binary reader from the streamBinaryReader br = new BinaryReader(theResource);
//then filestream
FileStream fs = new FileStream(Environment.GetEnvironmentVariable("TEMP") +
+"\\test.xls" , FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs); //and then binary writer
byte[] bt = new byte[theResource.Length]; //read the resource
theResource.Read(bt,0, bt.Length); //and then write to the file
bw.Write(bt); //don't forget to close all streams
br.Close();
bw.Close();
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/