Converting files into .rar file

Last post 05-17-2008 10:30 AM by rajeshthangarasu. 2 replies.

Sort Posts:

  • Converting files into .rar file

    05-17-2008, 12:40 AM
    • Loading...
    • san_7f
    • Joined on 05-09-2008, 10:00 AM
    • Posts 5

    Hi  

    Is there  any possible way to convert file into rar file.

    I have a folder, which contains files, by the way of using .net(regardless any language) program, all of the files need to be converted into .rar file

    Plz let me know the solution as soon as possible

     

    Regards,

    Appu 

     

     

  • Re: Converting files into .rar file

    05-17-2008, 3:42 AM
    Answer
    • Loading...
    • kamii47
    • Joined on 05-26-2005, 4:04 PM
    • Karachi, Pakistan
    • Posts 1,549
    In .net 2.0 (and following edition) we have a very powerful GZipStrream class which we use to zip the file [but extrension will be .gzip]
    Kamran Shahid(MCSD.NET,MCPD.net[web])
    Sr. Software Engineer
    Netprosys Inc.
    www.netprosys.com

    Remember to click "Mark as Answer" on the post that helps U
  • Re: Converting files into .rar file

    05-17-2008, 10:30 AM
    Answer

    Try this code:

    try replacing .Zip with .rar in second line of code

            FileStream sourceFile = File.OpenRead(@"C:\sample.xml");
            FileStream destFile = File.Create(@"C:\sample.zip");

            GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);

            try
            {
                int theByte = sourceFile.ReadByte();
                while (theByte != -1)
                {
                    compStream.WriteByte((byte)theByte);
                    theByte = sourceFile.ReadByte();
                }
            }
            finally
            {
                compStream.Dispose();
            }

    Mark as Answer if the post was useful to you

    Rajesh Thangarasu
    Microsoft Certified Professional
Page 1 of 1 (3 items)