View Single Post
  #1  
Old December 28th 07, 07:17 AM posted to microsoft.public.outlook.program_addins
[email protected]
external usenet poster
 
Posts: 4
Default Unable to Delete Folders from "Deleted Item" Folder

Hi, all

I'm trying to delete folders from the "Deleted Items" folder. I'm
using the below snippet. The "Deleted Items" folder also contains some
custom folders, which I'm not able to clear.


I am working with VSTO-SE in vb.net With Outlook 2007.

Plz reply me the solution.

*********************** Error Details ****************************
System.Runtime.InteropServices.COMException was caught
ErrorCode=-2147352567
Message="Cannot delete this folder. Right-click the folder, and then
click Properties to check your permissions for the folder. See the
folder owner or your administrator to change your permissions."
Source="Microsoft Office Outlook"
StackTrace:
at Microsoft.Office.Interop.Outlook.MAPIFolder.Delete ()
at
FileMounter.FileMounter.Installhelper.RemoveMyFold er(Application
application, String folderName) in D:\Development\Project\For Office
2007\25-12-2007\FileMounter\Classes\InstallHelper.vb:line 47

*********************Error Details End *******************************



This is my code snippet for deleting the folders from "Deleted Item"
Folder.

''' summary
''' This Function Remove MyFolder from our Session.
''' /summary
''' param name="application"/param
''' param name="folderName"/param
''' returns/returns
''' remarks/remarks
Public Function RemoveMyFolder(ByVal application As
Outlook.Application, Optional ByVal folderName As String = "MyFolder")
As Boolean
Dim tempStr As String = ""
Dim tempFolder As Outlook.MAPIFolder = Nothing
Try
For Each Folder As Outlook.MAPIFolder In
application.Session.GetDefaultFolder(Outlook.OlDef aultFolders.olFolderInbox).Parent.Folders
If Folder.Name = folderName.Trim Then
Folder.Delete()
tempStr = Folder.Name
'Releasing the Folder After Delete
Folder = Nothing
tempFolder = GetSubFolder(tempStr,
application.Session.GetDefaultFolder(Outlook.OlDef aultFolders.olFolderDeletedItems))
If tempFolder IsNot Nothing Then
tempFolder.Delete()
Return True
End If
Next
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
tempFolder = Nothing
End Function
''' summary
''' This Function gets the Subfolder from the given
ParentFolder.
''' Used to avoid Exceptions when Folder doesn't exists.
''' /summary
''' param name="folderName"The name of the Folder to
retrieve./param
''' param name="parentFolder"The Parent MAPIFolder Object./
param
''' returnsThe Subfolder Object or null./returns
Private Function GetSubFolder(ByVal folderName As String,
ByVal parentFolder As Outlook.MAPIFolder) As Outlook.MAPIFolder
Dim subFolder As Outlook.MAPIFolder
For index As Integer = parentFolder.Folders.Count To 1
Step -1
subFolder = parentFolder.Folders(index)
If subFolder.Name = folderName Then
Return subFolder
End If
Next
subFolder = Nothing
Return Nothing
End Function
Ads