|
using System.IO;
using System.Linq;
using System.Web;
public class UploadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string path = Path.Combine(context.Request.PhysicalApplicationPath, context.Request.Url.Segments.Last());
if (context.Request.RequestType == "DELETE")
{
File.Delete(path);
}
else if (context.Request.RequestType == "MOVE")
{
string destination = Path.Combine(context.Request.PhysicalApplicationPath, context.Request.Headers["Destination"].Split(new char[] { '/' }).Last());
File.Move(path, destination);
}
else if (context.Request.RequestType == "PUT")
{
byte[] fileBytes;
using (var reader = new BinaryReader(context.Request.InputStream))
{
fileBytes = reader.ReadBytes((int)context.Request.InputStream.Length);
}
File.WriteAllBytes(path, fileBytes);
}
}
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.