This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Removing file and FileVer parameter

Former Member
Former Member
I'm in dire straits in using some API features.
My software exports pdf files and put them in a vault. These file can be created in a single or multi file document (and this works fine).
If a file is exported more times, I should replace the file and put the new file.
Now, I tried to do this:
- destroy the document and re-create it (but I don't know why this doesn't work - see this post http://community.m-files.com/index.php?topic=1147.0)
- check-out the document, remove the file and put the new file in this way


Set oResults = oVault.ObjectSearchOperations.SearchForObjectsByConditions(arrCondizioni, MFilesAPI.MFSearchFlags.MFSearchFlagNone, False)
If oResults.Count > 0 Then
    oVault.ObjectOperations.CheckOut oResults(1).ObjVer.ObjID

    Dim objVersion As MFilesAPI.ObjVer
    Set objVersion = New ObjVer
    objVersion.SetObjIDAndVersion oResults(1).ObjVer.ObjID, CLng(oResults(1).ObjVer.Version) + 1

    oVault.ObjectFileOperations.RemoveFile objVersion, oResults(1).Files(1).FileVer
    oVault.ObjectFileOperations.AddFile objVersion, GetFileName(pathFile), "pdf", pathFile

[...]


When I call the ".RemoveFile" method, it throws an error saying "Not found."... I think that the way I set FileVer parameter is not correct... I didn't found informations about using FileVer...

Also, if the document is a "Single file document". the ".RemoveFile" throws an error saying that I can't remove a file from a single-file document... so, how can I replace this file?

If somebody can help me, I will be very grateful!!!
Thank you very much.

davides


  • Former Member
    Former Member
    Well... any answer... but I finally find this solution (I hope is right...)

    after having checked-out the document

    oVault.ObjectOperations.CheckOut oResults(1).ObjVer.ObjID


    I set "FileVer" parameter in this way


    Dim objVersion As MFilesAPI.ObjVer
    Set objVersion = New ObjVer
    Set objVersion = oVault.ObjectOperations.GetLatestObjVer(oResults(1).ObjVer.ObjID, True)

    Dim fVer As FileVer
    Set fVer = New FileVer
    If singleDocument Then
    fVer.ID = oResults(1).Files(1).FileVer.ID
    Else
    fVer.ID = oResults(1).Files.GetObjectFileByNameForFileSystem(myFileName & ".pdf").FileVer.ID
    End If
    fVer.Version = -1



    Now I can remove the file from the multiple document (if it's a "single document" then I proceeded to convert the document to "multiple", I removed the file, then I added the new file and re-converted to "single document")


    If singleDocument Then oVault.ObjectOperations.SetSingleFileObject objVersion, False

    oVault.ObjectFileOperations.RemoveFile objVersion, fVer
    oVault.ObjectFileOperations.AddFile objVersion, myFileName, "pdf", myFilePath

    If singleDocument Then oVault.ObjectOperations.SetSingleFileObject objVersion, True


    This works fine. There would be another way?
    Bye

    davides
  • Former Member
    Former Member
    I have same error when I try to remove a file, I got error single file document.

    How can we remove a single file document? Without the need to convert it to multi files document.

    Best regards,