473,503 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compress a file(s)?

Hi

I want to achive 2 things.
First I would like to compress an existing file on my harddrive.
I can easily find out if a file is compressed or not by using
"File.GetAttributes".
But no matter what I do I simply can't set the compressed attribute using
"SetAttributes".
I have no problem setting the attributes "Read-Only", "Archive" or "Hidden"
using "SetAttributes"!

How can I do this?

Secondly I would like to be able to create a "compressed folder" (as it is
called in Windows Explorer) and copy files and folders into it.

How can I do that?

Regards
Wayne
Apr 9 '07 #1
6 6144
Wayne,

From the documentation for the SetAttributesMethod on the File class:

It is not possible to change the compression status of a File object using
the SetAttributes method.

By a compressed folder, do you mean a zip file? If that is the case,
then take a look at the System.IO.Compression namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wayne Gore" <Wa*******@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...
Hi

I want to achive 2 things.
First I would like to compress an existing file on my harddrive.
I can easily find out if a file is compressed or not by using
"File.GetAttributes".
But no matter what I do I simply can't set the compressed attribute using
"SetAttributes".
I have no problem setting the attributes "Read-Only", "Archive" or
"Hidden"
using "SetAttributes"!

How can I do this?

Secondly I would like to be able to create a "compressed folder" (as it is
called in Windows Explorer) and copy files and folders into it.

How can I do that?

Regards
Wayne

Apr 9 '07 #2
Hi Nicholas

Thank you for your reply.

Yes, I was refering to a .zip archive.
On your recommendation I will check out System.IO.Compression namespace.

Regarding the attributes...
What I want to do is to compress a file in the same way as if I was using
Windows Explorer, right-clicked a file, clicked Advanced and then checked the
"Compress contents to save diskspace".

Isn't there really any way to achive this using C#?

Thanks for you time and input.
Wayne

"Nicholas Paldino [.NET/C# MVP]" wrote:
Wayne,

From the documentation for the SetAttributesMethod on the File class:

It is not possible to change the compression status of a File object using
the SetAttributes method.

By a compressed folder, do you mean a zip file? If that is the case,
then take a look at the System.IO.Compression namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wayne Gore" <Wa*******@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...
Hi

I want to achive 2 things.
First I would like to compress an existing file on my harddrive.
I can easily find out if a file is compressed or not by using
"File.GetAttributes".
But no matter what I do I simply can't set the compressed attribute using
"SetAttributes".
I have no problem setting the attributes "Read-Only", "Archive" or
"Hidden"
using "SetAttributes"!

How can I do this?

Secondly I would like to be able to create a "compressed folder" (as it is
called in Windows Explorer) and copy files and folders into it.

How can I do that?

Regards
Wayne


Apr 9 '07 #3
On Apr 10, 12:52 am, Wayne Gore <WayneG...@discussions.microsoft.com>
wrote:
Hi Nicholas

Thank you for your reply.

Yes, I was refering to a .zip archive.
On your recommendation I will check out System.IO.Compression namespace.

Regarding the attributes...
What I want to do is to compress a file in the same way as if I was using
Windows Explorer, right-clicked a file, clicked Advanced and then checked the
"Compress contents to save diskspace".

Isn't there really any way to achive this using C#?

Thanks for you time and input.
Wayne

"Nicholas Paldino [.NET/C# MVP]" wrote:
Wayne,
From the documentation for the SetAttributesMethod on the File class:
It is not possible to change the compression status of a File object using
the SetAttributes method.
By a compressed folder, do you mean a zip file? If that is the case,
then take a look at the System.IO.Compression namespace.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Wayne Gore" <WayneG...@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...
Hi
I want to achive 2 things.
First I would like to compress an existing file on my harddrive.
I can easily find out if a file is compressed or not by using
"File.GetAttributes".
But no matter what I do I simply can't set the compressed attribute using
"SetAttributes".
I have no problem setting the attributes "Read-Only", "Archive" or
"Hidden"
using "SetAttributes"!
How can I do this?
Secondly I would like to be able to create a "compressed folder" (as it is
called in Windows Explorer) and copy files and folders into it.
How can I do that?
Regards
Wayne- Hide quoted text -

- Show quoted text -
Hi,

try this http://www.icsharpcode.net/OpenSource/SharpZipLib/
Apr 10 '07 #4
On Apr 10, 6:54 am, "harifa...@gmail.com" <harifa...@gmail.comwrote:

<snip>
try thishttp://www.icsharpcode.net/OpenSource/SharpZipLib/
That will create a zip file - it won't change the file to be
compressed at the Windows file-system level.

Jon

Apr 10 '07 #5
On Tue, 10 Apr 2007 00:05:52 -0700, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote:
>try thishttp://www.icsharpcode.net/OpenSource/SharpZipLib/

That will create a zip file - it won't change the file to be
compressed at the Windows file-system level.
Well, creating a zip file was one of the things he was trying to do. :)
Apr 10 '07 #6
Thanks for you input guys.

To be able to create a zip archive is very useful and I'm greatful for the
info.

I would really like to find out a way to compress it as if I was doing it
using Windows Explorer.
I just can't believe there is no way of doing it.
I know how I can do it using WMI but it shouldn't be necessary...

Cheers
Wayne
"Wayne Gore" wrote:
Hi

I want to achive 2 things.
First I would like to compress an existing file on my harddrive.
I can easily find out if a file is compressed or not by using
"File.GetAttributes".
But no matter what I do I simply can't set the compressed attribute using
"SetAttributes".
I have no problem setting the attributes "Read-Only", "Archive" or "Hidden"
using "SetAttributes"!

How can I do this?

Secondly I would like to be able to create a "compressed folder" (as it is
called in Windows Explorer) and copy files and folders into it.

How can I do that?

Regards
Wayne
Apr 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3510
by: Tony | last post by:
Hello, Any assistance would be appreciated: As the subject suggests I am trying to gunzip files using the Compress::Zlib module. The following is basically the code that I am working with: ...
0
1326
by: Santastp | last post by:
Hi! This is a situation who can happen often and I would like to know if something exist. I try to create an application who use XML as a native database. The problem is that I don't want...
1
2141
by: Marc Jennings | last post by:
Hi there, I have a problem in that I need to de-compress a file that was compressed using the UNIX compress command. The resulting filename is helloworld.xml.Z I have looked at SharpZipLib,...
5
12971
by: ad | last post by:
I used use SharpZipLib to compress files in disk. But now I want to compress stream into another stream in memory(the stream not associated with disk file) My pseudo is: Stream...
5
11638
by: Jigar Mehta | last post by:
Hye Friends!!, Happy New Year!! I am Jigar Mehta from India. Currently I am working on a project in which I need to compress some images on the harddisk... I want to make an engine that reads...
8
6439
by: Jose L. Velazquez | last post by:
Hi all, I have made a webservice that returns an XML, but sometimes the connection is so slow and there is a lot of data to be returned. I would like to know if it is possible to send this data...
6
2982
by: Champika Nirosh | last post by:
Hi, I have two machine where I needed to have a extended TCP/IP protocol to make the link between the two machines Mean,I need to write a application that compress every data the machine send...
1
11475
by: ironpythonster | last post by:
Hi everyone, this should be a quick question. I am writing a function to compress the Jpeg file,with the API Image.Save(...) . the code as follow that: public static void Save(string...
0
1310
by: vampire1986 | last post by:
Hi all. I have project compress file using C#. I'm using name space IO.Compression and i saw this code on Internet but it is compress to file bigger than source file. Can you help me, please.Thanks...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.