Receiving file via HTTP simple script for IIS

I was working for a customer and there was a need for receiving files via HTTP and saving them to disk. A BizTalk receive location was enabled on that location and processed the file after it was stored. Normally you would make use of BTSHTTPReceive.dll and directly send it to a BizTalk location. In this case the client wanted a buffer location for the files.

I created a simple script to do just that with no editting in the iis settings. Just create a file in the iis folder with the name ReHttpsRawPost.ashx with the following code:

<%@ WebHandler Language="C#" Class="ReHttpsRawPost" %>

using System;
using System.Web;
using System.IO;
using System.Collections.Specialized;

public class ReHttpsRawPost : IHttpHandler {

public void ProcessRequest (HttpContext context)
string path = @"D:\Messages\out\interfacename";

if (!System.IO.Directory.Exists(path))

context.Response.ContentType = "text/plain";
string destionationPath = Path.Combine(path, Guid.NewGuid() + ".xml");

if (!File.Exists(destionationPath))
using (FileStream fs = File.Create(destionationPath)) { }

context.Request.SaveAs(destionationPath, false);

public bool IsReusable {
get {
return false;


Now you can you the https settings in IIS to encrypt the transfer and disable anonymous settings so posting is only allowed with username and password.

Enjoy the script, let me know if it works!


Leave a Reply