IT Community - Software Programming, Web Development and Technical Support

How to Create a Cab file in C#?

This is a discussion on How to Create a Cab file in C#? within the C# Programming forums, part of the Software Development category; Hi, I want to create a cab file in C# and Extract it and Install it in a particular path? ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-24-2007, 08:13 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default How to Create a Cab file in C#?

Hi,

I want to create a cab file in C# and Extract it and Install it in a particular path? Can anyone tell me how the cab file is created?
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-24-2007, 08:23 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: How to Create a Cab file in C#?

Hi,

A cabinet (.cab) file is a library of compressed files stored as a single file. Cabinet files are used to organize installation files that are copied to the user's system. A large compressed file can be spread over several .cab files.

Each file compressed in a .cab file is stored completely within a single folder.

Create a C# project and the copy and paste the following code then extract the zip file attched with this post and add the dll as reference.

String s_EncryptionKey = "";
String s_CompressFile = "";
String s_DecryptDir = "";
CabLib.Compress i_Compress = new CabLib.Compress();
CabLib.Extract i_Extract = new CabLib.Extract();

[DllImport("kernel32.dll", EntryPoint = "GetWindowsDirectoryA", CharSet = CharSet.Ansi)]
private static extern int GetWindowsDirectory(StringBuilder s_Text, int MaxCount);

[DllImport("kernel32.dll", EntryPoint = "GetCurrentDirectoryA", CharSet = CharSet.Ansi)]
private static extern int GetCurrentDirectory(int MaxCount, StringBuilder s_Text);

public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int s32_SplitSize = 0x7FFFFFFF;
StringBuilder s_WinDir = new StringBuilder(500);
GetWindowsDirectory(s_WinDir, 500);

String s_Explorer = s_WinDir + "\\Explorer.exe";
String s_Notepad = s_WinDir + "\\Notepad.exe";

StringBuilder s_WorkDir = new StringBuilder(500);
GetCurrentDirectory(500, s_WorkDir);

String s_CompressDir = s_WorkDir + "\\_Compressed";
s_DecryptDir = s_WorkDir + "\\_Decrypted";
String s_ResourceDir = s_WorkDir + "\\_ExtractResource";

s_CompressFile = s_CompressDir + "\\Packed_%d.cab";

i_Compress.SetEncryptionKey(s_EncryptionKey);
i_Extract.SetDecryptionKey(s_EncryptionKey);
ArrayList i_Files = new ArrayList();
i_Files.Add(new string[] { s_Explorer, @"FileManager\Explorer.exe" });
i_Files.Add(new string[] { s_Notepad, @"TextManager\Notepad.exe" });

i_Compress.CompressFileList(i_Files, s_CompressFile, s32_SplitSize);
MessageBox.Show("Cab File Created");

}


This is the sample for creating a cab file.

Thanks..

S.Balasubramanian..
Attached Files
File Type: zip CabLib.zip (38.4 KB, 89 views)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-24-2007, 08:26 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to Create a Cab file in C#?

Hi,

I checked your code. It is working fine. It only create a cab file. I want to extract a cab file in a particular path and install it.
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-24-2007, 08:28 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: How to Create a Cab file in C#?

Hi,

Use this code to extract a cab file. Copy the code and add the same dll as reference.

s_CompressFile = s_CompressFile.Replace("%d", "1");
i_Extract.ExtractFile(s_CompressFile, s_DecryptDir);


Thanks..

S.Balasubramanian..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-25-2007, 01:04 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to Create a Cab file in C#?

Hi,

I executed your code. It works on creating a cab file and extract it. Please tell me how many types of cab files available? and give me brief explanation..
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-25-2007, 01:13 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: How to Create a Cab file in C#?

Hi,

There are two completely different types of CAB files:

1) The ones which this project supports are the "Microsoft CAB" files (also called "MS-CAB"). The Microsoft pack format is also known as MSZIP.

2)InstallShield created the "InstallShield CAB" files. But these are absolutely incompatible with the MS-CAB files although they use the same file extension

If you open a MS-CAB file with a hex editor, you will notice that the first four bytes are "MSCF" (MicroSoft Cab File), while the first three bytes of an InstallShield-CAB file are "ISc". (InstallShield Cab). You cannot open or create InstallShield CAB files with this project. There exist only very few tools which are capable of managing InstallShield CAB files;


Thanks..

S.Balasubramanian..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code-behind to create node dynamically using XML File or any Stored Procedure poornima ASP and ASP.NET Programming 3 02-14-2008 09:46 PM
How to create a Setup file in VS 2005 to start a installer from a installer file? $enthil C# Programming 2 11-16-2007 03:10 AM
How to read inbox messages in windows mobile and create it as a text file using C#? mobilegeek Windows Mobile 4 08-17-2007 07:42 AM
How to create a ZIP File in Java? bluesky Java Programming 1 07-25-2007 06:03 AM
Is it possible to create an .ini file for CEAppMgr that will disable.. theone Mobile Software Development 1 07-19-2007 01:00 AM


All times are GMT -7. The time now is 11:36 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0