Attachments in rtf file

I have a situation where i have a directory full of rtf file. All the rtf file have attachments. I wrote some code that will let me get to the attachments but how can I save each attachment. Here's my code:
=====================================================================
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim i As Integer
Dim fl As Word.InlineShape
Dim fr As Word.OLEFormat

oWord = New Word.Application
oDoc = oWord.Documents.Open(FileName)
For i = 1 To oDoc.InlineShapes.Count
fl = oDoc.InlineShapes.Item(i)
fr = fl.OLEFormat
fr.Open()
Next

odoc.close(SaveChanges:=False)
oDoc = Nothing
oWord.Quit()
oWord = Nothing
======================================================================

I used the open method of the OLEFormat just to verify that I'm referecing the attachment. But how can I save the attachment. The OLEFormat doesn't have a save as method. So is there another way that I can accomplish this.
Please help........


Comments

  • : I have a situation where i have a directory full of rtf file. All the rtf file have attachments. I wrote some code that will let me get to the attachments but how can I save each attachment. Here's my code:
    : =====================================================================
    : Dim oWord As Word.Application
    : Dim oDoc As Word.Document
    : Dim i As Integer
    : Dim fl As Word.InlineShape
    : Dim fr As Word.OLEFormat
    :
    : oWord = New Word.Application
    : oDoc = oWord.Documents.Open(FileName)
    : For i = 1 To oDoc.InlineShapes.Count
    : fl = oDoc.InlineShapes.Item(i)
    : fr = fl.OLEFormat
    : fr.Open()
    : Next
    :
    : odoc.close(SaveChanges:=False)
    : oDoc = Nothing
    : oWord.Quit()
    : oWord = Nothing
    : ======================================================================
    :
    : I used the open method of the OLEFormat just to verify that I'm referecing the attachment. But how can I save the attachment. The OLEFormat doesn't have a save as method. So is there another way that I can accomplish this.
    : Please help........
    :
    :
    :
    Hi,
    this is not so easy, because as you said - there's no save method.
    You can use fl.Select to virtually select the InlineShape, and then call oWord.Selection.Copy to get it into clipboard.
    Now, the task changes to "How to save clipboard to file", .NET serves you ClipBoard object to acomplish this..



    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


  • : : I have a situation where i have a directory full of rtf file. All the rtf file have attachments. I wrote some code that will let me get to the attachments but how can I save each attachment. Here's my code:
    : : =====================================================================
    : : Dim oWord As Word.Application
    : : Dim oDoc As Word.Document
    : : Dim i As Integer
    : : Dim fl As Word.InlineShape
    : : Dim fr As Word.OLEFormat
    : :
    : : oWord = New Word.Application
    : : oDoc = oWord.Documents.Open(FileName)
    : : For i = 1 To oDoc.InlineShapes.Count
    : : fl = oDoc.InlineShapes.Item(i)
    : : fr = fl.OLEFormat
    : : fr.Open()
    : : Next
    : :
    : : odoc.close(SaveChanges:=False)
    : : oDoc = Nothing
    : : oWord.Quit()
    : : oWord = Nothing
    : : ======================================================================
    : :
    : : I used the open method of the OLEFormat just to verify that I'm referecing the attachment. But how can I save the attachment. The OLEFormat doesn't have a save as method. So is there another way that I can accomplish this.
    : : Please help........
    : :
    : :
    : :
    : Hi,
    : this is not so easy, because as you said - there's no save method.
    : You can use fl.Select to virtually select the InlineShape, and then call oWord.Selection.Copy to get it into clipboard.
    : Now, the task changes to "How to save clipboard to file", .NET serves you ClipBoard object to acomplish this..
    :
    :
    :
    : [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]
    :
    : [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]
    :
    :
    : Is there an example of how to copy and paste a file object or embedded object out there that I can reference to. The embedded object are pdf file that were saved during outlook. So when I get to the oleformat.progid is reads it as Outlook.AttachFile.

  • : : : I have a situation where i have a directory full of rtf file. All the rtf file have attachments. I wrote some code that will let me get to the attachments but how can I save each attachment. Here's my code:
    : : : =====================================================================
    : : : Dim oWord As Word.Application
    : : : Dim oDoc As Word.Document
    : : : Dim i As Integer
    : : : Dim fl As Word.InlineShape
    : : : Dim fr As Word.OLEFormat
    : : :
    : : : oWord = New Word.Application
    : : : oDoc = oWord.Documents.Open(FileName)
    : : : For i = 1 To oDoc.InlineShapes.Count
    : : : fl = oDoc.InlineShapes.Item(i)
    : : : fr = fl.OLEFormat
    : : : fr.Open()
    : : : Next
    : : :
    : : : odoc.close(SaveChanges:=False)
    : : : oDoc = Nothing
    : : : oWord.Quit()
    : : : oWord = Nothing
    : : : ======================================================================
    : : :
    : : : I used the open method of the OLEFormat just to verify that I'm referecing the attachment. But how can I save the attachment. The OLEFormat doesn't have a save as method. So is there another way that I can accomplish this.
    : : : Please help........
    : : :
    : : :
    : : :
    : : Hi,
    : : this is not so easy, because as you said - there's no save method.
    : : You can use fl.Select to virtually select the InlineShape, and then call oWord.Selection.Copy to get it into clipboard.
    : : Now, the task changes to "How to save clipboard to file", .NET serves you ClipBoard object to acomplish this..
    : :
    : :
    : :
    : : [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]
    : :
    : : [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]
    : :
    : :
    : : Is there an example of how to copy and paste a file object or embedded object out there that I can reference to. The embedded object are pdf file that were saved during outlook. So when I get to the oleformat.progid is reads it as Outlook.AttachFile.
    :
    :
    Hi,
    I took a look at it and now, I'm not so sure, if I guided you to correct way.. And I'm not sure if it's possible to extract that file (but I belive it is)

    I used this code to explore content of clipboard. It loops throught available content types, shows String content and saves memorystream types to C:TypeName (without extension)

    The closest things was Embedded Object in my file, but I'm now sure about exact format of your document. You may find there something usefull.. Take a look at it

    [code]Dim fs As FileStream, Data As Object
    Dim ms As MemoryStream

    Dim Formats() As String = Clipboard.GetDataObject.GetFormats
    For Each f As String In Formats
    If f = "EnhancedMetafile" Then
    MsgBox(f & " skip")
    Else
    Data = Clipboard.GetData(f)
    If Data Is Nothing Then
    MsgBox(f & " is nothing")
    ElseIf TypeOf Data Is String Then
    MsgBox(f & ": " & Data.ToString)
    ElseIf TypeOf Data Is MemoryStream Then
    fs = New FileStream("C:" & f, FileMode.CreateNew)
    ms = CType(Data, MemoryStream)
    ms.WriteTo(fs)
    ms.Close()
    fs.Close()
    Else
    MsgBox(f & ": .GetType=" & Data.GetType.ToString)
    End If
    End If
    Next[/code]

    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories