You are viewing limited content. For full access, please sign in.

Question

Question

Switching from LFSO to RA ( LFElectFileReadStream & LFElectFileWriteStream)

SDK
asked on June 23, 2014

Hi,

 

I am trying to read an LF electronic document (MS Word File as OpenXML WordprocessingDocument) using a Stream Reader, pass it to a Memory Stream, replace some values, then Append my changes to the same document using a Stream Writer.

 

I use to do this through LFSO in a few steps as follows:
    ''Read
    Dim doc as LFDocument=me.Entry
    Dim Datastream as LFElectFileReadStream =Doc.ElectFile.ReadStream
    Datastream.open()
    Dim content as Byte() =Datastream.ReadData(Datastream.DataLength)
    Dim mem as new MemoryStream(content)
    Datastream.Close()
    '<<Modification Here>>
    
    ''Write
    Dim data() as Byte = mem.toarray()
    Dim Datawriter as  LFElectFileWriteStream
    Datawriter=doc.ElectFile.WriteStream
    Datawriter.Open(data.LongLength)
    Datawriter.Write(data)
    Datawriter.Update
    Datawriter.close
        
While using RA, i was able to read the document, pass it to a Memory Stream, and replace the required values; but i am not able to append my changes:
    ''Read
    Dim LFDoc As DocumentInfo = me.BoundEntryInfo
    Dim LFElecReadStream As LaserficheReadStream
    Dim MIMEType As String = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    LFElecReadStream = LFDoc.ReadEdoc(MIMEType)
    Dim bytBuff As Byte() = New Byte(LFElecReadStream.Length - 1) {}
    LFElecReadStream.Read(bytBuff,0,CInt(bytBuff.Length))
    LFElecReadStream.Close()
    Dim MemStream As New MemoryStream()
    MemStream.SetLength(bytBuff.LongLength)
    MemStream.Seek(0, 0)
    MemStream.Write(bytBuff,0,CInt(bytBuff.Length))
    MemStream.Flush()
    '<<Modification Here>>
    
    ''Write
    Dim wordDoc As WordprocessingDocument = WordprocessingDocument.Open(objStream,True)
    using (wordDoc)
    Dim docText As String = Nothing
    Dim sr As StreamReader = New StreamReader(wordDoc.MainDocumentPart.GetStream)
    Do While sr.Peek() >= 0
        docText = docText + sr.ReadLine()
    Loop
    sr.Close()
    Dim regexText As Regex = New Regex(objInput)
    docText = regexText.Replace(docText, objReplace)

     ' *  Append Changes * '
    Dim sw As StreamWriter = New StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Open))
    sw.Write(docText)
    sw.Flush()
    sw.Close
    ???????????????

 


As previously said, my main concern is to  Append my changes to the electronic file.

Any help or hints suggestion would be greatly appreciated

 

Regards.
   

 

0 0

Replies

replied on June 23, 2014

Your RA code seems very different from the LFSO code. To write to the edoc using RA, you would do something like this:

Dim data() As Byte = mem.toarray()

Dim writeStream As Stream = doc.WriteEdoc("application/vnd.openxmlformats-officedocument.wordprocessingml.document", data.LongLength)
writeStream.Write(data, 0, data.LongLength)
writeStream.Close()

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.