Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Deleting Folders - Operation is not Allowed
DavidBLP
Hi,
I am trying to write a VB.NET function to delete a folder from Worksite based on the folder id and database. I am creating a session as the user who created the folder and so has full rights to it however I always get the message "The Operation is not allowed" when trying to delete the folder. This also happens as Administrator. My function is as below.
Public Function DeleteByFolderID(ByVal lID As Int32, ByVal sDatabase As String)
Dim oWorkArea As IManWorkArea
Dim colDBs As ManStrings
Dim fld As IManFolder
colDBs = New ManStrings
'Add the databases we should be searching in
colDBs.Add(sDatabase)
'We will use the work area for the user.
oWorkArea = _IWSession.WorkArea
'Create our search parameters. This is the folder id
Dim folderparams As IManFolderSearchParameters = _dms.CreateFolderSearchParameters()
folderparams.Add(imFolderAttributeID.imFolderID, lID)
'Run our search
Dim retFolders As IManFolders = oWorkArea.SearchFolders(colDBs, folderparams)
'this should only be 1 folder
If retFolders.Count = 0 Then
Throw New Exception("No Folders Found with ID: " & lID.ToString & " in database " & sDatabase)
End If
If retFolders.Count > 1 Then
Throw New Exception("More than one Folders Found with ID: " & lID.ToString & " in database " & sDatabase)
End If
'Check the correct folder is found
MessageBox.Show(retFolders.ItemByIndex(1).Name)
'This returns false
MessageBox.Show(retFolders.IsOperationAllowed(imFoldersOp.imRemoveFoldersOp))
'This creates an exception The operation is not allowed
retFolders.RemoveByIndex(1)
End Function
Is there a problem with the code or is there any way I can tell why the folder cannot be deleted? Logged in as the user in Desksite allows me to delete the folder.
Many thanks for your help.
Regards
David
Find more posts tagged with
Comments
jny
This is because you're attempting to remove the folder from the results collection. You need to remove it from the folder's parent's folder collection.
That is, if the target folder belongs to a workspace, then you would need to remove it from the workspace's documentfolder collection, like so:
' Get target folder to remove
Dim targetfldr As IManDocumentFolder = retFolders.ItemByIndex(1)
' Assuming that the ws is a valid pointer to the workspace object
Dim wsFldrs As IManDocumentFolders = ws.DocumentFolders
This should now return True
MessageBox.Show(wsFldrs.IsOperationAllowed(imFo ldersOp.imRemoveFoldersOp))
wsFldrs.RemoveByObject(targetfldr)
'Or,
wsFldrs.RemoveByIndex(1) 'Assuming that the first folder is the target.
Or, if the target folder is the parent, then get the root.subfolders. If, however, the folder is a child folder, then get the parent's document folder collection. Like so:
Dim fldrs As IManDocumentFolders
If targetfldr.Parent Is Nothing Then
' target is the parent
fldrs = targetfldr.Database.Root.SubFolders
Else
' get parent's folder collection
fldrs = fldr.Parent.SubFolders
End If
' This should now return True
MessageBox.Show(fldrs.IsOperationAllowed(imFo ldersOp.imRemoveFoldersOp))
fldrs.RemoveByObject(targetfldr)
' Or,
'fldrs.RemoveByIndex(1)