You must Sign In to post a response.
  • Category: Silverlight

    How to Zip File in Silver light

    Are you looking to ZIP a file in silverlight ? then read this thread to know more about it

    HI Everyone.
    How do we zip file in Silver Light . Lets say i have a button on event i want to take a file from folder and zip else unzip to another folder. Any link relevant to that would be very helpful.

    Rakesh Chaubey
  • #714502

    Add zip.exe file in your bin directory. zipafolder method contain the code to compress a folder to zip file. Pass following parameters sourcefile and destinationfile into the zipafolder method.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using ICSharpCode.SharpZipLib.Zip;
    using System.IO;

    public static void zipafolder(string sourcefile, string destfile)
    long directorySize = GetDirectorySize(sourcefile);

    if (File.Exists(destfile) == false)
    System.IO.FileStream fs = System.IO.File.Create(destfile);

    //zip.exe file should be present in Base Directory
    string zipfile = System.AppDomain.CurrentDomain.BaseDirectory + "zip.exe";

    System.Diagnostics.ProcessStartInfo i = new System.Diagnostics.ProcessStartInfo(zipfile);

    i.CreateNoWindow = true;
    string args = "";

    if (sourcefile.IndexOf(" ") != -1)
    //we got a space in the path so wrap it in double qoutes
    args += "\"" + sourcefile + "\"";
    args += sourcefile;

    string dest = destfile;
    if (dest.IndexOf(" ") != -1)
    //we got a space in the path so wrap it in double qoutes
    args += " " + "\"" + dest + "\"";
    args += " " + dest;

    i.Arguments = args;

    //Mark the process window as hidden so
    //that the progress copy window doesn't show
    i.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start(i);
    int size = Convert.ToInt32(Convert.ToInt32(directorySize));



    I had attached sample sourcecode hope it will be useful.

    Senior Software Engineer,
    Microsoft Certified Technology Specialist.


    Delete Attachment

  • #714506

    Thnaks for u r instant reply .I am not able to Download the attachment that u have . Could you please attach again . Else send to my mail id .It would be very helppfull.

    Rakesh Chaubey

  • #714526
    You can use SaveFileDialog in Silverlight is that its ShowDialog() method for creating Zip File in Silver light

  • #714536
    Could you plz explain a little more .Phagu Mahato . Do u have any google link where i can see examples. Because i have tried in google. Not able to meet my needs .
    Rakesh Chaubey

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.