Redemption + get ID from Name in outlook contacts + .net

A

Anushya

Hi
How to get the id of a name in contact items in outlook. How to do it
thru redemption in .net??
i tried the code below. but it shows the error. pls have a look at the
code

Microsoft.Office.Interop.Outlook.NameSpace oNs;
oNs = Connect.oApplication.GetNamespace("MAPI");

//it shows an error here - invalid cast exception
Redemption.AddressLists rAddressLists = (Redemption.AddressLists)
oNs.AddressLists;

for (int intI=0; intI < rAddressLists.Count;intI++)
{
Redemption.AddressList rAddressList = rAddressLists.Item(intI);
MessageBox.Show(rAddressList.ID + " " + rAddressList.Name);
}

Thanks
Anushya
 
D

Dmitry Streblechenko \(MVP\)

You are casting Outlook.AddressLists object returned by
Namespace.AddressLIsts to Redemption.AddressLists, that is bound to fail.
To use Redemption.AddressLists object, simply create an instane of it, there
is nothing else to do.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Anushya

Hi
Thanks Dmitry.

But How to create an instance for addresslists, addresslist,
addressentries & addressentry in .net? i dont know how since cannot
create the object straight by using new. When i tried new operator
found addressListInterface and addresslistClass. How shud i????

then tried by creating object and then cast to object type(as u
suggested to someone in a group). but i cannot move thru items as it
is not a collection, just an object.
Microsoft.Office.Interop.Outlook.NameSpace oNs;
oNs = Connect.oApplication.GetNamespace("MAPI");
Object rals;
Object ral;
Object raes;
Object rae;
rals = oNs.AddressLists;
MessageBox.Show(((Redemption.AddressLists)rals).Count.ToString());
for(int intI=0;intI<((Redemption.AddressLists)rals).Count;i++)
{
//here is the problem, since rals is an object, cannot access
ral = rals(intI);
raes = ((Redemption.AddressList)ral).AddressEntries;
for(int intJ=1;intJ<((Redemption.AddressEntries)raes).Count;intJ++)
{
//here is the problem, since raes is an object, cannot access
rae = raes(intJ);
MessageBox.Show(((Redemption.AddressEntry)rae).Address );
//((Redemption.AddressEntry)rae).Address
}
}

Or shud i go thru some other way like

rals = Activator.CreateComInstanceFrom("Interop.Redemption.dll","Redemption.AddressListsClass");

Even so how to access the properties and methods????
My main intention is to get the id for the name i give, by accessing
outlook contacts.
Pls let me know
Thx
Anushya
 
D

Dmitry Streblechenko \(MVP\)

Simply use new to create an instance of the Redemption.AddressLists object.
Or something like

Type t = Type.GetTypeFromProgID("Redemption.AddressLists");
Redemption.AddressLists rals = (Redemption.AddressLists)
Activator.CreateInstance(t);

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Anushya Velayutham

Thankssssss Dmirty
It works fine.

Type tmpType;
tmpType = Type.GetTypeFromProgID("Redemption.AddressLists");
Redemption.AddressLists oRedemptionAddressLists =
(Redemption.AddressLists)Activator.CreateInstance(tmpType);
for(int intI=0;intI<oRedemptionAddressLists.Count;intI++)
{
Redemption.AddressList oRedemptionAddressList =
oRedemptionAddressLists.Item(intI);

Redemption.AddressEntries oRedemptionAddressEntries =
oRedemptionAddressList.AddressEntries;
for(int intJ=1;intJ<oRedemptionAddressEntries.Count;intJ++)
{
MessageBox.Show(oRedemptionAddressEntries[intJ].Name.ToString());
MessageBox.Show(oRedemptionAddressEntries[intJ].Address.ToString())
;
}
}

Anushya
_---Original Message-----
Type t = Type.GetTypeFromProgID("Redemption.AddressLists");
Redemption.AddressLists rals = (Redemption.AddressLists)
Activator.CreateInstance(t);

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top