ExchangeService service = this.GetService();
FolderId folderID = GetPublicFolderID(service, "My Address Book");
ContactsFolder folder = ContactsFolder.Bind(service, folderID);
int folderCount = folder.TotalCount;
var guid = DefaultExtendedPropertySet.PublicStrings;
var epdCP = new ExtendedPropertyDefinition(guid, "CustomProp", MapiPropertyType.Boolean);
var epdAccount = new ExtendedPropertyDefinition(guid, "Account", MapiPropertyType.String);
var epdCID = new ExtendedPropertyDefinition(guid, "CustomerID", MapiPropertyType.Integer);
var view = new ItemView(folderCount);
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
view.PropertySet.Add(epdCP);
view.PropertySet.Add(epdAccount);
view.PropertySet.Add(epdCID);
var contacts = service.FindItems(folderID, view);
foreach (Contact contact in contacts)
{
bool CP;
string Account;
int CID;
contact.GetLoadedPropertyDefinitions();
contact.TryGetProperty(epdCP, out CP);
contact.TryGetProperty(epdAccuont, out Account);
contact.TryGetProperty(epdCID, out CID);
Console.WriteLine(String.Format("{0, -20} - {1} - {2}"
, contact.DisplayName
, contact.EmailAddresses[EmailAddressKey.EmailAddress1]
, CP
, Account
, CID
));
}
Goal is to get the Contact information out of a Public Address Book so I can sync it with another program we have.
For each Contact in the Public Address Book, this prints out DisplayName, EmailAddress and my Custom Property. No issues there.
The problem I have is I can't seem to get the right incantation to pull certain properties. CustomerID and Account are two examples that I can't seem to get to pull/print. They aren't "Custom", in as much as I haven't created them.
How can I get CustomerID and Account out of a contact via EWS?
The GUID isn't needed for the Account and CustomerID.. and the name needs to be the Unique ID:
var guid = DefaultExtendedPropertySet.PublicStrings;
var epdAccount = new ExtendedPropertyDefinition(0x3A00, MapiPropertyType.String);
var epdCID = new ExtendedPropertyDefinition(0x3A4A, MapiPropertyType.String);
var epdCP = new ExtendedPropertyDefinition(guid, "CustomBln", MapiPropertyType.Boolean);
var epdCI = new ExtendedPropertyDefinition(guid, "CustomInt", MapiPropertyType.Integer);
Now if only I can figure out why MapiPropertyType.Integer isn't mapping correctly.... Custom Boolean pulls properly, but Custom Integers aren't.
edit: Found that double works, where Integer doesn't.
var epdCI = new ExtendedPropertyDefinition(guid, "CustomInt", MapiPropertyType.Double);
Edited Example:
ExchangeService service = this.GetService();
FolderId folderID = GetPublicFolderID(service, "My Address Book");
ContactsFolder folder = ContactsFolder.Bind(service, folderID);
int folderCount = folder.TotalCount;
var guid = DefaultExtendedPropertySet.PublicStrings;
var epdAccount = new ExtendedPropertyDefinition(0x3A00, MapiPropertyType.String);
var epdCID = new ExtendedPropertyDefinition(0x3A4A, MapiPropertyType.String);
var epdCBLN = new ExtendedPropertyDefinition(guid, "CustomBln", MapiPropertyType.Boolean);
var epdCDBL = new ExtendedPropertyDefinition(guid, "CustomDbl", MapiPropertyType.Double);
var view = new ItemView(folderCount);
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
view.PropertySet.Add(epdAccount);
view.PropertySet.Add(epdCID);
view.PropertySet.Add(epdCBLN);
view.PropertySet.Add(epdCDBL);
//var searchOrFilterCollection = new List<SearchFilter>();
//searchOrFilterCollection.Add(new SearchFilter.IsEqualTo(epdCBLN, true));
//searchOrFilterCollection.Add(new SearchFilter.IsEqualTo(epdAccount, "user"));
//var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchOrFilterCollection);
var filter = new SearchFilter.IsEqualTo(epdAccount, "user");
var contacts = service.FindItems(folderID, filter, view);
foreach (Contact contact in contacts)
{
string Account;
int CID;
bool CBLN;
double CDBL;
contact.GetLoadedPropertyDefinitions();
contact.TryGetProperty(epdAccuont, out Account);
contact.TryGetProperty(epdCID, out CID);
contact.TryGetProperty(epdCBLN, out CBLN);
contact.TryGetProperty(epdCDBL, out CDBL);
Console.WriteLine(String.Format("{0, -20} - {1} - {2} - {3} - {4}"
, contact.DisplayName
, contact.EmailAddresses[EmailAddressKey.EmailAddress1]
, Account
, CID
, CBLN
, CDBL
));
}
Related
i could i add user to supergroup / channel using tlsharp
i tried:
var contacts = new TLVector<TLInputPhoneContact>();
contacts.Add(new TLInputPhoneContact { FirstName = "xxx", LastName = "xxx", Phone = "xxx" });
var req = new TLRequestImportContacts()
{
Contacts = contacts
};
var contact = client.SendRequestAsync<TLImportedContacts>(req).GetAwaiter().GetResult();
I have tried some think like this:
List<TLInputUser> users= new List<TLInputUser>();
foreach (TeleSharp.TL.TLUser user in users)
{
usuarios.Add(new TLInputUser
{
UserId = user.Id,
AccessHash = user.AccessHash.Value
});
}
TeleSharp.TL.Channels.TLRequestInviteToChannel r = new TeleSharp.TL.Channels.TLRequestInviteToChannel
{
Channel = new TLInputChannel
{
ChannelId = tlChannel.Id,
AccessHash = tlChannel.AccessHash.Value
},
Users = new TLVector<TLAbsInputUser>(users)
};
But I received the exception USER_NOT_MUTUAL_CONTACT. Is there any other option to add a user to a group?
Thank you very much.
This is my code for sending email.
private void SendEmail(Guid accountToGuid)
{
string name = GetName(service, accountToGuid);
#region Email
Entity fromParty = new Entity("activityparty");
fromParty["partyid"] = new EntityReference("systemuser", ownerId);
Entity toParty = new Entity("activityparty");
toParty["partyid"] = new EntityReference("account", accountToGuid);
Entity Email = new Entity("email");
Email.Attributes["from"] = new Entity[] { fromParty };
Email.Attributes["to"] = new Entity[] { toParty };
Email.Attributes["subject"] = "Hello " + name;
Email.Attributes["description"] = "Your account has been confirmed by Admin";
Email.Attributes["ownerid"] = new EntityReference("systemuser", ownerId);
Guid EmailId = service.Create(Email);
SendEmailRequest req = new SendEmailRequest();
req.EmailId = EmailId;
req.IssueSend = true;
req.TrackingToken = "";
SendEmailResponse res = (SendEmailResponse)service.Execute(req);
#endregion
}
Lets say, I already sent an email to account. Email will display in activities section. How to retrieve it from SDK?
You need to perform either:
(Full examples in links)
Retrieve - When you already know the record Id, email Id in your case.
RetrieveMultiple - When you don't know the record Id, but you are going to search based on some other criteria, e.g. emails related to the account Id.
is it possible to retrieve only items with a certain flag status by using a SearchFilter?
For example, to retrieve all unread items, the search filter below is used:
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
Is there an equivalent way to retrieve all items that don't have a completed flag assigned?
Thanks
You can do it using the pidTagFlagstatus extended property https://msdn.microsoft.com/en-us/library/office/cc842307.aspx eg if the value is 2 then is flagged if the value is 1 its complete eg
String MailboxToAccess = "user#domain.com";
ExtendedPropertyDefinition PR_FLAG_STATUS = new ExtendedPropertyDefinition(0x1090, MapiPropertyType.Integer);
ExtendedPropertyDefinition FlagRequest = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, 0x8530, MapiPropertyType.String);
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(PR_FLAG_STATUS, 2);
PropertySet fiFindItemPropset = new PropertySet(BasePropertySet.FirstClassProperties);
fiFindItemPropset.Add(FlagRequest);
FolderId FolderToAccess = new FolderId(WellKnownFolderName.Inbox, MailboxToAccess);
ItemView ivItemView = new ItemView(1000);
ivItemView.PropertySet = fiFindItemPropset;
FindItemsResults<Item> FindItemResults = null;
do
{
FindItemResults = service.FindItems(FolderToAccess, sfSearchFilter, ivItemView);
foreach (Item itItem in FindItemResults.Items)
{
Console.WriteLine(itItem.Subject);
Object FlagValue = null;
if (itItem.TryGetProperty(FlagRequest, out FlagValue))
{
Console.WriteLine("Flag : " + FlagValue);
}
}
ivItemView.Offset += FindItemResults.Items.Count;
} while (FindItemResults.MoreAvailable);
I am using paypal API for .NET to create payments.
My exact code in Console Application:
// Get a reference to the config
var config = ConfigManager.Instance.GetProperties();
// Use OAuthTokenCredential to request an access token from PayPal
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken);
var p = new Payment();
p.intent = "sale";
p.payer = new Payer();
p.payer.payment_method = "credit_card"; //paypal or credit_card
var t = new Transaction();
t.amount = new Amount();
t.amount.currency = "GBP";
t.amount.total = "10.00";
t.amount.details = new Details();
t.amount.details.subtotal = "6.00";
t.amount.details.tax = "2.00";
t.amount.details.shipping = "2.00";
t.item_list = new ItemList();
t.item_list.items = new List<Item>();
var i1 = new Item();
i1.quantity = "1";
i1.name = "OBJETO TESTE";
i1.price = "6.00";
i1.currency = "GBP";
i1.sku = "TESTE";
t.item_list.items.Add(i1);
var a = new ShippingAddress();
a.recipient_name = "ADDRESS";
a.line1 = "LINE1";
a.line2 = "LINE2";
a.city = "LONDOM";
a.country_code = "GB";
a.postal_code = "NW19EA";
t.item_list.shipping_address = a;
p.transactions = new List<Transaction>();
p.transactions.Add(t);
p.redirect_urls = new RedirectUrls();
p.redirect_urls.cancel_url = string.Format("{0}{1}", "http://localhost:3161/", "Order/CancelPayment");
p.redirect_urls.return_url = string.Format("{0}{1}", "http://localhost:3161/", "Order/CompletePayment");
var payment = Payment.Create(apiContext, p);
If I change payment method to paypal, its working. if I send credit_card I get error 500.
debug_id: 30e0f1bb08d3f
configuration: live
Merchants from UK cannot make Direct(Credit Card) Payments using REST API.
You will need to upgrade your account to PRO to make use of Direct Card Payments.
Only US merchants can make direct card payments in REST API without a PRO account.
I've got the following code:
private void ListCalendarFolders(ref List<EBCalendar> items, int offset)
{
var pageSize = 100;
var view = new FolderView(pageSize, offset, OffsetBasePoint.Beginning);
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
view.PropertySet.Add(FolderSchema.DisplayName);
view.PropertySet.Add(FolderSchema.EffectiveRights);
view.Traversal = FolderTraversal.Deep;
FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.MsgFolderRoot, view);
foreach (Folder myFolder in findFolderResults.Folders)
{
if (myFolder is CalendarFolder)
{
var folder = myFolder as CalendarFolder;
items.Add(EBCalendar.FromEWSFolder(folder));
}
}
if (findFolderResults.MoreAvailable)
{
offset = offset + pageSize;
ListCalendarFolders(ref items, offset);
}
}
Where service is an ExchangeService instance. Unfortunately, it still lists folders that have been deleted, and it doesn't list shared calendars.
How can I get it to list all the shared calendars, and how can I get it to not include the folders that have been deleted?
By Shared Calendars do you mean the calendars under the other calendars node in Outlook ?
If so these Items are NavLinks that are stored in the Common Views folder in a Mailbox which is under the NonIPMSubtree (root) see http://msdn.microsoft.com/en-us/library/ee157359(v=exchg.80).aspx. You can use EWS to get the NavLinks from a Mailbox and use the PidTagWlinkAddressBookEID extended property to get the X500 address of the Mailbox these Links refer to and then use Resolve Name to resolve that to a SMTP Address. Then all you need to do is Bind to that folder eg
static Dictionary<string, Folder> GetSharedCalendarFolders(ExchangeService service, String mbMailboxname)
{
Dictionary<String, Folder> rtList = new System.Collections.Generic.Dictionary<string, Folder>();
FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root, mbMailboxname);
FolderView fvFolderView = new FolderView(1000);
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Common Views");
FindFoldersResults ffoldres = service.FindFolders(rfRootFolderid, sfSearchFilter, fvFolderView);
if (ffoldres.Folders.Count == 1)
{
PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
ExtendedPropertyDefinition PidTagWlinkAddressBookEID = new ExtendedPropertyDefinition(0x6854, MapiPropertyType.Binary);
ExtendedPropertyDefinition PidTagWlinkGroupName = new ExtendedPropertyDefinition(0x6851, MapiPropertyType.String);
psPropset.Add(PidTagWlinkAddressBookEID);
ItemView iv = new ItemView(1000);
iv.PropertySet = psPropset;
iv.Traversal = ItemTraversal.Associated;
SearchFilter cntSearch = new SearchFilter.IsEqualTo(PidTagWlinkGroupName, "Other Calendars");
// Can also find this using PidTagWlinkType = wblSharedFolder
FindItemsResults<Item> fiResults = ffoldres.Folders[0].FindItems(cntSearch, iv);
foreach (Item itItem in fiResults.Items)
{
try
{
object GroupName = null;
object WlinkAddressBookEID = null;
// This property will only be there in Outlook 2010 and beyond
//https://msdn.microsoft.com/en-us/library/ee220131(v=exchg.80).aspx#Appendix_A_30
if (itItem.TryGetProperty(PidTagWlinkAddressBookEID, out WlinkAddressBookEID))
{
byte[] ssStoreID = (byte[])WlinkAddressBookEID;
int leLegDnStart = 0;
// Can also extract the DN by getting the 28th(or 30th?) byte to the second to last byte
//https://msdn.microsoft.com/en-us/library/ee237564(v=exchg.80).aspx
//https://msdn.microsoft.com/en-us/library/hh354838(v=exchg.80).aspx
String lnLegDN = "";
for (int ssArraynum = (ssStoreID.Length - 2); ssArraynum != 0; ssArraynum--)
{
if (ssStoreID[ssArraynum] == 0)
{
leLegDnStart = ssArraynum;
lnLegDN = System.Text.ASCIIEncoding.ASCII.GetString(ssStoreID, leLegDnStart + 1, (ssStoreID.Length - (leLegDnStart + 2)));
ssArraynum = 1;
}
}
NameResolutionCollection ncCol = service.ResolveName(lnLegDN, ResolveNameSearchLocation.DirectoryOnly, false);
if (ncCol.Count > 0)
{
FolderId SharedCalendarId = new FolderId(WellKnownFolderName.Calendar, ncCol[0].Mailbox.Address);
Folder SharedCalendaFolder = Folder.Bind(service, SharedCalendarId);
rtList.Add(ncCol[0].Mailbox.Address, SharedCalendaFolder);
}
}
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
}
return rtList;
}
Cheers
Glen
You need to specify a searchfilter.
this is described here, though im not sure which Schema is the correct one, my guess would be Archieved.
So you would do something like this:
SearchFilter searchFilter = new SearchFilter.IsEqualTo(FolderSchema.Archieved, false);
FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.MsgFolderRoot,searchFilter, view);
Glen post is perfect but binding folder gives error. However i solved this. Instead of this line:
Folder SharedCalendaFolder = Folder.Bind(service, SharedCalendarId);
use the following line for shared folder binding
CalendarFolder calendar = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, OwnerEmailAddress), new PropertySet());
Here OwnerEmailAddress is Email Address of Owner or you can write ncCol[0].Mailbox.Address if using Glen's code.