Skip to main content

Posts

Showing posts from September, 2014

How to post a dynamic form using json data?

// Post dynamic form using json data   function post(uri, data, method) { // when method not provided use default post method method = method || "post" ;     var form = document.createElement( "form" ); form.setAttribute( "method" , method); form.setAttribute( "action" , uri); for ( var property in data) {   if (params.hasOwnProperty(property)) {     var hiddenField = document.createElement( "input" );     hiddenField.setAttribute( "type" , "hidden" );     hiddenField.setAttribute( "name" , property);     hiddenField.setAttribute( "value" , data[property]);      form.appendChild(hiddenField);   } } document.body.appendChild(form); form.submit(); }

How to Gzip and export a csv stream in web usig c#

using System.IO.Compression; public static void ExportAsGZip(Stream stream, string fileName) {     HttpContext.Current.Response.ContentType = "application/gzip";     HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.gz", fileName));     using (GZipStream compressionStream = new GZipStream(HttpContext.Current.Response.OutputStream, CompressionMode.Compress))     {       stream.CopyTo(compressionStream);     } }