2010-07-20 17 views
5

मेरे पास कोड है जो एक पीडीएफ फ़ाइल उत्पन्न करता है और मैं इसे एक ईमेल के अनुलग्नक के रूप में भेजना चाहता हूं।उत्पन्न पीडीएफ फ़ाइल को सी # से ईमेल में अनुलग्नक के रूप में कैसे भेजा जाए?

मैं इस कोड है:

 FileContentResult fileContentResult = File(fileName, "application/pdf", "file.pdf"); 

और मैं एक अनुलग्नक

 Attachment a = new Attachment(); 
     sender.SendMail("[email protected]", "[email protected]", "subject", "Body", a); 

ईमेल करने के लिए इस कोड है मैं कैसे एक FileContentResult परिवर्तित एक लगाव वस्तु में?

+0

। मेमोरीस्ट्रीम बिट यहां दिखाया गया है http://stackoverflow.com/questions/1196059/itextsharp-sending-in-memory-pdf-in-an-email-attachment – Tahbaza

उत्तर

8

क्या आपने इसका उपयोग करने का प्रयास किया है: Attachment Constructor (Stream, ContentType)?

कुछ

तरह
MemoryStream ms = new MemoryStream(fileContentResult.FileContents); 
// Create an in-memory System.IO.Stream 

ContentType ct = new ContentType(fileContentResult.ContentType); 

Attachment a = new Attachment(ms, ct); 
+0

@ मॉरॉन - यह कोड संकलित नहीं करता है। मैंने उपरोक्त उस चर का नाम बदल दिया है। यह लाइन पहचाना नहीं गया है: ContentType ct = stream.ContentType; – leora

+0

@ooo: आपको System.IO' का उपयोग करने की आवश्यकता है, क्या आपके पास यह है? कोड को स्ट्रीम के रूप में भी संपादित किया गया। सामग्री प्रकार स्पष्ट रूप से स्ट्रिंग था। –

+0

@ मॉरॉन - यह लाइन पहचाना नहीं गया है: ContentType ct = stream.ContentType; – leora

1

मैं सिर्फ 7 साल देर से कर रहा हूँ, लेकिन यहाँ अपने जवाब है: आप शायद एक MemoryStream में सामान अपने FileContentResult उदाहरण के FileContents संपत्ति का उपयोग करें और भेजना चाहते हैं

Attachment a = new Attachment(fileName, "application/pdf"); 
sender.SendMail("[email protected]", "[email protected]", "subject", "Body", a); 
+0

अकेले हास्य के लिए वोट! – sondlerd

संबंधित मुद्दे