Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drag and drop file handler client/server -- server code
<%@ WebHandler Language="C#" Class="FileHandler" %>
using System;
using System.Web;
public class FileHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
foreach (string key in files)
{
HttpPostedFile file = files[key];
//string fileName = file.FileName;
//fileName = context.Server.MapPath("~/uploads/" + fileName);
string fileName = context.Server.MapPath("~/uploads/" + key);
file.SaveAs(fileName);
}
}
context.Response.ContentType = "text/plain";
context.Response.Write("File(s) uploaded successfully!");
}
public bool IsReusable
{
get { return false; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment