Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3452760
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:17:45+00:00 2026-05-18T09:17:45+00:00

I am dynamically generating a number of different types of files based upon a

  • 0

I am dynamically generating a number of different types of files based upon a GridView in ASP.NET – an Excel spreadsheet and a HTML file. I am doing so using this code (this is just for the Excel spreadsheet):

  Response.Clear();
  Response.AddHeader("content-disposition", "attachment;filename=InvoiceSummary" + Request.QueryString["id"] + ".xls");
  Response.Charset = "";

  Response.ContentType = "application/vnd.xls";
  System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
  contents.RenderControl(htmlWrite);
  //GridView1.RenderControl(htmlWrite);
  Response.Write(stringWrite.ToString());
  Response.End();

I would like to give users the options of emailing the generated file as an attachment to either an email address they specify or one linked with their account on the database. But I don’t want the user to have to save the file, then attach it in a form – I’d like to automatically attach the generated file. Is this possible, and how easy is it?

Of course, I’ll be using the System.Net.Mail class to send mail…if it’s possible anyway!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:17:46+00:00Added an answer on May 18, 2026 at 9:17 am

    You might be able to create System.Net.Mail.Attachment from string then send out the mail as normal.

    var m = new System.Net.Mail.MailMessage(from, to, subject, body);
    var a = System.Net.Mail.Attachment.CreateAttachmentFromString(stringWrite.ToString(), "application/vnd.xls");
    m.Attachments.Add(a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm generating controls dynamically on my asp.net page by xslt transformation from an xml
I am dynamically generating html file. It is formated with Css and Images. I
I'm dynamically generating image from text, and existing image on my asp.net website. Here
For my webpage, I have a number of lists which I'm generating dynamically from
i'm dynamically generating asp controls inside an update panel on a certain trigger. However,
I've built an ASP.NET page whose output stream is a dynamically-generated PNG image containing
I'm dynamically generating RDL files for SSRS 2008, assembling my reports from building blocks
I am working on an ASP.Net web application that must print dynamically created labels
I am dynamically generating the form based on the drop down selected. The form
I am dynamically generating (in a PHP script) a .mobileconfig file for iOS devices

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.