如何將程序的Access数据库嵌入到资源中发布
Code
1 private string AccessPath = Application.StartupPath.ToString() + "\\" + "SAP_Words.dll";
2 private string ResourcesPath = Application.StartupPath.ToString() + "\\" + "Resources.dll";
3
4 調用 WriteEmbeddedFile("SAP_Words.dll", AccessPath);
5 private Stream GetStream(string name)
6 {
7 return GetResourceAssembly().GetManifestResourceStream("資源類的命名空間."+name);
8 }
9
10 private Assembly GetResourceAssembly()
11 {
12 return Assembly.LoadFrom(ResourcesPath);
13 }
14
15 private void WriteEmbeddedFile(string name, string fileName)
16 {
17 using (Stream stream = GetStream(name))
18 {
19 FileInfo file = new FileInfo(fileName);
20 using (FileStream fileStream = file.Create())
21 {
22 byte[] buf = new byte[1024];
23 int size;
24 while ((size = stream.Read(buf, 0, 1024)) > 0)
25 {
26 fileStream.Write(buf, 0, size);
27 }
28 }
29 }
30 }
31
1 private string AccessPath = Application.StartupPath.ToString() + "\\" + "SAP_Words.dll";
2 private string ResourcesPath = Application.StartupPath.ToString() + "\\" + "Resources.dll";
3
4 調用 WriteEmbeddedFile("SAP_Words.dll", AccessPath);
5 private Stream GetStream(string name)
6 {
7 return GetResourceAssembly().GetManifestResourceStream("資源類的命名空間."+name);
8 }
9
10 private Assembly GetResourceAssembly()
11 {
12 return Assembly.LoadFrom(ResourcesPath);
13 }
14
15 private void WriteEmbeddedFile(string name, string fileName)
16 {
17 using (Stream stream = GetStream(name))
18 {
19 FileInfo file = new FileInfo(fileName);
20 using (FileStream fileStream = file.Create())
21 {
22 byte[] buf = new byte[1024];
23 int size;
24 while ((size = stream.Read(buf, 0, 1024)) > 0)
25 {
26 fileStream.Write(buf, 0, size);
27 }
28 }
29 }
30 }
31