problem with the MAPIFOLDER

  • Thread starter othmane benchebab
  • Start date
O

othmane benchebab

HI,

there are my code behind , but i have a probleme : can everyone help me please.

string ID="";
Outlook.AppointmentItem nouveauRdv;
nouveauRdv =(Outlook.AppointmentItemoutlookApplication.CreateItem(Outlo ok.OlItemType.olAppointmentItem);
try
{

nouveauRdv.Start = Convert.ToDateTime(_start);
nouveauRdv.End = Convert.ToDateTime(_fin);
nouveauRdv.Body = _corps;

}
catch
{
}

nouveauRdv.Save();
Outlook.NameSpace outlookNameSpace = outlookApplication.GetNamespace("MAPI");

Outlook.MAPIFolder calendarFolder = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.O utlook.OlDefaultFolders.olFolderCalendar);

Outlook.Items appointmentItems;
Outlook.AppointmentItem RdvRecherche;
RdvRecherche = null;
string filter = string.Format("[Start] = '{0}' And [End] = '{1}'", _start,_fin);
appointmentItems = calendarFolder.Items.Restrict(filter);

for (int i = 0; i < appointmentItems.Count; i++)
{
RdvRecherche = (Outlook.AppointmentItem)appointmentItems[i + 1];
}

ID =RdvRecherche.GlobalAppointmentID;
***************************************
I have problem because when i print "appointmentItems.Count" , I find 0.
 
K

Ken Slovak - [MVP - Outlook]

Does the count == 0 if you don't use the restriction? BTW, Outlook
collections run from 1 to Count.

In general it's best not to use equality as a test for date/time filters or
restrictions due to possible rounding or other slight differences. It's
usually better to use a range test for any date/time properties. Also, for
properties such as Start or End you should remove the seconds component of
the date/time values.
 
O

othmane benchebab

Hi
I do what's do u tell me , i don't use filter but the count of calendar items it's 0
my question is :
after nouvRDV.Save() ; when i do nouvRDV.Saved i find true ,but it's no present in the Calender folder.
 
K

Ken Slovak - [MVP - Outlook]

If without a filter the items count in the Calendar folder is 0 and there
are actually items in that folder you have other problems than the filter.
Are you stepping your code and making sure that you aren't hitting a catch{}
block? Do you have valid objects every step of the way, when you get your
appointment item, get the folder, get the Items collection, etc?
 
O

othmane benchebab

yes i do all that , but the problem i think , that we can't automate outlook from an asp.net application , because outlook isn't downloadede in the server web .
now i don't know what s i can do to solve this problem?
 
K

Ken Slovak - [MVP - Outlook]

That's a whole different problem.

Outlook has to run in some user context, not on a server. So your ASP code
would have to run client-side in the context of the logged in user who has
Outlook installed and with their Outlook profile.
 
O

othmane benchebab

Hi
Thank You for your post the last time.
I have one question please .
you told me that i can't automate outlook through an asp.net application , my question is : can i automate outlook through a windows application (Winform)?
PS: i have do that but i have the same problem
 

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