Creating a new document in using DM 5.1.05 API results in zero length file

Posted on 2007-11-14
Last Modified: 2010-08-05
Using the example from the API reference and modifying it for from vb6, i am creating a new document in DM.  The result is that no error is thrown, the document does get created but the version of the document in DM is 0 length.  Trapping the "TotalBytesWritten" return value also reveals that no bytes were written.  The errDescription and errNumber both are OK.

Here is my VB.Net code

        Dim DocNumber As Long
        Dim VersionID As Long
        Dim TotalFileSize As Long
        Dim TotalBytesWritten As Long
        Dim szErr As String
        Dim bdata() As Byte
        Dim objDoc As New PCDCLIENTLib.PCDDocObject
        objDoc.SetProperty("%TARGET_LIBRARY", gszLibrary)
        'Set the Profile Form for this document.
**code that sets the profile field values purposely omitted from ee post ***    

    Dim objPutStream As New Object
        objPutStream = objPutDoc.GetPropertyValue("%CONTENT")
        Dim FileName
        FileName = "C:\Test\005.doc"
        Dim fs As FileStream = File.Open(FileName, FileMode.Open, FileAccess.Read)
        Dim r As BinaryReader = New BinaryReader(fs)
        Dim bytesToWrite As Integer

        'FileOpen(1, FileName, OpenMode.Binary, OpenAccess.Read, OpenShare.LockRead, bdata.Length)
         TotalFileSize = fs.Length
        TotalBytesWritten = 0
        Me.lblImportProgress.Text = "Uploading Image: " & FileName
        bdata = r.ReadBytes(TotalFileSize)
        objPutStream.Write(bdata, TotalBytesWritten)
        objPutStream = Nothing
        objDoc = Nothing
        objDoc = New PCDCLIENTLib.PCDDocObject

The code example from the api reference used the OPEN and GET methods.
Here is the crux of the writing portion from the example:

Dim DocNumber As Long
Dim VersionID As Long
Dim TotalFileSize As Long
Dim TotalBytesWritten As Long
Dim Buffread As Long
'Set bdata ridiculously low for test purposes
'to increase the likelihood of corruption.
Dim bdata(16) As Byte
Dim objDoc As PCDDocObject
Set objDoc = New PCDDocObject
objDoc.SetProperty "%TARGET_LIBRARY", Library
objDoc.SetDST DST
'Set the Profile Form for this document.
Dim objPutDoc As PCDPutDoc
Set objPutDoc = CreateObject( _
objPutDoc.SetDST DST

Dim objPutStream As Object
Set objPutStream = _
Dim FileName
FileName = txtFileName.Text

Open FileName For Binary Access Read As #1
TotalFileSize = LOF(1)
While (Not EOF(1))
TotalBytesWritten = TotalFileSize
If TotalBytesWritten > 0 Then

If (TotalBytesWritten > UBound(bdata)) Then

TotalBytesWritten = UBound(bdata) + 1


TotalFileSize = TotalBytesWritten
End If

Get #1, , bdata
objPutStream.Write bdata, TotalBytesWritten
Debug.Print TotalBytesWritten, _
objPutStream.BytesWritten, _
objPutStream.ErrNumber, _
TotalBytesWritten = TotalFileSize - _
End If


Close #1
If objDoc.ErrNumber <> 0 Then
Debug.Print objDoc.ErrNumber, _
End If
Set objPutDoc = Nothing
Set objDoc = Nothing
Debug.Print "Upload completed!"

Thank you in advance.

Question by:howardseay

Author Comment

ID: 20287228
I finally figured it out.  There were a few things wrong.  Here is the corrected block of code.

        Dim FileName
        FileName = "P:\Projects\COH_DIM\images\005.doc"
        Dim fs As FileStream = File.Open(FileName, FileMode.Open, FileAccess.Read)
        Dim breader As BinaryReader = New BinaryReader(fs)
        Dim bdata(1024) As Byte
        TotalFileSize = fs.Length
        Dim bytesToWrite As Integer
        bytesToWrite = 1024
        Dim lStart As Long
        Dim lLength As Long
        lStart = 0
        lLength = 1024
            breader.Read(bdata, 0, lLength)
            objPutStream.Write(bdata, lLength)
            If lStart = TotalFileSize Then Exit Do
            If lStart + 1024 > TotalFileSize Then
                lLength = TotalFileSize - lStart - 1
            End If
            lStart = lStart + lLength + 1

Open in new window


Accepted Solution

EE_AutoDeleter earned 0 total points
ID: 20968295
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 97
listing all functions in JavaScript 19 203
Regular Expression Calculator Tester 2 74
Selenium docs api java index 3 18
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question