• Clone File Resource

    By Rob Mellinger 8 years ago

    If anyone needs to clone an existing file resource and rename it, you can use this additional function, which is basically FindFileResource plus making a copy of the found resource and renaming it:

    %REM

    Function CloneFileResource
    Description: Updated from FindFileResource to make a copy of an existing one. 
        Search a database for a design element of a given name and type
        (type being, for instance, "xpage" or "fileresource"). Once that design element has 
        been found, make a copy and update the $Title and $FileName field. This is only 
        suitable for design elements of the type that contain binary-encoded file data,
        which is usually but not always in an item named $FileData.
        NOTE: This has the same drawback as NotesDatabase.GetView and the
        like, in that if there are multiple design elements with the same
        name you will only find one of them. It may be better to use
        NotesNoteCollection to locate the design elements yourself and
        call MakeFileResource instead.
    

    %END REM
    Function CloneFileResource(db As NotesDatabase, ByVal resType$, ByVal resName$, ByVal resNameNew$) As FileResource

    Dim nnc As NotesNoteCollection, session As New NotesSession
    Set nnc = db.Createnotecollection(false)
    SetSelectionExt nnc, resType, "*" & resName, 1
    nnc.Buildcollection
    If nnc.Count Then
        Dim docDes As NotesDocument
        Dim docNew As NotesDocument
        Dim docNewTitle As NotesItem, docNewName As NotesItem
        Set docDes = db.Getdocumentbyid(nnc.Getfirstnoteid)
        Set docNew = docDes.Copytodatabase(db)
        Set docNewTitle = docNew.Getfirstitem("$TITLE")
        Set docNewName = docNew.Getfirstitem("$FileNames")
        docNewTitle.Issummary = False
        docNewName.Issummary = False
        docNewTitle.Values = resNameNew$
        docNewName.Values = resNameNew$
        Call docNew.Save(True, False, False)
        Set CloneFileResource = MakeFileResource(docNew)
        Delete docNew
        Delete docDes
    End If
    

    End Function

    • By Rob Mellinger 8 years ago

      update, you don't need (nor want) those two Issummary flags reset…