473,657 Members | 2,593 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.GetAttrib utes".
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 6156
Wayne,

From the documentation for the SetAttributesMe thod 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.Compr ession namespace.

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

"Wayne Gore" <Wa*******@disc ussions.microso ft.comwrote in message
news:C7******** *************** ***********@mic rosoft.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.GetAttrib utes".
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.Compr ession 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 SetAttributesMe thod 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.Compr ession namespace.

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

"Wayne Gore" <Wa*******@disc ussions.microso ft.comwrote in message
news:C7******** *************** ***********@mic rosoft.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.GetAttrib utes".
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...@disc ussions.microso ft.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.Compr ession 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 SetAttributesMe thod 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.Compr ession namespace.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om
"Wayne Gore" <WayneG...@disc ussions.microso ft.comwrote in message
news:C7******** *************** ***********@mic rosoft.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.GetAttrib utes".
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...@gmai l.com" <harifa...@gmai l.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.co m>
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.GetAttrib utes".
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
3521
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
1337
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 that the user can play in the XML. I would like to compress the file
1
2158
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, but haven't been able to make it work on this file (perhaps this format is not supported?) WinZip seems to cope perfectly happily with the file, but I need to be
5
12981
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 InputStream; Stream OutPutStream; DataSet1.WriteXml(InputStream);
5
11667
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 whole BMP image and then compress it.. The target location can be of any type.. BMP, TIFF, JPG or any.. Some data loss will be negligible because all the images are having very high resolution with 32-bit colors (taken from digi-cam).
8
6458
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 compressed, and how to do it. Thanks. Jose Luis.
6
2993
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 out.. and also need to un compress at the receiving end.. futher explaing...
1
11510
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 imagePath, Bitmap image, int quality) { if (JpegQuality.Codec == null) image.Save(imagePath,
0
1321
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 for your help. public void CompressFile(string inputFileName, string outputFileName) { byte buffer = new byte; if (File.Exists(inputFileName)) { using (FileStream inputFile = File.Open(inputFileName, FileMode.Open), outputFile =...
0
8821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8502
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.