 |
|
 |
first I'de like to thank you fo this code
you are right the problem of repeating the same message was from the instance
objFolder = objNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Debug.WriteLine(objFolder.Items.Count + " E-Mails found.");
Items item1 = objFolder.Items;
for (int i=0; i < objFolder.Items.Count; i++)
{
item = (Microsoft.Office.Interop.Outlook.MailItem)item1.GetNext();
rv.Tables[0].Rows.Add(new object[] {
item.SenderName,
item.To,
item.CC,
item.Subject,
item.ReceivedTime,
item.Body
});
this.ItemProcessed();
|
|
|
|
 |
|
 |
The problem is that with this code you basically get the same items in each row. The problem is in the following code:
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Debug.WriteLine(objFolder.Items.Count + " Appointments found.");
for (int i=0; i < objFolder.Items.Count; i++)
{
item =
(Outlook.AppointmentItem)objFolder.Items.GetNext();
rv.Tables[0].Rows.Add(new object[] {
item.Subject,
item.Location,
item.Start,
item.End,
item.AllDayEvent,
item.Duration,
item.Organizer,
item.Importance,
item.Sensitivity,
item.Body
});
this.ItemProcessed()
Every time you call the GetNext method you get a new instance of the Items class. This seems to be a bug. You can fix this by creating a new instance of the Items class and using that. Like so:
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Debug.WriteLine(objFolder.Items.Count + " Appointments found.");
Items items = objFolder.Items;
for (int i=0; i < objFolder.Items.Count; i++)
{
item = (Outlook.AppointmentItem) items.GetNext();
rv.Tables[0].Rows.Add(new object[] {
item.Subject,
item.Location,
item.Start,
item.End,
item.AllDayEvent,
item.Duration,
item.Organizer,
item.Importance,
item.Sensitivity,
item.Body
});
this.ItemProcessed()
This will fix it and it'll work perfectly.
|
|
|
|
 |
|
 |
You have to call GetFirst before you call GetNext otherwise the first element won't be enumerated.
See the article in MSDN.
You should write the enumeration like this:
for (var item = (ContactItem)items.GetFirst(); item != null; item = (ContactItem) items.GetNext())
|
|
|
|
 |
|
 |
Error Description:
CS0117: 'Microsoft.Office.Interop.Outlook.MailItem' does not contain a definition for 'SenderEmailAddress'
Dipak
|
|
|
|
 |
|
 |
Hi ,This is a great article!
But I can't find Microsoft.Outlook11 in my COM Components list.
"Namespace Microsoft.Office.Interop is not exist"
Do you have any advice that will help me ?
|
|
|
|
 |
|
 |
Hi
Can You please tell me how to do the same in Asp.Net.
I am using Asp.Net 2.0 with C# and MS Outlook 2007.
Sagar Pattnayak
Software Developer
Sun-Dew Solutions
+91-9831169962
|
|
|
|
 |
|
 |
Hello,
I am still searching for a method which can convert
the X.400 / X.500 e-mail adress into "smtp e-mail adress".
Is it possible to show the e-mail adress in smtp-Format.
I was not able to find in the net a good solution.
Is there a method for C# existing.
It would be great if someone can help me.
Thanks alot...
|
|
|
|
 |
|
 |
Any idea how to extract those free timing from microsoft outlook calendar (those timing that is without appointment) using visual basic or C#?
Btw...can it be done without using Microsoft Exchange Server?
Please Help...
Thanks in advance
Best Regards,
ClaudeX
-- modified at 5:31 Thursday 7th June, 2007
|
|
|
|
 |
|
 |
Hi Mathias,
This is a great article and I am keen to implement your OutlookCOnnector in my applications.
I have added references to both Microsoft.Office11 and Microsoft.Outlook11 into your code and I am still getting the "Namespace Outlook could not be found" error.
Do you have any further advice that will help me with this?
cheers,
Mark Chimes
|
|
|
|
 |
|
 |
Hi All,
I solved this issue by place "Microsoft.Office.Interop." in front of every reference to "Outlook".
I guess this means my solution is not reading the added references properly, butat least it works this way.
cheers,
Mark Chimes
|
|
|
|
 |
|
 |
I don't want any existing Outlook window to close after program execution, so i deleted the line:
if (objOutlook != null) objOutlook.Quit();
New problem:
tried exporting my contacts 3 times in a row
first time: all 137 contacts exported
second time: something between 4 and 124 contacts exported
third time: always 0 contacts exported
tried to open outlook -> error message, couldn't open my inbox anymore
had to kill outlook.exe in the task manager to make it work properly again.
so my question is:
isn't it possible to check for an existing outlook instance, and use this one instead of creating a new one ?
Any ideas ?
|
|
|
|
 |
|
 |
Hi,
While trying this code I encountered into a bug. The following code in OutlookConnector.cs, method getCalendarDataSet:
for (int i=0; i < objFolder.Items.Count; i++)
{
item = (Outlook.AppointmentItem) objFolder.Items.GetNext();
rv.Tables[0].Rows.Add(new object[] {
item.Subject,
item.Location,
item.Start,
item.End,
item.AllDayEvent,
item.Duration,
item.Organizer,
item.Importance,
item.Sensitivity,
item.Body
});
this.ItemProcessed();
}
should be replaced with:
foreach (Outlook.AppointmentItem item in objFolder.Items)
{
rv.Tables[0].Rows.Add(new object[] {
item.Subject,
item.Location,
item.Start,
item.End,
item.AllDayEvent,
item.Duration,
item.Organizer,
item.Importance,
item.Sensitivity,
item.Body
});
this.ItemProcessed();
}
and the definition of item earlier in this method should also be removed.
Cheers, Nadav
|
|
|
|
 |
|
 |
also 4 contacts imo
/*for (int i=0; i < objFolder.Items.Count; i++)
{
item = (Outlook.ContactItem) objFolder.Items.GetNext();
rv.Tables[0].Rows.Add(new object[] {
item.FirstName,
item.LastName,
item.CompanyName,
item.Email1Address,
item.HomeTelephoneNumber,
item.BusinessTelephoneNumber
});
this.ItemProcessed();
}*/
foreach (Outlook.ContactItem item1 in objFolder.Items)
{
rv.Tables[0].Rows.Add(new object[] {
item1.FirstName,
item1.LastName,
item1.CompanyName,
item1.Email1Address,
item1.HomeTelephoneNumber,
item1.BusinessTelephoneNumber
});
this.ItemProcessed();
}
old one return one value.. you should remove this one and repeate to my modification
my modification gives correct values
you should also correct other functions
-- modified at 7:27 Thursday 31st August, 2006
|
|
|
|
 |
|
 |
Hiya,
I am a bit Novice user here. i am trying to export data from a perticular folder from outlook to an access database or a sql server. Is it possible with this code. If yes i am not able to get my head around it. Can anybody help me.
Thanks
Ash
|
|
|
|
 |
|
 |
Hi,
I'm writing a similar application that retrieves contacts and appointments from a database to create them in Outlook 2003.
On some machine, I got an error of COMException when I try to retrieve the folder with the method GetDefaultFolder(OlDefaultFolders);
Example of code :
objNamespace.GetDefaultFolder(OlDefaultFolders.olContacts);
I would like to know if you had experiment this kind of problem with your application and how to solve this.
Thanks
|
|
|
|
 |
|
 |
I am using Outlook similar to your example, but pulling in shared folders from Exchange. It is all working except that I cannot cast Items.Item to Contact.Item. I instead need to keep them as Object - which then uses late binding.
Since I am processing over 500,000 entries, I would like the performance boost of early binding.
Any ideas why Exchange won't allow the cast?
(I am also using the exact same code with the default Outlook folder and there the cast works fine. Just not with any shared folders.)
Thanks!
|
|
|
|
 |
|
 |
hey howzit?
its easy to import contacts from outlook in code...but what i wanna do is be able to drag an outlook contact straight from the running Outlook Application itself into my running C# application...can anyone help?
So far I am able to drop random files into a listbox using this tutorial: http://www.csharphelp.com/archives2/archive365.html but its still doesn't provide me will the ability described above
|
|
|
|
 |
|
 |
Hi,
When I run the Outlook Connector and I want to export the appointments, I became always one appointment.
Where is the failure?
Greetz
|
|
|
|
 |
|
 |
Could this be modified to access any PST? I output PST files from kvs enterprise vault but then want to read each PST and parse out the data I need.
|
|
|
|
 |
|
 |
While I was debbuging I found to an ineresting bug and exception that is swolen inside the code
In class methods eg. LoadInboxItems and others where you are going to get next, at the last item objItems.GetNext() returns null value. The result is exception that is written to Console so without carefull looking it wanish and possibly won't be seen
So the resolution is to modify code like this (in all methods working with GetNext() method of Outlook.Items collection of course):
outlookItem = objItems.GetNext();
if (outlookItem ==null)
break;
P.S.
It is wise to show Exception message to the user in such cases, or throw some custom message or handle it in some way that would be obvious to the user or fellow programer.
P.S.S Great work tough!!! Thx for the code!
Preky
|
|
|
|
 |
|
 |
When i try to run the code it is count the number of calendar items as 2 and contacts as 5 etc(and these figures are correct). But when the data is exported to xml both the items are same. That means under contacts there are 5 items but all the 5 are the same record. ie. the first record. Why is this happening like this. Also i did an iteration through the code runtime and i am storing subject and body in a temp variables. But those values are always having the same values (the 1st record). Can anybody tell me what is the change to be made to read record by record in contacts or calendar. Please help .
for (int i=0; i < objFolder.Items.Count; i++)
{
item = (Outlook.AppointmentItem) objFolder.Items.GetNext();
string sub = item.Subject;
string bd = item.Body;
rv.Tables[0].Rows.Add(new object[] {
item.Subject,
item.Location,
item.Start,
item.Body
});
this.ItemProcessed();
}
|
|
|
|
 |
|
 |
I ran into the same problem and changed the code to make it work. Alternately, try getting version 1.0. In the release notes 1.1 he said he stopped using the the Enumerator and changed it to a for loop for compatibility with office 10. However, I think that broke the program for Office 11 (2003) as the GetNext() method on the Items collection doesn't seem to work properly, I kept getting the same item repeated over and over.
This is what I did to get 1.1 to work. It worked for me but YMMV and all the usual disclaimers. Get rid of the For loop in the get*DataSet methods and make them while loops with the IEnumerator like this (this is for the OutlookConnector.GetInboxData() method)
System.Collections.IEnumerator MsgEnum = objFolder.Items.GetEnumerator();
while (MsgEnum.MoveNext())
{
item = (Outlook.MailItem) MsgEnum.Current;
rv.Tables[0].Rows.Add(new object[] { item.SenderName,
item.To,
item.CC,
item.Subject,
item.ReceivedTime,
item.Body
});
this.ItemProcessed();
}
|
|
|
|
 |
|
 |
It changed the code bold line
for (int i=1; i <= objFolder.Items.Count; i++)
{
item = (Outlook.MailItem) objFolder.Items.Item(i);
rv.Tables[0].Rows.Add(new object[] {
item.SenderName,
item.To,
item.CC,
item.Subject,
item.ReceivedTime,
item.Body
});
this.ItemProcessed();
}
|
|
|
|
 |
|
 |
The code as written returns the same first item each time.
The reason is that every time GetNext is called
the code retrieves a new instance of the Items object.
Solution: Store the Items object in a local variable to make sure you are always using the same
instance
new code
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items Items= objFolder.Items;
item = (Outlook.MailItem) Items.GetFirst();
while (null != item)
{
item = (Outlook.MailItem)Items.GetNext();
rv.Tables[0].Rows.Add(new object[] {
item.SenderName,
item.To,
item.CC,
item.Subject,
item.ReceivedTime,
item.Body
});
this.ItemProcessed();
}
RDerby
|
|
|
|
 |
|
 |
I tried to execute the getting calendar items and contracts items from the code and i am always getting only the first record. In debug mode i have inserted a a string variable to get the exception and the exception you can see in this screenshot. http://www.guidant-cor.com/tempfiles/exceptionscreen.jpg
Can anybody help me with this. Please reply as when is the cause of the error.
|
|
|
|
 |