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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:56:06+00:00 2026-05-30T14:56:06+00:00

I am trying to work out how to use the new asp.net 4.5 async

  • 0

I am trying to work out how to use the new asp.net 4.5 async handlers as well as the Request.GetBufferlessInputStream to write a image upload out to disk. This code runs and it writes a file out but the image is corrupt and I am not sure why. Here is the code I am using

public class UploadHandler : HttpTaskAsyncHandler
{
    public override Task ProcessRequestAsync(HttpContext context)
    {
        // Gets a Stream object that can be used to read the 
        // incoming HTTP entity body, optionally disabling the
        // request-length limit that is set in the MaxRequestLength property.

        // This method provides an alternative to using the 
        // InputStream property. The InputStream property waits until the
        // whole request has been received before it returns a Stream object. 
        // In contrast, the GetBufferlessInputStream method returns
        // the Stream object immediately. 
        // You can use the method to begin processing the 
        // entity body before the complete contents of the 
        // body have been received.
        // The entity body (or as much of it as you request and has
        // been received) is returned only when you use the object that 
        // is returned by this method to read the stream, by calling 
        // methods such as the Read method. You use parameters of the 
        // Read method to specify how much of the entity body to read.

        // This method can be useful if the request is uploading a 
        // large file and you want to begin accessing the file contents
        // before the upload is finished. 
        // However, you should only use this method for scenarios where
        // you want to take over all processing of the entity body. 
        // This means that you cannot use this method from an .aspx page, 
        // because by the time an .aspx page runs, the entity body 
        // has already been read.

        using (Stream input = context.Request.GetBufferlessInputStream(true))
        using (var file = new FileStream("C:\\myfile.jpg", FileMode.Create, 
            FileAccess.Write, FileShare.Write))
        {
            input.CopyTo(file);
        }

        context.Response.ContentType = "text/plain";
        return context.Response.Output.WriteAsync("Done");
    }
}
  • 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-30T14:56:07+00:00Added an answer on May 30, 2026 at 2:56 pm

    Well it looks like there is an easy way to handle this now using ASP.NET Web Api!

    Read about it here: http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx

    Use one of these bad boys MultipartFormDataStreamProvider

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work out how to use the CrmService to close a Task
I'm trying to work out the correct pattern to use for a Singleton that
I am trying to work out how to configure PHPUnit to use the test
trying to work out how to use constructors with an inherited class. I know
I'm trying to work out how to use the icalendar ruby gem, found at:
I am trying to use new .net 4.0 Routing for Web Forms with mixed
I'm checking out Linq for NHibernate 2.1 to use in an ASP.NET MVC application
I'm new to BDD, and using SpecFlow I'm trying to work out an efficient,
I am trying to work out how to use the Branch-per-feature approach in mercurial
I'm new to SQL and database design and trying to work out if the

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.