Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working to compress files via seven zip sharp in c#.
I need to compress files with different extenuations (like .txt, *.abc, *.tff ,etc).
The flow work without exceptions, but the result is wrong.
In the 7z folder just the *.txt files exists.
Does anyone have a solation?

What I have tried:

var cmp = new SevenZipCompressor
			{
				ScanOnlyWritable = false,
				CompressionMode = Directory.Exists(@"C:\Users\User\Desktop\Zip.7z") ? SevenZip.CompressionMode.Append : SevenZip.CompressionMode.Create,
			};
									cmp.CompressFiles(@"C:\Users\User\Desktop\Zip.7z", "c:\\aaa\\file.abc");//this file don't exist in the output folder
Posted
Updated 24-Sep-17 5:39am
v3
Comments
Richard MacCutchan 24-Sep-17 9:28am    
What is the value of outputStringBuilder and CompressionMode and what is the expected output? Did you check the documentation to see that your usage is correct?
Member 13405921 24-Sep-17 9:38am    
Compression mode is the way how to create the 7zip folder.
in our case to crate if it is not exist and update if the folder exist
outputStringBuilder is the output folder (I change it in the code bellow).
I expect to get a 7z folder with the file.abc.
actual the file is not exists.
BTW I try some extenuations of files and the only file that exist in the output folder is *.txt file is it related?
Richard MacCutchan 24-Sep-17 9:58am    
I know that, and that is not what I asked you. I asked you what are the values of those fields when you run the code, and are they consistent with the settings as shown in the documentation? You need to gather proper diagnostic information and show it in your question; we cannot guess what is going on.
[no name] 24-Sep-17 9:39am    
As Richard MacCutchan implies it Looks like you did not read the docs.

/// Packs files into the archive.
// <param name="fileFullNames">Array of file names to pack.
// <param name="archiveName">The archive file name.
public void CompressFiles(string archiveName, params string[] fileFullNames)

I would say fileFullName does not accept something like "c:\xyz\*.xyz"
Member 13405921 24-Sep-17 10:00am    
So which method could be used for this case?

Look here: Code 4 Freaks: Compress files using 7-Zip from C# code[^] it gives example code that is very similar to yours, but that doesn't pass a fixed string as the first parameter.
 
Share this answer
 
You're missing something. Why are you using Directory.Exists on a file? I'm assuming "Zip.7z" is a file in your case.

That's not correct. Explorer treats .ZIP files as folders only for convenience to the user. They are still actual files, not folders, in applications.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900