howardseay
asked on
Creating a new document in vb.net using DM 5.1.05 API results in zero length file
Using the example from the API reference and modifying it for vb.net 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("%TARGE T_LIBRARY" , gszLibrary)
objDoc.SetDST(gszDst)
'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)
fs.Close()
objPutStream = Nothing
objDoc = Nothing
objDoc = New PCDCLIENTLib.PCDDocObject
objDoc.SetDST(gszDst)
objDoc.SetObjectType(gclsT emplate.DM Profile.To String)
objDoc.Update()
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.
***PROFILE FIELD VALUES OMITTED FOR EE POST***
Dim objPutDoc As PCDPutDoc
Set objPutDoc = CreateObject( _
"PCDClient.PCDPutDoc")
objPutDoc.SetDST DST
objPutDoc.NextRow
Dim objPutStream As Object
Set objPutStream = _
objPutDoc.GetPropertyValue ("%CONTENT ")
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
Else
TotalFileSize = TotalBytesWritten
End If
Get #1, , bdata
objPutStream.Write bdata, TotalBytesWritten
Debug.Print TotalBytesWritten, _
objPutStream.BytesWritten, _
objPutStream.ErrNumber, _
objPutStream.ErrDescriptio n
TotalBytesWritten = TotalFileSize - _
TotalBytesWritten
End If
Wend
objPutStream.SetComplete
Close #1
objDoc.Update
If objDoc.ErrNumber <> 0 Then
Debug.Print objDoc.ErrNumber, _
objDoc.ErrDescription
End If
Set objPutDoc = Nothing
Set objDoc = Nothing
Debug.Print "Upload completed!"
Thank you in advance.
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("%TARGE
objDoc.SetDST(gszDst)
'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
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)
fs.Close()
objPutStream = Nothing
objDoc = Nothing
objDoc = New PCDCLIENTLib.PCDDocObject
objDoc.SetDST(gszDst)
objDoc.SetObjectType(gclsT
objDoc.Update()
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.
***PROFILE FIELD VALUES OMITTED FOR EE POST***
Dim objPutDoc As PCDPutDoc
Set objPutDoc = CreateObject( _
"PCDClient.PCDPutDoc")
objPutDoc.SetDST DST
objPutDoc.NextRow
Dim objPutStream As Object
Set objPutStream = _
objPutDoc.GetPropertyValue
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
Else
TotalFileSize = TotalBytesWritten
End If
Get #1, , bdata
objPutStream.Write bdata, TotalBytesWritten
Debug.Print TotalBytesWritten, _
objPutStream.BytesWritten,
objPutStream.ErrNumber, _
objPutStream.ErrDescriptio
TotalBytesWritten = TotalFileSize - _
TotalBytesWritten
End If
Wend
objPutStream.SetComplete
Close #1
objDoc.Update
If objDoc.ErrNumber <> 0 Then
Debug.Print objDoc.ErrNumber, _
objDoc.ErrDescription
End If
Set objPutDoc = Nothing
Set objDoc = Nothing
Debug.Print "Upload completed!"
Thank you in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window