嵌入资源第三讲:多格式文件内嵌入WPF资源文件
2014-06-02 22:07
253 查看
作为一个扩展,你需要了解DotNetZip用法,请参见:
C# .NET 使用第三方类库DotNetZip解压/压缩Zip文件
你也需要了解单文件内嵌入资源文件基本方法,参见:
WPF调用嵌入的非.net的EXE资源文件
作者:一剑
如果你有一大堆文件或者想通过打包的方式嵌入任意格式的文件到资源文件中,那么你可以打包成一个ZIP文件,再嵌入到资源文件中是一个不错的选择:
在这篇示例中,在程序结束时加入了ZIP中文件的遍历及清理,使得使用过后不留痕迹,把活干得漂亮点^_^。
C# .NET 使用第三方类库DotNetZip解压/压缩Zip文件
你也需要了解单文件内嵌入资源文件基本方法,参见:
WPF调用嵌入的非.net的EXE资源文件
作者:一剑
如果你有一大堆文件或者想通过打包的方式嵌入任意格式的文件到资源文件中,那么你可以打包成一个ZIP文件,再嵌入到资源文件中是一个不错的选择:
using Ionic.Zip;//+ using System.Reflection; using System.IO; using System.Threading; namespace WpfApplication2 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { List<string> fileList = new List<string>(); public MainWindow() { InitializeComponent(); Thread t = new Thread(new ThreadStart(unzip)); t.IsBackground = true; t.Start(); } private void unzip() { String projectName = Assembly.GetExecutingAssembly().GetName().Name.ToString(); using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(projectName + ".f.zip")) { Byte[] b = new Byte[stream.Length]; stream.Read(b, 0, b.Length); MemoryStream m = new MemoryStream(b); using (ZipFile zip = ZipFile.Read(m)) { zip.ExtractAll(System.IO.Path.GetTempPath(), ExtractExistingFileAction.OverwriteSilently); foreach (ZipEntry entry in zip) { fileList.Add(System.IO.Path.GetTempPath() + entry.FileName); } } } } private void Button_Click(object sender, RoutedEventArgs e) { foreach (string f in fileList) { if (File.Exists(f)) MessageBox.Show(f + " is found."); } } private void Window_Closed(object sender, EventArgs e) {foreach (string f in fileList) { if (File.Exists(f)) File.Delete(f); } } } }
在这篇示例中,在程序结束时加入了ZIP中文件的遍历及清理,使得使用过后不留痕迹,把活干得漂亮点^_^。
相关文章推荐
- 演示:多格式文件内嵌入WPF资源文件
- 嵌入资源第二讲:WPF调用嵌入的非.net的EXE资源文件
- .Net中对资源文件的获取(获取嵌入到程序中的图片资源)
- [转贴] 在.NET中嵌入和使用资源文件
- 播放嵌入资源的声音文件
- 为JavaScript 文件嵌入本地化资源
- 在.Net中嵌入资源文件到程序集中-.NET教程,VB.Net语言
- 播放嵌入资源的声音文件
- 在.NET中嵌入和使用资源文件
- 学习使用资源文件[10] - 嵌入和提取任何类型的文件
- 将XSD架构文件嵌入资源使用
- 在.Net中嵌入资源文件到程序集中
- 资源文件的嵌入及自定义控件Tag
- JIURL PE 格式学习总结(四)-- PE文件中的资源
- [CF.Skills]播放嵌入资源的声音文件
- 读取嵌入到 Dll 文件中的资源文件
- 在.Net中嵌入资源文件到程序集中
- 读取嵌入到 Dll 文件中的资源文件
- 将XSD架构文件嵌入资源使用
- Illustrator CS4之fxg文件格式(MXML) Vs WPF之XAML