create account

Turkish Tutorial of SharpZipLib C# by pars11

View this thread on: hive.blogpeakd.comecency.com
· @pars11 · (edited)
$19.58
Turkish Tutorial of SharpZipLib C#
<hr>

> **SharpZipLib**
SharpZipLib (#ziplib, formerly NZipLib) is a compression library for Zip, GZip, BZip2, and Tar written entirely in C# for .NET. It is implemented as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language)
[Source](https://www.nuget.org/packages/SharpZipLib/1.0.0-alpha2)

<hr>

<center>![icon.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515355727/gqite1yxhmgeeycisuzw.png)
<div>Icons made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div></center>

<hr>

Merhaba arkadaşlar bugün bir .NET kütüphanesi olan SharpZipLib' i tanıtmaya ve örnek bir C# uygulaması yapmaya çalışacağım. SharpZipLib kullanarak dosyalarımızı Zip olarak sıkıştırabiliriz. Zip sıkıştırılmış bir dosya biçimidir. Dosyaların sıkıştırılması boyutlarının küçülmesini sağlar. Daha hızlı indirmenizi ve daha fazla depolama alanı sağlamak için veya dosyalarımı dışarı aktarmak için dosyalarımı Zip arşivine dönüştürürüz. Bugun C# ile SharpZipLib kütüphanesini kullanarak. Dosyalarımızı sıkıştıracağız.

<hr>

[SharpZipLib Website](http://icsharpcode.github.io/SharpZipLib/)
[NuGet](https://www.nuget.org/packages/SharpZipLib/1.0.0-alpha2)
[GitHub](https://github.com/icsharpcode/SharpZipLib)
[Proje Dosyamız](https://drive.google.com/file/d/1crur2DFMMVExATVh7s1_3y0SJREYOl1e/view?usp=sharing) 

<hr>

## SharpZipLib C# Projemiz
Öncelikle arkadaşlar Visual Studio üzerinden bir Form Application projesi oluşturuyoruz. Ben Form Application oluşturmak istedim siz başka bir proje çeşidide seçebilirsiniz ihtiyacınıza göre SharpZipLib bütün .NET dillerinde ve projelerinde kullanabilirsiniz.

![1.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515356541/gqg6vbrwfjpwh5ffh8v0.png)

Projemizi oluşturduktan sonra projemize SharpZipLib kütüphanesini eklememiz için NuGet linkindeki kodumuzu NuGet Package Manager Console'a yazmamız yeterli.
Kodumuz:

<hr>

```Install-Package SharpZipLib -Version 1.0.0-alpha2```
```Bu işlemi detaylı açıkladığım konuma buradan ulaşabilirsiniz.```
[Turkish Tutorial of NuGet Package Manager C#](https://utopian.io/utopian-io/@pars11/turkish-tutorial-of-nuget-package-manager-c)

<hr>

![2.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357021/b5rvkiiui4h129ratrv5.png)

Kütüphanemiz projemize başarıyla eklendi.

Kütüphanemizi kodumuzda kullanabilmek için formumuzun kod alanına girip. SharpZipLib kütüphanemizin using kodunu ekliyoruz.
Kodlarımız:

<hr>

```using System.IO;```
```using ICSharpCode.SharpZipLib```

<hr>

System.IO dosyalarımız üzerinde işlem yapabilmemizi sağlayacak. Diğer kodumuz ise kütüphanemizin kodu.

![3.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357476/zqvxegdcvtlkqi8hwsjx.png)

Kütüphanemizi eklememizde bittiğine göre formumuzun tasarımına geçebiliriz.
Ben klasörü zipleme ve ziplenmiş dosyayı açma işlemi yapmak istiyorum.

Bu yüzden formuma iki adet label iki adet textbox iki adet button ekleyeceğim.

![4.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357816/otbmjrfxt0bu5vl6u2fp.png)

Formumuzun adını labellarımızın ve butonlarımızın textini tasarım için değiştiriyoruz.

![5.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357914/hoovahpbmcvslvqihhjp.png)

Tasarım kısmımız tamamlandı kodlarımıza geri dönüyoruz.

<hr>

Öncelikle Zipleme yapabilmek için en üste using kısmımıza kütüphanemizin

```using ICSharpCode.SharpZipLib.Zip;``` 

kodunu ekliyoruz.

Ve Zip'den çıkarma işlemi yapabilmek için yine en üste using kısmımıza kütüphanemizin

```using ICSharpCode.SharpZipLib.Core;``` 

kodunu ekliyoruz.

Şimdi bunlarıda hallettiğimize göre iki fonksiyon yazağız biri klasörlerimizi dosyalarımızı ziplemek için diğeride zipli dosyalarımızı klasöre çıkartmak için.

İlk Fonksiyonumuz dosya sıkıştırma şu şekilde olacak:

<hr>

```

 private void compressDirectory(string DirectoryPath, string OutputFilePath, int CompressionLevel = 9)
        {
            //Seçtiğimiz yoldaki dosyaları çekiyoruz.
            string[] filenames = Directory.GetFiles(DirectoryPath);

            // Zip'in çıkartılacağı yer için bir ZipOutputStream nesnesi oluşturuyoruz.
            using (ZipOutputStream OutputStream = new ZipOutputStream(File.Create(OutputFilePath)))
            {

                // Sıkıştırma levelini belirliyoruz 0-9 arası bir değer verebilir.
                // Biz yukarda bu sayıyı 9 girdik en iyi biçimde sıkıştırma yapılacak yani.
                OutputStream.SetLevel(CompressionLevel);

                byte[] buffer = new byte[4096];

                foreach (string file in filenames)
                {

                    //Zip dosyamıza dosyalarımızı ekliyoruz.
                    ZipEntry entry = new ZipEntry(Path.GetFileName(file));

                    //Zip'e yazılan dosyaların yazma tarihini şuan olarak belirliyoruz.
                    entry.DateTime = DateTime.Now;
                    OutputStream.PutNextEntry(entry);


                    using (FileStream fs = File.OpenRead(file))
                    {
                        int sourceBytes;

                        do
                        {
                            sourceBytes = fs.Read(buffer, 0, buffer.Length);
                            OutputStream.Write(buffer, 0, sourceBytes);
                        } while (sourceBytes > 0);
                    }
                }

                // ZipOutputStream işlemimizi bitiriyoruz.
                OutputStream.Finish();
                // ZipOutputStream işlemimizi kapatıyoruz.
                OutputStream.Close();
            }
        }

```

<hr>

Şimdi ikinci fonksiyonumuz zip açmaya geçebiliriz oda şu şekilde:

<hr>

```

    public void ExtractZipContent(string FileZipPath, string OutputFolder)
        {
            ZipFile file = null;
            FileStream fs = File.OpenRead(FileZipPath);
            file = new ZipFile(fs);

            foreach (ZipEntry zipEntry in file)
            {
                if (!zipEntry.IsFile)
                {
                    //Dosyaları geç
                    continue;
                }

                //Dosya adımızı zip adımıza eşitliyoruz.
                string entryFileName = zipEntry.Name;
                
                byte[] buffer = new byte[4096];
                Stream zipStream = file.GetInputStream(zipEntry);

                string fullZipToPath = Path.Combine(OutputFolder, entryFileName);
                string directoryName = Path.GetDirectoryName(fullZipToPath);

                if (directoryName.Length > 0)
                {
                    Directory.CreateDirectory(directoryName);
                }

                using (FileStream streamWriter = File.Create(fullZipToPath))
                {
                    StreamUtils.Copy(zipStream, streamWriter, buffer);
                }
            }
        }

```

<hr>

Fonksiyonlarımız tamamlandı dosya sıkıştırmak ve sıkıştırılmış dosyayı açmak için fonksiyonlarımız hazır. 
Şimdi butonlarımızın kodlarını yazmamız gerekiyor.

Button 1 yani zipleme yapmak için kullanacağımız butonumuzun kodları:

<hr>

```
private void button1_Click(object sender, EventArgs e)
        {
            //FolderBrowserDialog nesnenimizi oluşturuyoruz.
            FolderBrowserDialog folder = new FolderBrowserDialog();
            //Klasör seçme menümüzü açtırıyoruz.
            folder.ShowDialog();
            string folderpath;
            //Dosya çıktısı yolumuzu masaüstüne ayarlıyoruz.
            string OutputFilePath = "C:\\Users\\gffdg\\Desktop";
            //Klasör yolumuzu seçtiğimiz yola ayarlıyoruz.
            folderpath = folder.SelectedPath;
            //Textbox1 in textini klasör yolumuz yapıyoruz.
            textBox1.Text = folderpath;
            //Zipleme fonksiyonumuzu kullanarak.
            //Dosyamızın masaüstünde ziplenmiş halini oluşturuyoruz. 
            compressDirectory(folderpath, OutputFilePath);
        }

```

<hr>


Button 2 yani ziplenmiş dosyamızı açmak için kullanacağımız butonumuzun kodları:

<hr>

```

        private void button2_Click(object sender, EventArgs e)
        {
            //FolderBrowserDialog nesnenimizi oluşturuyoruz.
            FolderBrowserDialog folder = new FolderBrowserDialog();
            //Klasör seçme menümüzü açtırıyoruz.
            folder.ShowDialog();
            string folderpath;
            //Dosya çıktısı yolumuzu masaüstüne ayarlıyoruz.
            string OutputFilePath = "C:\\Users\\gffdg\\Desktop";
            //Klasör yolumuzu seçtiğimiz yola ayarlıyoruz.
            folderpath = folder.SelectedPath;
            //Textbox1 in textini klasör yolumuz yapıyoruz.
            textBox1.Text = folderpath;
            //Zipten çıkarma fonksiyonumuzu kullanarak.
            //Dosyamızın masaüstünde ziplenmiş halini oluşturuyoruz. 
            ExtractZipContent(folderpath, OutputFilePath);
        }

```

<hr>

## Programımızın Ekran Görüntüleri

![6.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363622/prrnaww5eouqtfbmrkim.png)

![7.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363629/dqtmllf2pvhlhninapw9.png)

![8.PNG](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363635/btru2htcma04lqphlvjk.png)

Okuduğunuz için teşekkürler. 

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@pars11/turkish-tutorial-of-sharpziplib-c">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , ,
properties (23)
authorpars11
permlinkturkish-tutorial-of-sharpziplib-c
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":868789,"name":"SharpZipLib","full_name":"icsharpcode/SharpZipLib","html_url":"https://github.com/icsharpcode/SharpZipLib","fork":false,"owner":{"login":"icsharpcode"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","tr","tutorial"],"users":["pars11"],"links":["https://www.nuget.org/packages/SharpZipLib/1.0.0-alpha2","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515355727/gqite1yxhmgeeycisuzw.png","http://icsharpcode.github.io/SharpZipLib/","https://github.com/icsharpcode/SharpZipLib","https://drive.google.com/file/d/1crur2DFMMVExATVh7s1_3y0SJREYOl1e/view?usp=sharing","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515356541/gqg6vbrwfjpwh5ffh8v0.png","https://utopian.io/utopian-io/@pars11/turkish-tutorial-of-nuget-package-manager-c","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357021/b5rvkiiui4h129ratrv5.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357476/zqvxegdcvtlkqi8hwsjx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357816/otbmjrfxt0bu5vl6u2fp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357914/hoovahpbmcvslvqihhjp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363622/prrnaww5eouqtfbmrkim.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363629/dqtmllf2pvhlhninapw9.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363635/btru2htcma04lqphlvjk.png"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515355727/gqite1yxhmgeeycisuzw.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515356541/gqg6vbrwfjpwh5ffh8v0.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357021/b5rvkiiui4h129ratrv5.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357476/zqvxegdcvtlkqi8hwsjx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357816/otbmjrfxt0bu5vl6u2fp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515357914/hoovahpbmcvslvqihhjp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363622/prrnaww5eouqtfbmrkim.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363629/dqtmllf2pvhlhninapw9.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515363635/btru2htcma04lqphlvjk.png"],"moderator":{"account":"manishmike10","pending":false,"reviewed":true,"flagged":false}}
created2018-01-07 22:23:06
last_update2018-01-09 11:28:57
depth0
children5
last_payout2018-01-14 22:23:06
cashout_time1969-12-31 23:59:59
total_payout_value13.758 HBD
curator_payout_value5.818 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9,644
author_reputation13,018,135,268,251
root_title"Turkish Tutorial of SharpZipLib C#"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,856,329
net_rshares2,309,186,198,816
author_curate_reward""
vote details (10)
@manishmike10 ·
Your contribution cannot be approved yet. See the [Utopian Rules](https://utopian.io/rules). Please edit your contribution to reapply for approval.
* I'd request you to add the codes here aswell, `Bu işlemi detaylı açıkladığım konuma buradan ulaşabilirsiniz.`
You may edit your post [here](https://utopian.io/utopian-io/@pars11/turkish-tutorial-of-sharpziplib-c), as shown below: 
![](https://res.cloudinary.com/hpiynhbhq/image/upload/v1509788371/nbgbomithszxs3nxq6gx.png)

You can contact us on [Discord](https://discord.gg/UCvqCsx).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authormanishmike10
permlinkre-pars11-turkish-tutorial-of-sharpziplib-c-20180108t175856273z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-08 17:59:03
last_update2018-01-08 17:59:03
depth1
children1
last_payout2018-01-15 17:59:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length591
author_reputation20,399,732,899,016
root_title"Turkish Tutorial of SharpZipLib C#"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id28,055,262
net_rshares0
@pars11 ·
I edit my contribution. Please reapply my contribution. Thank you very much yours contributions.
properties (22)
authorpars11
permlinkre-manishmike10-re-pars11-turkish-tutorial-of-sharpziplib-c-20180108t215517872z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-08 21:55:21
last_update2018-01-08 21:55:21
depth2
children0
last_payout2018-01-15 21:55:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length96
author_reputation13,018,135,268,251
root_title"Turkish Tutorial of SharpZipLib C#"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id28,094,983
net_rshares0
@manishmike10 ·
$0.23
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/UCvqCsx).
**[[utopian-moderator]](https://utopian.io/moderators)**
👍  
properties (23)
authormanishmike10
permlinkre-pars11-turkish-tutorial-of-sharpziplib-c-20180109t112908846z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-09 11:29:09
last_update2018-01-09 11:29:09
depth1
children1
last_payout2018-01-16 11:29:09
cashout_time1969-12-31 23:59:59
total_payout_value0.214 HBD
curator_payout_value0.017 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation20,399,732,899,016
root_title"Turkish Tutorial of SharpZipLib C#"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id28,229,796
net_rshares21,648,514,500
author_curate_reward""
vote details (1)
@pars11 ·
Thanks :)
properties (22)
authorpars11
permlinkre-manishmike10-re-pars11-turkish-tutorial-of-sharpziplib-c-20180109t182638964z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-09 18:26:48
last_update2018-01-09 18:26:48
depth2
children0
last_payout2018-01-16 18:26:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9
author_reputation13,018,135,268,251
root_title"Turkish Tutorial of SharpZipLib C#"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id28,312,315
net_rshares0
@utopian-io ·
### Hey @pars11 I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-pars11-turkish-tutorial-of-sharpziplib-c-20180110t034251301z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-10 03:42:51
last_update2018-01-10 03:42:51
depth1
children0
last_payout2018-01-17 03:42:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,504
author_reputation152,955,367,999,756
root_title"Turkish Tutorial of SharpZipLib C#"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id28,401,493
net_rshares0