• <tfoot id='dvceP'></tfoot>
    • <bdo id='dvceP'></bdo><ul id='dvceP'></ul>
  • <small id='dvceP'></small><noframes id='dvceP'>

        <legend id='dvceP'><style id='dvceP'><dir id='dvceP'><q id='dvceP'></q></dir></style></legend>

        <i id='dvceP'><tr id='dvceP'><dt id='dvceP'><q id='dvceP'><span id='dvceP'><b id='dvceP'><form id='dvceP'><ins id='dvceP'></ins><ul id='dvceP'></ul><sub id='dvceP'></sub></form><legend id='dvceP'></legend><bdo id='dvceP'><pre id='dvceP'><center id='dvceP'></center></pre></bdo></b><th id='dvceP'></th></span></q></dt></tr></i><div id='dvceP'><tfoot id='dvceP'></tfoot><dl id='dvceP'><fieldset id='dvceP'></fieldset></dl></div>

        将文件从 MemoryStream 附加到 C# 中的 MailMessage

        Attach a file from MemoryStream to a MailMessage in C#(将文件从 MemoryStream 附加到 C# 中的 MailMessage)
          • <small id='VmT6s'></small><noframes id='VmT6s'>

              <i id='VmT6s'><tr id='VmT6s'><dt id='VmT6s'><q id='VmT6s'><span id='VmT6s'><b id='VmT6s'><form id='VmT6s'><ins id='VmT6s'></ins><ul id='VmT6s'></ul><sub id='VmT6s'></sub></form><legend id='VmT6s'></legend><bdo id='VmT6s'><pre id='VmT6s'><center id='VmT6s'></center></pre></bdo></b><th id='VmT6s'></th></span></q></dt></tr></i><div id='VmT6s'><tfoot id='VmT6s'></tfoot><dl id='VmT6s'><fieldset id='VmT6s'></fieldset></dl></div>
              <tfoot id='VmT6s'></tfoot>

                <tbody id='VmT6s'></tbody>
                <bdo id='VmT6s'></bdo><ul id='VmT6s'></ul>
              • <legend id='VmT6s'><style id='VmT6s'><dir id='VmT6s'><q id='VmT6s'></q></dir></style></legend>

                  本文介绍了将文件从 MemoryStream 附加到 C# 中的 MailMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写一个将文件附加到电子邮件的程序.目前我正在使用 FileStream 将文件保存到磁盘中,然后我使用

                  I am writing a program to attach a file to email. Currently I am saving file using FileStream into disk, and then I use

                  System.Net.Mail.MailMessage.Attachments.Add(
                      new System.Net.Mail.Attachment("file name")); 
                  

                  我不想将文件存储在磁盘中,我想将文件存储在内存中,然后从内存流中将其传递给 Attachment.

                  I do not want to store file in disk, I want to store file in memory and from memory stream pass this to Attachment.

                  推荐答案

                  这里是示例代码.

                  System.IO.MemoryStream ms = new System.IO.MemoryStream();
                  System.IO.StreamWriter writer = new System.IO.StreamWriter(ms);
                  writer.Write("Hello its my sample file");
                  writer.Flush();
                  writer.Dispose();
                  ms.Position = 0;
                  
                  System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Plain);
                  System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(ms, ct);
                  attach.ContentDisposition.FileName = "myFile.txt";
                  
                  // I guess you know how to send email with an attachment
                  // after sending email
                  ms.Close();
                  

                  编辑 1

                  您可以通过 System.Net.Mime.MimeTypeNames 指定其他文件类型,例如 System.Net.Mime.MediaTypeNames.Application.Pdf

                  You can specify other file types by System.Net.Mime.MimeTypeNames like System.Net.Mime.MediaTypeNames.Application.Pdf

                  根据 Mime 类型,您需要在 FileName 中指定正确的扩展名,例如 "myFile.pdf"

                  Based on Mime Type you need to specify correct extension in FileName for instance "myFile.pdf"

                  这篇关于将文件从 MemoryStream 附加到 C# 中的 MailMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                      <tbody id='gkebt'></tbody>
                  1. <i id='gkebt'><tr id='gkebt'><dt id='gkebt'><q id='gkebt'><span id='gkebt'><b id='gkebt'><form id='gkebt'><ins id='gkebt'></ins><ul id='gkebt'></ul><sub id='gkebt'></sub></form><legend id='gkebt'></legend><bdo id='gkebt'><pre id='gkebt'><center id='gkebt'></center></pre></bdo></b><th id='gkebt'></th></span></q></dt></tr></i><div id='gkebt'><tfoot id='gkebt'></tfoot><dl id='gkebt'><fieldset id='gkebt'></fieldset></dl></div>
                    <tfoot id='gkebt'></tfoot>
                        <bdo id='gkebt'></bdo><ul id='gkebt'></ul>
                        • <small id='gkebt'></small><noframes id='gkebt'>

                          1. <legend id='gkebt'><style id='gkebt'><dir id='gkebt'><q id='gkebt'></q></dir></style></legend>