Minimum C# code to extract from .CAB archives or InfoPath XSN files, in memory

不羁岁月 提交于 2019-11-29 03:48:05

Are you able to use other libraries created by Microsoft? It doesn't come with the framework but there is a MS library for working with Cab files:

Microsoft.Deployment.Compression.Cab

It can be used as follows

CabInfo cab = new CabInfo(@"C:\data.cab");
cab.Unpack(@"C:\ExtractDir");

We also have the "no third party libs" policy (pain that it is). Yet we need to "unroll" IP forms for various reasons. Our solution was to use CABARC (which is an exe but from Microsoft, and it used to be included in Windows installation although might not be anymore). It can be scripted in any language from a shell, we use vbs or powershell. It works just like any zip/unzip program with command line switches.

Just another option for those finding the good information from above.

Expanding CAB files is identical to expanding ZIP files.

You can find some code here

What about this approach: How to extract a file from a .CAB file? I mean the proposal of JohnWein (an MCC) there. What you do then with the files - whether you copy them in a target directoty, as in the foreach statemant of the referenced example, or just use them in memory - is up to you then. (I guess this is what Alexandru-Dan meant as well - if you're not looking at the question but the answer there instead.)

If this approach does work in your scenario then it's a much more simpler solution - without any 3rd party dll.

Does it?

If the concern is with 3rd party binary libraries, I can't help, but there are open source ZIP libraries that will open a CAB file.

http://www.icsharpcode.net/opensource/sharpziplib/

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