Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

iDocument.ReplaceFile Method - not working?!?

It seems like the ReplaceFile method no longer works as intended - or as it used to.

I have had it working an update ago (from 7.5 to 8.4) but only found out lately.

I tried the example script with a few changes. The document is created in SuperOffice but replacing the content does not happen. Has anything changed or is there another way to replace the content of created files?

Dim objApp, soDoc, soDB

Set objApp = CreateObject("SuperOffice.Application")
Set soDB = objApp.Database

Set soDoc = soDB.CreateDocument
soDoc.Contact = soDB.GetContact(90)
soDoc.Project = soDB.GetProject (1619)
soDoc.Template = soDB.GetListItem(130, 59)

soDoc.Header = "Added though SuperCOM 6"

MsgBox "Check for the added document with header Added through SuperCOM, try to open." & vbCrLf & "It fails since we have not yet created a document file."

soDoc.ReplaceFile "C:\Users\pomu\Documents\04 SuperOffice Udvikling\23 Scripts\Test1.docx", False


MsgBox "Now try to open the file"

soDoc.ReplaceFile "C:\Users\pomu\Documents\04 SuperOffice Udvikling\23 Scripts\Test2.docx", False

MsgBox "Now try to open the file, verify that the text is replaced."

Thanks in anticipation for any clarifications


RE: iDocument.ReplaceFile Method - not working?!?

Just found out that ReplaceFile does exactly the opposite!

The content of the file stored on the harddrive is replaced by the content of the file created in SuperOffice...

Is there a possibility to change the direction by using some undocumented parameter?


Af: Peter Munk 21. nov 2019

RE: iDocument.ReplaceFile Method - not working?!?

Hi Peter,

Unless I misunderstand, your situation appears to meet the last documented scenario:

ReplaceFile - archive the file provided and update record if necessary, or replace contents of existing file with same name, or

There are three different scenarios:

  • The document record exists but filename is empty. The file is saved and the document record is updated with files name

  • The document record exists but not the file. File is saved with name from document record.

  • The document record and file exists. If the content of the files differs the existing content is replaced.

Af: Tony Yates 21. nov 2019

RE: iDocument.ReplaceFile Method - not working?!?

The following is what I expect and is how the method has worked before and which I believe is also the intention:

  • I have a file which is not archived in SO for example: Test1.Docx
  • I create a document in SO database - could be based on some existing template
  • I then use ReplaceFile to copy the content of Test1.Docx into the just created document in SO

What happens is that the content of Test1.Docx instead is replaced by the content of the document created in SO.

I only found out because I used a Word template (with letterhead and fields) when creating the entry in SO and to my surprice found out that Test1.Docx now was replaced with the document from SO.

If I try with no template the file in SO obviously not created. But the filename (in the database) is created and somehow based on the last template which has been in use directly from SO, but does not exist even after the ReplaceFile method has been run. The document Test1.Docx remains untouched in this case.

The version of SO is: 8.4.6915.14 if that helps tracing this behavior.

Af: Peter Munk 21. nov 2019

HiRE: iDocument.ReplaceFile Method - not working?!?

we are looking into this.
Looks like the direction might have been mixed up when we did away with our classic docplugin and moved to the netserver plugin. This was introduced in 8.0 towards end of 2014.

tfs 68378



Af: Conrad Weyns 22. nov 2019

RE: iDocument.ReplaceFile Method - not working?!?

Thanks Conrad,

Hopefully no one has used this method to copy critical original documents into SuperOffice...

...or used the last argument (TRUE) for deleting the original file after copy.

Af: Peter Munk 22. nov 2019

RE: iDocument.ReplaceFile Method - not working?!?

Hi Peter,
Yes,.what can I say?
Seemed like a good idea back then to use the netserver docplugin but I think it cost much more then anyone could predict.

You are the first one to report this. Shows that Win clients do not upgrade very often or that much of the COM API is never used.

In April 2017, I added the following to IDatabase (some one wanted this badly - can't remember who).
Might be in your 8.4, not sure though!


Function AddDocumentForAssociate(ByVal i_FilePath As String, ByVal i_RemoveOriginal As Boolean, ByVal i_OpenCreatedDocument As Boolean, ByVal i_AssociateId As Long, ByVal i_ContactId As Long, ByVal i_PersonId As Long, ByVal i_ProjectId As Long) As IDocument

Add an existing file to the document archive on behalf of some associate, returning a new document object for the file.


This simple vb script example works for me in our latest 8.5:

Set app = CreateObject( "SuperOffice.Application" )
If Not app Is Nothing Then
    Set db = app.Database
    assocId = 106
    contactId = 175
    personId = 63664
    projectId = 0
    Set doc = db.AddDocumentForAssociate( "D:\AddThisDoc1.txt", vbFalse, vbFalse, assocId, contactId, personId, projectId )
  ­  WScript.Echo doc.filename
    WScript.Echo "Error getting application object"
End If


We will try and look into ReplaceFile for the next release which I think should be 8.5 R08..


Af: Conrad Weyns 22. nov 2019

RE: iDocument.ReplaceFile Method - not working?!?

Hi Conrad,

Thanks a million!

Works perfect ;o)

Af: Peter Munk 22. nov 2019