WebFormsを使用しているので、私はrendering your log sheet in a Control as a string、次にattaching that to a MailMessageをお勧めします。
レンダリング部分は少し次のようになります。
public static string GetRenderedHtml(this Control control)
{
StringBuilder sbHtml = new StringBuilder();
using (StringWriter stringWriter = new StringWriter(sbHtml))
using (HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter))
{
control.RenderControl(textWriter);
}
return sbHtml.ToString();
}
編集可能なコントロール(TextBox
、DropDownList
、など)を持っている場合、あなたはGetRenderedHtml()
を呼び出す前に、ラベルやリテラルでそれらを交換する必要があります。完全な例については、this blog postを参照してください。ここで
はMSDN example for attachmentsです:
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
string file = "data.xls";
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"[email protected]",
"[email protected]",
"Quarterly data report.",
"See the attached spreadsheet.");
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
のための仕事をするかもしれません。 – Matt
@Matt razorテンプレートはウェブフォームでも機能します。 – adt
これは知っておきたいことですが、残念ながらasp.net 3.5をまだ実行していて、RazorEngineには4.0が必要です – Matt