Can I embed other files in a DLL?

限于喜欢 提交于 2019-11-29 06:21:41

Sure, you can embed a resource in your DLL. Then at runtime you just do:

Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("com.stackoverflow.plugin.example.Foo.pdf");

This would give you a stream to the Foo.pdf file embedded in your DLL. Pay attention to the fact that the resource name has to be scoped by the namespace of the type from which you're invoking the method.

Sure, just make them "Embedded Resource" in VS.NET (assuming you're using it). You can then read them via resource APIs or simply with Assembly.GetManifestResourceStream().

Yes, you can do that.

Add a resource file to your project. Open the resource file in Visual Studio and click Insert Resource. You can select different types of resources, including external files.

Visual Studio will generate code for you so that you can retrieve the files as byte arrays at run time from their names through the Resources identifier.

As an alternate option, if you need to unpack and save the files on the users machine (say a chm file you want accessible outside your app) you can also do the same with zip files.

You said you wanted the file to be "Dragged" onto your app. Simply have your DDE events check to see if the file is a zip (maybe even using something like a jar with metadata) and unpack the necessary files, including the actual plugin.

This is the same idea as openxml docs, they are really just zips in disguise.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!