GridView to Excel Export

Jun 21 2013 11:32 AM
Im always getting error when i open my file "the file extension is invalid"

HttpResponse r = Response;

            //clean up the response.object
            
            r.Clear();
            r.Buffer = true;
            r.Charset = "UTF-8";
            //set the response mime type for excel
            r.ContentType = "application/vnd.ms-excel";
            string attachment = "attachment; filename=Report" + ".xls";
            r.AddHeader("content-disposition", attachment);           
            r.ContentEncoding = new System.Text.UTF8Encoding();
            r.Write(content);
  r.End();

Anyone whats the problem ?        

Answers (4)