using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Contacts : System.Web.UI.Page
{
    public void Export(string fileName, string contentType, byte[] data)
    {
        Response.ClearContent();
        Response.ContentType = contentType;
        Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
        Response.AddHeader("Content-Length", data.Length.ToString());
        Response.BinaryWrite(data);
        Response.End();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack && Request.Form["fileName"] != null)
        {
            string fileName = Request.Form["fileName"].ToString();
            string contentType = Request.Form["contentType"].ToString();
            byte[] data = Convert.FromBase64String(Request.Form["base64"].ToString());

            Export(fileName, contentType, data);
        }
    }
}