Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 901305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:32:09+00:00 2026-05-15T15:32:09+00:00

I am trying to do this using C#(Winforms). The code I am using is

  • 0

I am trying to do this using C#(Winforms).
The code I am using is giving me a string as an output, but I need to have a zipped file.

I am using the following code

try
{
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(
                            "ftp:SITENAME/FILENAME.zip");
    request.Method = WebRequestMethods.Ftp.DownloadFile;

    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential("", "");

    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

    Stream responseStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(responseStream);
    //StreamWriter writer = new StreamWriter(responseStream);

    MessageBox.Show(reader.ReadtoEnd);

    MessageBox.Show("Download Complete, status {0}" + response.StatusCode);

    reader.Close();
    response.Close();
}
catch (NotSupportedException ne)
{
    MessageBox.Show(ne.Message);
}

I have an idea that I have to use Open source library from SharpZipLib to convert this string to a zipped file. But,I cannot find any sample code to show me how to do that.

I would really appreciate if someone can guide me through the process.

Thanks,

Sidhanshu

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:32:10+00:00Added an answer on May 15, 2026 at 3:32 pm

    This might do just that.

    using ICSharpCode.SharpZipLib.BZip2;
    
        public static string Unzip(byte[] compressedbytes)
                {
                    string result;
                    MemoryStream m_msBZip2 = null;
                    BZip2InputStream m_isBZip2 = null;
    
                    m_msBZip2 = new MemoryStream(compressedbytes);
                    // read final uncompressed string size stored in first 4 bytes
                    using (BinaryReader reader = new BinaryReader(m_msBZip2, System.Text.Encoding.ASCII))
                    {
                        Int32 size = reader.ReadInt32();
    
                        m_isBZip2 = new BZip2InputStream(m_msBZip2);
                        byte[] bytesUncompressed = new byte[size];
                        m_isBZip2.Read(bytesUncompressed, 0, bytesUncompressed.Length);
                        m_isBZip2.Close();
                        m_msBZip2.Close();
    
                        result = Encoding.ASCII.GetString(bytesUncompressed, 0, bytesUncompressed.Length);
    
                        reader.Close();
                    }
    
                    return result;
                }
    
                public static byte[] Zip(string sBuffer)
                {
    
                    byte[] result;
    
                    using (MemoryStream m_msBZip2 = new MemoryStream())
                    {
                        Int32 size = sBuffer.Length;
                        // Prepend the compressed data with the length of the uncompressed data (firs 4 bytes)
                        using (BinaryWriter writer = new BinaryWriter(m_msBZip2, System.Text.Encoding.ASCII))
                        {
                            writer.Write(size);
    
                            using (BZip2OutputStream m_osBZip2 = new BZip2OutputStream(m_msBZip2))
                            {
                                m_osBZip2.Write(Encoding.ASCII.GetBytes(sBuffer), 0, sBuffer.Length);
                                m_osBZip2.Close();
                            }
    
                            writer.Close();
                            result = m_msBZip2.ToArray();
    
                            m_msBZip2.Close();
                        }
                    }
    
                    return result;
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
I am trying to achieve this using Expression Blend 3. I need that every
I'm trying to retrieve this page using Apache HttpClient: http://quick-dish.tablespoon.com/ Unfortunately, when I try
I am trying to make this button using CSS3: But my button looks like
I am trying to follow this tutorial ( Using-core-plot-in-an-iphone-application ). When I try to
I'm trying to write this code using mostly arrays. I'm trying to get Correct
I am trying to show listbox in but it didnt works, this code in
I have some simple example WinForms code which I am trying to translate into
EDIT: trying to excute the following code in Winforms. I am fetching the data
I am trying to run the following code on a .net 2 winforms app:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.