本文整理汇总了C#中ExchangeService.FindFolders方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.FindFolders方法的具体用法?C# ExchangeService.FindFolders怎么用?C# ExchangeService.FindFolders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExchangeService
的用法示例。
在下文中一共展示了ExchangeService.FindFolders方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindFolder
/// <summary>
/// Return the FolderID of a sub-folder within a given parent folder.
/// </summary>
/// <param name="WebService">Exchange Web Service instance to use</param>
/// <param name="BaseFolderId">FolderID of the prent folder</param>
/// <param name="FolderName">Name of the folder to find</param>
/// <returns>FolderID of the matching folder (or null if not found)</returns>
public static FolderId FindFolder(ExchangeService WebService, FolderId BaseFolderId, string FolderName)
{
// Retrieve a list of folders (paged by 10)
FolderView folderView = new FolderView(10, 0);
// Set base point of offset.
folderView.OffsetBasePoint = OffsetBasePoint.Beginning;
// Set the properties that will be loaded on returned items (display namme & folder ID)
folderView.PropertySet = new PropertySet(FolderSchema.DisplayName, FolderSchema.Id);
FindFoldersResults folderResults;
do
{
// Get the folder at the base level.
folderResults = WebService.FindFolders(BaseFolderId, folderView);
// Iterate over the folders, until we find one that matches what we're looking for.
foreach (Folder folder in folderResults)
{
// Found it - return
if (String.Compare(folder.DisplayName, FolderName, StringComparison.OrdinalIgnoreCase) == 0)
{
return folder.Id;
}
}
// If there's more folders, get them ...
if (folderResults.NextPageOffset.HasValue)
{
folderView.Offset = folderResults.NextPageOffset.Value;
}
}
while (folderResults.MoreAvailable);
// If we got here, we didn't find it, so return null.
return null;
}
示例2: GetSourceFolder
private static Folder GetSourceFolder(ExchangeService service, EmailAddress email)
{
log4net.Config.XmlConfigurator.Configure();
// Use the following search filter to get all mail in the Inbox with the word "extended" in the subject line.
SearchFilter searchCriteria = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
//Search for Folder DisplayName that matches mailbox email address:
new SearchFilter.IsEqualTo(FolderSchema.DisplayName, email.Address));
// Find the search folder named "MailModder".
FindFoldersResults findResults = service.FindFolders(
WellKnownFolderName.Inbox,
searchCriteria,
new FolderView(50));
//Return root of inbox by default:
Folder returnFolder = Folder.Bind(service, WellKnownFolderName.Inbox);
foreach (Folder searchFolder in findResults.Folders)
{
if (searchFolder.DisplayName == email.Address)
{
returnFolder = searchFolder;
}
}
return returnFolder;
}
示例3: GetMailItemByExtendedProperty
/// <summary>
/// This function gets the mail item by the extended property
/// </summary>
/// <param name="service"></param>
/// <param name="folderId"></param>
/// <param name="msgFolderRootId"></param>
/// <param name="outlookMsgId"></param>
/// <param name="isIn"></param>
/// <returns></returns>
public object GetMailItemByExtendedProperty(ref ExchangeService service, FolderId folderId,
FolderId msgFolderRootId, string outlookMsgId, bool isIn)
{
EmailMessage message = null;
//Folder view
var viewFolders = new FolderView(int.MaxValue)
{
Traversal = FolderTraversal.Deep,
PropertySet = new PropertySet(BasePropertySet.IdOnly)
};
//email view
var viewEmails = new ItemView(int.MaxValue) { PropertySet = new PropertySet(BasePropertySet.IdOnly) };
//email filter
SearchFilter emailFilter =
new SearchFilter.IsEqualTo(
isIn
? MailboxExtendedPropertyDefinitionInbox
: MailboxExtendedPropertyDefinitionSent, outlookMsgId);
//search item in default folder
var findResults = service.FindItems(msgFolderRootId, emailFilter, viewEmails);
//check
if ((findResults != null) && findResults.TotalCount > 0 && findResults.FirstOrDefault() is EmailMessage)
{
//we found the email in default folder
message = (EmailMessage)findResults.First();
}
else
{
//find in all folders
var allFolders = service.FindFolders(msgFolderRootId, viewFolders);
foreach (var folder in allFolders.Folders)
{
//search
findResults = service.FindItems(folder.Id, emailFilter, viewEmails);
//check
if ((findResults != null) && findResults.TotalCount > 0 &&
findResults.FirstOrDefault() is EmailMessage)
{
//we found the email in somewhere
message = (EmailMessage)findResults.First();
break;
}
}
}
if (message != null)
{
//create property set and load necessary properties
var propertySet = new PropertySet(EmailMessageSchema.ToRecipients, EmailMessageSchema.Sender,
ItemSchema.Subject, ItemSchema.Body,
ItemSchema.DateTimeReceived, ItemSchema.DateTimeSent, ItemSchema.HasAttachments,
ItemSchema.Attachments) { RequestedBodyType = BodyType.HTML };
//load properties
service.LoadPropertiesForItems(findResults, propertySet);
}
return message;
}
示例4: GetGlobalFolder
public static Folder GetGlobalFolder(ExchangeService service)
{
FolderView fv = new FolderView(50);
fv.PropertySet = new PropertySet(BasePropertySet.IdOnly, FolderSchema.DisplayName, FolderSchema.TotalCount);
SearchFilter folderSearch = new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, Parameters.GlobalSearchFolder);
var findFoldersResults = service.FindFolders(WellKnownFolderName.SearchFolders, folderSearch, fv);
Folder targetFolder = new Folder(service);
foreach (Folder folder in findFoldersResults)
{
if (folder.DisplayName.ToLower() == Parameters.GlobalSearchFolder.ToLower())
{
targetFolder = folder;
}
}
return targetFolder;
}
示例5: GetSourceFolder
private static Folder GetSourceFolder(ExchangeService service, string email)
{
// Use the following search filter to get all mail in the Inbox with the word "extended" in the subject line.
SearchFilter searchCriteria = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
//Search for Folder DisplayName that matches mailbox email address:
new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, email.ToLower()));
FolderView fv = new FolderView(100);
fv.PropertySet = new PropertySet(BasePropertySet.IdOnly, FolderSchema.DisplayName, FolderSchema.TotalCount);
// Find the search folder named "MailModder".
FindFoldersResults findResults = service.FindFolders(
WellKnownFolderName.Inbox,
searchCriteria,
fv);
//Return root of inbox by default:
//Folder returnFolder = Folder.Bind(service, WellKnownFolderName.Inbox);
foreach (Folder searchFolder in findResults)
{
if (searchFolder.DisplayName.Contains(email.ToLower()))
{
logger.Debug("Found source folder for email: " + email + ". Using folder: " + searchFolder.DisplayName + searchFolder.TotalCount);
return searchFolder;
}
}
logger.Debug("Error getting commissioner source folder; returning global instead for: " + email);
return GetGlobalFolder(service);
}
示例6: Main
static void Main(string[] args)
{
Thread t = null;
var reqType = new RequestType();
try
{
if (args[0].Contains("poll"))
{
reqType = RequestType.Poll;
Console.WriteLine("\n\tTrying to connect to Exchange server.");
t = new Thread(ShowProgress);
t.Start();
}
else if (args[0].Contains("send"))
reqType = RequestType.Send;
else
{
Console.WriteLine("\n\tAccepted arguments are 'poll' or 'send'");
Environment.Exit(1);
}
}
catch
{
Console.WriteLine("\n\tYou have not provided any argument. Give either 'poll' or 'send' as argument.");
Environment.Exit(1);
}
ExchangeService service = new ExchangeService();
service.Credentials = new WebCredentials("<username>", "<password>", "<domain>");
service.AutodiscoverUrl("<full email address>", RedirectionUrlValidationCallback);
if (reqType == RequestType.Poll)
{
if (t != null)
t.Abort();
Console.WriteLine("\n\n\tConnected. Polling for a matching email started. Hit Ctrl+C to quit.");
while (true)
{
Thread.Sleep(10000);
FolderView folderView = new FolderView(int.MaxValue);
FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.Inbox, folderView);
foreach (Folder folder in findFolderResults)
{
if (folder.DisplayName == "<Folder name>" && folder.UnreadCount > 0)
{
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
ItemView view = new ItemView(1);
// Fire the query for the unread items.
// This method call results in a FindItem call to EWS.
FindItemsResults<Item> findResults = service.FindItems(folder.Id, sf, view);
var email = (EmailMessage)findResults.Items[0];
EmailMessage message = EmailMessage.Bind(service, email.Id, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments));
mailFrom = message.From.Address;
//Console.WriteLine("Name:" + email.From.Name);
string subject = email.Subject;
Console.WriteLine("\n\tEmail received from : " + mailFrom + " with subject \"" + subject + " at " + DateTime.Now);
folder.MarkAllItemsAsRead(true);
//Perform the action you want. Example : Go to the desired URL
var client = new WebClient();
try{
client.OpenRead("http://google.com");
}
catch(Exception e){}
}
}
}
}
else if (reqType == RequestType.Send)
{
SendEmailWithReport(service, "<To email address>");
}
}