Tuesday, October 13, 2009

Sending meeting request through Exchange server API

Here we can send a meeting request through exchange server .

Here is the code for creating the  meeting request.

        ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

        exchangeService.Credentials = new WebCredentials("<user name>", "<password>", "<domain>");

        exchangeService.Url = new Uri("<Exchange server url.>");

 

Here is the method in C#  which creates the meeting request.

public static void CreateMeetingRequest(string ownerEmail, string subjectText, string messageBody, string location, DateTime start, DateTime end, DataTable attendees)

        {

            try

            {

                SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

                    exchangeService.Credentials = new WebCredentials(EXCHANGE_USER_NAME, EXCHANGE_PASSWORD, EXCHANGE_DOMAIN);

                    exchangeService.Url = new Uri(EXCHANGE_URL);

                    Appointment appointment = new Appointment(exchangeService);

                    appointment.Subject = subjectText;

                    appointment.Body = new MessageBody(BodyType.Text, messageBody);

                    appointment.Start = start;

                    appointment.End = end;

                    appointment.Location = location;

                    appointment.ReminderMinutesBeforeStart = 30;

                    foreach (DataRow drow in attendees.Rows)

                    {

                        appointment.RequiredAttendees.Add(new Attendee(Convert.ToString(drow["Email"])));

                    }

                    appointment.Save();

                });

            }

            catch (ServiceRequestException ex)

            {

                throw new ApplicationException("Error: " + ex.Message);

            }

            catch (WebException ex)

            {

                throw new ApplicationException("Error: " + ex.Message);

            }

        }

Sending meeting request through Exchange server API

Here we can send a meeting request through exchange server .

Here is the code for creating the  meeting request.

        ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

        exchangeService.Credentials = new WebCredentials("<user name>", "<password>", "<domain>");

        exchangeService.Url = new Uri("<Exchange server url.>");

 

Here is the method in C#  which creates the meeting request.

public static void CreateMeetingRequest(string ownerEmail, string subjectText, string messageBody, string location, DateTime start, DateTime end, DataTable attendees)

        {

            try

            {

                SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

                    exchangeService.Credentials = new WebCredentials(EXCHANGE_USER_NAME, EXCHANGE_PASSWORD, EXCHANGE_DOMAIN);

                    exchangeService.Url = new Uri(EXCHANGE_URL);

                    Appointment appointment = new Appointment(exchangeService);

                    appointment.Subject = subjectText;

                    appointment.Body = new MessageBody(BodyType.Text, messageBody);

                    appointment.Start = start;

                    appointment.End = end;

                    appointment.Location = location;

                    appointment.ReminderMinutesBeforeStart = 30;

                    foreach (DataRow drow in attendees.Rows)

                    {

                        appointment.RequiredAttendees.Add(new Attendee(Convert.ToString(drow["Email"])));

                    }

                    appointment.Save();

                });

            }

            catch (ServiceRequestException ex)

            {

                throw new ApplicationException("Error: " + ex.Message);

            }

            catch (WebException ex)

            {

                throw new ApplicationException("Error: " + ex.Message);

            }

        }

Rename Title field in share point List

Here is the code to rename the Title field. Because the Title is the default field in custom list.


                    SPField f = listCollection[<Guid of List>].Fields["Title"];
                    f.Title = "Name";
                    f.StaticName = "Name";
                    f.Update();



Note: in SPQuery field you should use Title field. because still internal name is Title.

How to insert lookupfield in Sharepoint List.

Here is the code to get the lookup column value and then insert into list.


private static SPFieldLookupValue GetIteminLookUpList(SPWeb webObject, string lookupListName, string lookupString)
{
SPFieldLookupValue fieldLookupValue = null;
try
{
if (CheckListExist(webObject.Lists, lookupListName) == false)
{
// Throw error if the list doesn't exists.
throw new ApplicationException(string.Format("{0}'s list doesn't exists!", lookupListName));
}
SPList lookupList = webObject.Lists[lookupListName];
foreach (SPListItem item in lookupList.Items)
{
if (item["Title"].ToString() == lookupString)
{
fieldLookupValue = new SPFieldLookupValue(item.ID, lookupString);
break;
}
}
return fieldLookupValue;
}
catch (Exception ex)
{
throw new ApplicationException("Error: " + ex.Message);
}
}