2010-10-30 43 views
3

即時通訊創建一個web表單,需要用戶上傳doc,docxorpdf格式的文件 將提交表單發送到一個電子郵件地址以及附加文件,我已經成功地實現了發佈表單到電子郵件地址,但不知道如何將文件與它連接... plz幫助文件附件窗體c#

public void ProcessRequest(HttpContext context) 
     { 
      string template = context.Request["template"]; 

      string responseHtml = BuiltTemplateHtml(context.Request, template, "response", false); 
      string reuestEmailHtml = BuiltTemplateHtml(context.Request, template, "request_email", false); 
      string contactEmail = GetTagsInnerText(reuestEmailHtml, "to", 0); 
      string contactName = GetTagsInnerText(reuestEmailHtml, "toname", 0); 

      string responEmailHtml = BuiltTemplateHtml(context.Request, template, "response_email", true, "contactName", contactName, "contactEmail", contactEmail); 



      sendEmail(reuestEmailHtml); 
      sendEmail(responEmailHtml); 
      context.Response.ContentType = "text/html"; 
      context.Response.Write(responseHtml); 

      SaveAttachments(context, reuestEmailHtml); 

     } 

     private void SaveAttachments(HttpContext context, string settingFile) 
     { 
      if (context.Request.Files.Count > 0) 
      { 
       string fileNameformat = GetTagsInnerText(settingFile, "fileNameformat", 0); 
       string[] savefiles = GetTagsInnerText(settingFile, "savefiles", 0).Split('|', ','); 
       string[] allowextensions = GetTagsInnerText(settingFile, "allowextensions", 0).Split('|', ',');     





       string path = cleanPath(fileNameformat); 

       MailMessage mail = new MailMessage(); 

      // attachment code here 









      } 
     } 

回答

2

檢查了這一點,

// 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); 

,並檢查MSDN上這個鏈接瞭解更多信息, http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments.aspx

3

MailMessage類有一個Attachments屬性,該屬性可以用來將附件添加到郵件中。

+0

TNX的幫助... – Rafay 2010-11-01 05:40:04