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 452271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:03:21+00:00 2026-05-12T22:03:21+00:00

i have problem in sending zip file in network.. all other formats i am

  • 0

i have problem in sending zip file in network.. all other formats i am able to send except .zip..

i tried a lot i dont no how to do this.. the code i have written at client side to upload file, this is suggested by microsoft here is the link

i am able to create zip file, if i try to open it says corrupted..size of the file also varying lot.

here is code

  public void UploadFile(string localFile, string uploadUrl)
    {

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);

        req.Method = "PUT";
        req.AllowWriteStreamBuffering = true;

        // Retrieve request stream and wrap in StreamWriter
        Stream reqStream = req.GetRequestStream();
        StreamWriter wrtr = new StreamWriter(reqStream);

        // Open the local file


        Stream Stream = File.Open(localFile, FileMode.Open);

        // loop through the local file reading each line 
        //  and writing to the request stream buffer 

        byte[] buff = new byte[1024];
        int bytesRead;
        while ((bytesRead = Stream.Read(buff, 0,1024)) > 0)
        {
            wrtr.Write(buff);
        }



        Stream.Close();
        wrtr.Close();

        try
        {
            req.GetResponse();
        }
        catch(Exception ee)
        {

        }

        reqStream.Close();

please help me…

Thanks

  • 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-12T22:03:21+00:00Added an answer on May 12, 2026 at 10:03 pm

    The main problem is that you’re using a StreamWriter, which is a TextWriter, designed for text data, not binary files like zip files.

    Additionally there’s the problem Jacob mentioned, and also the fact that you’re not closing the request stream until after you’ve received the response – although that won’t make any difference because the StreamWriter will close it first.

    Here’s the fixed code, changed to use using statements (to avoid leaving streams open), a simpler call to the File class, and more meaningful names (IMO).

    using (Stream output = req.GetRequestStream())
    using (Stream input = File.OpenRead(localFile))
    {
        // loop through the local file reading each line 
        //  and writing to the request stream buffer 
    
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = input.Read(buffer, 0, 1024)) > 0)
        {
            output.Write(buffer, 0, bytesRead);
        }
    }
    

    Note that you can easily extract the while loop into a helper method:

    public static void CopyStream(Stream input, Stream output)
    {
        // loop through the local file reading each line 
        //  and writing to the request stream buffer 
    
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = input.Read(buffer, 0, 1024)) > 0)
        {
            output.Write(buffer, 0, bytesRead);
        }
    }
    

    to be used from other places, leaving just:

    using (Stream output = req.GetRequestStream())
    using (Stream input = File.OpenRead(localFile))
    {
        CopyStream(input, output);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when trying to send a POST request. The sending method
I have problem while sending messages from android to PC. Messages are send when
greetings all i have a problem that when sending an email from the server
I have a problem sending POST request with VB6. The code below works properly
Hi I have a problem in sending data from php to pdf. I think
I have a problem when I want to sending data using byte format in
I have a little problem, I'm making project and I'm sending data from client
I have problem for bulk insert of the file.I am saving the multiple record
I have problem sending emails, i checked the email sending error logs, and I
I have problem with sending objects via TCPClient. At first, I serialize them into

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.