Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version

Upload files using an HttpHandler

, 9 Dec 2009
Using an HttpHandler to upload a file.
UploadHttphandler.zip
UploadHttphandler
UploadHttphandler
App_Data
bin
UploadHttphandler.dll
FileSave
Properties
UploadHttphandler.csproj.user
UploadHttphandler.suo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UploadHttphandler
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    public class UploadHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string filePath = "FileSave//";

            //write your handler implementation here.
            if (context.Request.Files.Count <= 0)
            {
                context.Response.Write("No file uploaded");
            }
            else
            {
                for (int i = 0; i < context.Request.Files.Count; ++i)
                {
                    HttpPostedFile file = context.Request.Files[i];
                    file.SaveAs(context.Server.MapPath(filePath+file.FileName));
                    context.Response.Write("File uploaded");
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ritesh Ramesh
Architect Infosolvex Solutions Inc
Australia Australia
Ritesh is an IT consultant with over ten years of experience in the IT industry varying from consultation, architecture, design, development to technical management. He has a strong background in solutions and applications architecture with a focus on Microsoft’s .Net platform. His area of expertise spans design and implementation of client/server, database and web-based systems. He has worked with C#, ASP.NET 1.1 and 2.0, ADO.NET, Web Services and SQL technology on several enterprise class projects.
 

 

Freedom is not worth having if it does not include the freedom to make mistakes.
Mahatma Gandhi

| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 9 Dec 2009
Article Copyright 2009 by Ritesh Ramesh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid