2014-06-25 56 views
0

我們使用第三方公司進行採購。一些採購訂單有Word,Excel等支持文件。該公司可以將文件提供給包含文件MIME編碼的txt文件。下面的例子。VB如何從MIME編碼的文本文件中提取附件

尋找一個VB解決方案來讀取此文件並將文檔提取到磁盤。任何幫助將不勝感激。

-------------------------------MIME_BOUNDARY_FOR_ATTACHMENTS 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: binary 
Content-ID: <[email protected]> 
Content-Disposition: attachment; filename="happy_path_reqs.png" 

‰PNG 
IHDR È ¥ 2² € IDATxÚì]`TUÖNOè`n¯ %4»»k_ËZ鮺ºÝ†kTºÒ{jX‘ 
µ)&ؼBßÛGËY3pV£[email protected]â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî 
µ)&ؼBßÛGËY3pV£[email protected]â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî 
µ)&ؼBßÛGËY3pV£[email protected]â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî 
µ)&ؼBßÛGËY3pV£[email protected]â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî 
-------------------------------MIME_BOUNDARY_FOR_ATTACHMENTS-- 

回答

1

我不熟悉VB.NET,但你應該能夠使用MimeKit分析這些MIME格式的文件。我已經使用它很多成功了很長一段時間了。

在C#中,你會做這樣的事情:

var message = MimeMessage.Load ("email.msg"); 

foreach (var attachment in message.Attachments) { 
    using (var stream = File.Create (attachment.FileName)) 
     attachment.ContentObject.DecodeTo (stream); 
} 

在VB.NET,它很可能是這樣的:

Dim message As MimeMessage.Load ("email.msg") 

For Each attachment As MimePart In message.Attachments 
    Dim stream As File.Create (attachment.FileName) 
    attachment.ContentObject.DecodeTo (stream) 
    stream.Dispose() 
Next