A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Unable to Delete Folders from "Deleted Item" Folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 28th 07, 08:18 AM posted to microsoft.public.outlook.program_vba
[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
  #2  
Old December 28th 07, 03:34 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Unable to Delete Folders from "Deleted Item" Folder

Please do no multipost. If you really need to post to more than 1 group do
so in one post.

For Outlook 2007 you should use Folder and not MAPIFolder, BTW.

I'm assuming that if you use the user interface that you actually can delete
the folder that was deleted.

Do you get a valid tempFolder object?

Does it work any better if you frst release Folder then try to delete
tempFolder?

By release I mean calling Marshal.ReleaseComObject(Folder) and then calling
GC.Collect() and then GC.WaitForPendingFinalizers() before calling the
GetSubFolder() method.

If there was more than one folder to be deleted a For Each loop is not the
way to go. A down counting For loop should be used instead.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


wrote in message
...
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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Delete Folders from Outlook 2007 "Deleted Items" Folder. [email protected] Outlook and VBA 0 December 27th 07 03:38 PM
How to Delete Folders from Outlook 2007 "Deleted Items" Folder. [email protected] Add-ins for Outlook 0 December 27th 07 03:34 PM
PST views - Can I hide "Search Folders" and "Deleted Items"? Rob Outlook - General Queries 1 August 25th 06 08:41 PM
Two "Personal Folders" in my "Folder List" jaygreg Outlook - Using Contacts 2 August 24th 06 12:13 AM
"Unable to Display the Folder" msg, can't delete folder Yvonne Outlook - Calandaring 2 March 29th 06 09:01 PM


All times are GMT +1. The time now is 08:17 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.