Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to send excel attachment mail which is converted from datatable without saving to system in asp.net

How to send excel attachment mail which is converted from datatable without saving to system in asp.net

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    ven753
    wrote on last edited by
    #1

    hi i have result in datatable and i converted to excel using streamwriter. Now i dont want save to computer and then send mail by using that path. Is there any other method that i can send that excel without saving to system in c#. If anybody knows, please reply me. Thanks in advance.

    Richard DeemingR 1 Reply Last reply
    0
    • V ven753

      hi i have result in datatable and i converted to excel using streamwriter. Now i dont want save to computer and then send mail by using that path. Is there any other method that i can send that excel without saving to system in c#. If anybody knows, please reply me. Thanks in advance.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Try using a MemoryStream[^] to store the Excel file, and pass that stream to the Attachment constructor[^].

      var ms = new MemoryStream();
      using (var sw = new StreamWriter(ms))
      {
      RenderExcelAttachment(sw);
      }

      var attachment = new Attachment(ms, "data.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      message.Attachments.Add(attachment);


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups