HighTechTalks DotNet Forums  

How to Search Emails in PST root Folder in Outlook 2007 using Outl

Visual Studio.net (Tools Office) microsoft.public.vsnet.vstools.office


Discuss How to Search Emails in PST root Folder in Outlook 2007 using Outl in the Visual Studio.net (Tools Office) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Kolan Veera Reddy
 
Posts: n/a

Default How to Search Emails in PST root Folder in Outlook 2007 using Outl - 10-23-2007 , 04:07 AM






How can I search emails in PST root folder..? Which folder name I have to
pass to the AdvancedSearch method to get the emails from PST root folder..?

The following sample code uses the AdvancedSearch method to create a new
search that returns all the items in a PST folder that are marked with high
importance. If the FolderPath property of the folder contains spaces, use
double quotes and single quotes when you set the search filter

("'\PSTFolder\PST SubFolder'", for example). If the FolderPath property of
the folder does not contain spaces, you can omit the single quotes.

Sub SearchPSTFolder()
Dim objSch As Search
Dim strF As String
Dim strS As String
Dim strTag As String
'TODO: Change "\PSTFolder\PST SubFolder" to the PST's FolderPath
'property while omitting the first \
strS = "'\PSTFolder\PST SubFolder'"
'TODO: replace ; with :
strF = "urn;schemas:httpmail;importance = 2"
strTag = "ImportanceSearch"
objSch = objOL.AdvancedSearch(strS, strF, False, strTag)
End Sub

It is not searching the emails from PST root folder it is searching mails
only from PST sub folder.

Thanks in Advance...!
---------------------
Kolan Veera Reddy

Reply With Quote
  #2  
Old   
Ken Slovak - [MVP - Outlook]
 
Posts: n/a

Default Re: How to Search Emails in PST root Folder in Outlook 2007 using Outl - 10-23-2007 , 10:03 AM






The Root folder is not available to the Outlook object model except in
Outlook 2007. In any case to search folders from one folder to all its
subfolders you need to set the SearchSubfolders argument to True, not to
False.

You can list all the top level folders such as 'Inbox', "Sent Items', etc.
and put those in your search string and set the subfolders search on and get
all folders that way.

--
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


"Kolan Veera Reddy" <KolanVeeraReddy (AT) discussions (DOT) microsoft.com> wrote in
message news:FD1453D8-E6F1-461C-BD2C-3B79716CA27E (AT) microsoft (DOT) com...
Quote:
How can I search emails in PST root folder..? Which folder name I have to
pass to the AdvancedSearch method to get the emails from PST root
folder..?

The following sample code uses the AdvancedSearch method to create a new
search that returns all the items in a PST folder that are marked with
high
importance. If the FolderPath property of the folder contains spaces, use
double quotes and single quotes when you set the search filter

("'\PSTFolder\PST SubFolder'", for example). If the FolderPath property of
the folder does not contain spaces, you can omit the single quotes.

Sub SearchPSTFolder()
Dim objSch As Search
Dim strF As String
Dim strS As String
Dim strTag As String
'TODO: Change "\PSTFolder\PST SubFolder" to the PST's FolderPath
'property while omitting the first \
strS = "'\PSTFolder\PST SubFolder'"
'TODO: replace ; with :
strF = "urn;schemas:httpmail;importance = 2"
strTag = "ImportanceSearch"
objSch = objOL.AdvancedSearch(strS, strF, False, strTag)
End Sub

It is not searching the emails from PST root folder it is searching mails
only from PST sub folder.

Thanks in Advance...!
---------------------
Kolan Veera Reddy


Reply With Quote
  #3  
Old   
Kolan Veera Reddy
 
Posts: n/a

Default Re: How to Search Emails in PST root Folder in Outlook 2007 using - 10-23-2007 , 12:13 PM



Hi Slovak,

Thanks for your reply,

I am using Outlook 2007, In the first post code, i have mentioned False to
AdvanceSearch method, actually it is True. For better understanding I am
adding some more points.

I have created a search object using AdvancedSearch method in outlook object
model and saved the search results to "Demo Search" Folder. Please refer the
below code.


Public Sub Create_SearchFolder(ByVal strRootFolderName As String)
'strRootFolderName is my PST Folder path it
‘contains "\\DemoFolders" ''''''path of PST file''''''
If Not strRootFolderName Is Nothing Then
Dim olApp As New Outlook.Application
Dim objSch As Microsoft.Office.Interop.Outlook.Search
'Search Query

Dim strF As String
'Scope which it is going to search.
Dim strS As String
Try
Dim olSearchFolder As Outlook.MAPIFolder
'Here I am passing strRootFolderName it
‘contains "\\DemoFolders"
'strS = "\\DemoFolders"
strS = strRootFolderName
Dim strTag As String
'MySearch is the tag for the Search
strTag = "MySearch"
'Search query to search the mails which contains
strF = "urn:schemas:mailheader:subject = 'Test'"
objSch = olApp.AdvancedSearch(strS, strF, True, strTag)
'I am saving the search results to "Demo Search"
‘folder inside search folders
olSearchFolder = objSch.Save("Demo Search")
Catch ex As System.Exception
Throw
End Try
End If
End Sub

Instead of strS = "’\\DemoFolders’", if I pass strS = "’MyFolder’" or 'strS
= "’Inbox’,'MyFolder1','MyFolder2'" the ’MyFolder1’ and ‘MyFolder2’ are
subfolders inside ‘\\Demo Folders’ PST folder. It is working fine and
creating "Demo Search" search folder Success fully. It is not creating the
search folder for ‘\\Demo Folders'. I need to search the emails in ‘\\Demo
Folders’ Root.

I have crated a Custom Search Folder using Out of the box properties. It is
created search folder successfully and I am able to see the mails in root
folder of PST folder. The folder which is named as "Top of Personal Folders"
If I pass "’Top of Personal Folders’" to the search method strS = "’Top of
Personal Folders’" Search method is throwing exception.

I am able to search emails in all subfolders inside the PST folder except in
PST root.

The PST root is named with "Top of Personal Folders". I am not able to pass
the same to search method.

How can I search emails in PST root folder..? Which folder name I have to
pass to the AdvancedSearch method to get the emails from PST root
folder..?
--
Kolan Veera Reddy


"Ken Slovak - [MVP - Outlook]" wrote:

Quote:
The Root folder is not available to the Outlook object model except in
Outlook 2007. In any case to search folders from one folder to all its
subfolders you need to set the SearchSubfolders argument to True, not to
False.

You can list all the top level folders such as 'Inbox', "Sent Items', etc.
and put those in your search string and set the subfolders search on and get
all folders that way.

--
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


"Kolan Veera Reddy" <KolanVeeraReddy (AT) discussions (DOT) microsoft.com> wrote in
message news:FD1453D8-E6F1-461C-BD2C-3B79716CA27E (AT) microsoft (DOT) com...
How can I search emails in PST root folder..? Which folder name I have to
pass to the AdvancedSearch method to get the emails from PST root
folder..?

The following sample code uses the AdvancedSearch method to create a new
search that returns all the items in a PST folder that are marked with
high
importance. If the FolderPath property of the folder contains spaces, use
double quotes and single quotes when you set the search filter

("'\PSTFolder\PST SubFolder'", for example). If the FolderPath property of
the folder does not contain spaces, you can omit the single quotes.

Sub SearchPSTFolder()
Dim objSch As Search
Dim strF As String
Dim strS As String
Dim strTag As String
'TODO: Change "\PSTFolder\PST SubFolder" to the PST's FolderPath
'property while omitting the first \
strS = "'\PSTFolder\PST SubFolder'"
'TODO: replace ; with :
strF = "urn;schemas:httpmail;importance = 2"
strTag = "ImportanceSearch"
objSch = objOL.AdvancedSearch(strS, strF, False, strTag)
End Sub

It is not searching the emails from PST root folder it is searching mails
only from PST sub folder.

Thanks in Advance...!
---------------------
Kolan Veera Reddy



Reply With Quote
  #4  
Old   
Ken Slovak - [MVP - Outlook]
 
Posts: n/a

Default Re: How to Search Emails in PST root Folder in Outlook 2007 using - 10-24-2007 , 09:19 AM



You would have to get the folder as a folder probably by iterating the
NameSpace.Folders collection. Each Folder returned as a member of that
collection is the top of personal folders, which technically is completely
different than the root folder. Once you have the folder you want use
FolderPath to get its folder path to use in the search criteria.

--
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


"Kolan Veera Reddy" <KolanVeeraReddy (AT) discussions (DOT) microsoft.com> wrote in
message news:1FEE46FF-190E-4F72-9111-2FF41649976E (AT) microsoft (DOT) com...
Quote:
Hi Slovak,

Thanks for your reply,

I am using Outlook 2007, In the first post code, i have mentioned False to
AdvanceSearch method, actually it is True. For better understanding I am
adding some more points.

I have created a search object using AdvancedSearch method in outlook
object
model and saved the search results to "Demo Search" Folder. Please refer
the
below code.


Public Sub Create_SearchFolder(ByVal strRootFolderName As String)
'strRootFolderName is my PST Folder path it
‘contains "\\DemoFolders" ''''''path of PST file''''''
If Not strRootFolderName Is Nothing Then
Dim olApp As New Outlook.Application
Dim objSch As Microsoft.Office.Interop.Outlook.Search
'Search Query

Dim strF As String
'Scope which it is going to search.
Dim strS As String
Try
Dim olSearchFolder As Outlook.MAPIFolder
'Here I am passing strRootFolderName it
‘contains "\\DemoFolders"
'strS = "\\DemoFolders"
strS = strRootFolderName
Dim strTag As String
'MySearch is the tag for the Search
strTag = "MySearch"
'Search query to search the mails which contains
strF = "urn:schemas:mailheader:subject = 'Test'"
objSch = olApp.AdvancedSearch(strS, strF, True, strTag)
'I am saving the search results to "Demo Search"
‘folder inside search folders
olSearchFolder = objSch.Save("Demo Search")
Catch ex As System.Exception
Throw
End Try
End If
End Sub

Instead of strS = "’\\DemoFolders’", if I pass strS = "’MyFolder’" or
'strS
= "’Inbox’,'MyFolder1','MyFolder2'" the ’MyFolder1’ and ‘MyFolder2’ are
subfolders inside ‘\\Demo Folders’ PST folder. It is working fine and
creating "Demo Search" search folder Success fully. It is not creating the
search folder for ‘\\Demo Folders'. I need to search the emails in
‘\\Demo
Folders’ Root.

I have crated a Custom Search Folder using Out of the box properties. It
is
created search folder successfully and I am able to see the mails in root
folder of PST folder. The folder which is named as "Top of Personal
Folders"
If I pass "’Top of Personal Folders’" to the search method strS = "’Top of
Personal Folders’" Search method is throwing exception.

I am able to search emails in all subfolders inside the PST folder except
in
PST root.

The PST root is named with "Top of Personal Folders". I am not able to
pass
the same to search method.

How can I search emails in PST root folder..? Which folder name I have to
pass to the AdvancedSearch method to get the emails from PST root
folder..?
--
Kolan Veera Reddy


Reply With Quote
Reply




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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.