You are viewing limited content. For full access, please sign in.

Question

Question

Error Using FolderInfo.Create

SDK
asked on March 23, 2015

After crawling through a lot of threads, the consensus in the SDK Forums is that the TryGetEntryInfo method is the best way to see if a folder exists, and that FolderInfo.Create is the best way to create a folder if it does not.

So we have a situation where there is definitely a parent folder, and we want to create a single sub folder.

The line 

LF_FolderInfo = Entry.TryGetEntryInfo(sParentFolder, LF_Session)

Works fine, and populates the FolderInfo Object without any issue.

Logically, we'd then run:

LF_FolderInfo.Create((sParentFolder & sNewSubFolder), EntryNameOption.None)

 

where sParentFolder definitely ends with a slash, and sNewSubFolder definitely does not exist.

Not matter whether the folder creation code is in the same routine or we split it off to a different Sub, it always fails with the message, "Only new objects support this operation".  

The only way we've gotten this to work is via:

            Dim LF_FolderInfo As Laserfiche.RepositoryAccess.FolderInfo = Nothing
            LF_FolderInfo = Folder.GetFolderInfo(sParentFolder, LF_Session)
           Dim nRet As Integer = Folder.Create(sParentFolder & sNewSubFolder,     "Default",  EntryNameOption.None, LF_Session)

So are we missing something obvious?

TIA

 

0 0

Answer

SELECTED ANSWER
replied on March 23, 2015

Call FolderInfo create on a newly created FolderInfo object:

Dim sParentPath As String = "\\parentFolder\\"
Dim sChildFolderName As String = "New Folder"
Dim parentFolder As FolderInfo = Folder.GetFolderInfo(sParentPath, mySession) ' Verifies the parent exists
Dim newFolder As FolderInfo = New FolderInfo(mySession)
newFolder.Create(sParentPath & sChildFolderName, EntryNameOption.None)

 

1 0

Replies

replied on March 23, 2015

Bill - The following code snippet works on my system;

        Dim mySession As Session = New Session

        mySession.Connect(New RepositoryRegistration("SAMANTHA-PC", "LFMAIN"))
        mySession.LogIn("admin", "admin")

        Folder.Create("\TestFolder\SubFolder", "DEFAULT", EntryNameOption.AutoRename, mySession)

        mySession.LogOut()
        mySession.Close()

The folder 'TestFolder' resides in root of the repository and this code creates a folder called 'SubFolder' in 'TestFolder'.  Running the code again creates a subfolder called 'SubFolder (2)' in 'TestFolder'.

replied on March 24, 2015

Thanks, Robert -

So a FolderInfo instance cannot create a child folder, you need a second FolderInfo object for that. That explains the error message.  I'll give this a try. 

0 0
replied on March 24, 2015

That did the trick, and here's the final result, below.  In this case we 1) know that the parent exists, 2) want to check to see if a specific child folder exists under it, and 3) need to create the child if it does not exist.  (We don't need to run up and down n levels of an entire folder tree, fortunately.) The TryGetEntryInfo is a nice method to test for this, but requires the EntryInfo Object.  It would be nice if there were a TryGetFolderInfo method available in the FolderInfo Object, for the convenience and slightly lower performance cost.

            'LF Entry Info/Folder Info Objects
            Dim LF_EntryInfo As EntryInfo = Nothing
            Dim LF_ParentFolderInfo As FolderInfo = Nothing
            Dim LF_ChildFolderInfo As New FolderInfo(LF_Session)

            'We know the parent exists
            LF_ParentFolderInfo = Folder.GetFolderInfo(sParentFolder, LF_Session)
            LF_EntryInfo = Entry.TryGetEntryInfo(LF_ParentFolderInfo, sNewSubFolder, LF_Session)
            'Check the results
            If IsNothing(LF_EntryInfo) Then
                'Create the Child Folder
                LF_ChildFolderInfo.Create(sParentFolder & sNewSubFolder, EntryNameOption.None)
            Else
                'It's already there
                CheckFolder = True
            End If

            'Clean Up
            LF_ParentFolderInfo.Dispose()
            LF_ChildFolderInfo.Dispose()
            If Not IsNothing(LF_EntryInfo) Then
                LF_EntryInfo.Dispose()
            End If

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.