SPMeeting.Add Method (String, String, Int16, Int32, String, String )

Adds a meeting instance represented in Internet Calendar (iCalendar) format to the current Meeting Workspace site.

Namespace:  Microsoft.SharePoint.Meetings
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Function Add ( _
    icalText As String, _
    organizer As String, _
    <OutAttribute> ByRef nMeetingCount As Short, _
    <OutAttribute> ByRef attendeeUpdateStatus As Integer, _
    <OutAttribute> ByRef attendeeUpdateMessage As String, _
    <OutAttribute> ByRef AttendeeEmailsUnresolved As String() _
) As Integer
'Usage
Dim instance As SPMeeting
Dim icalText As String
Dim organizer As String
Dim nMeetingCount As Short
Dim attendeeUpdateStatus As Integer
Dim attendeeUpdateMessage As String
Dim AttendeeEmailsUnresolved As String()
Dim returnValue As Integer

returnValue = instance.Add(icalText, organizer, _
    nMeetingCount, attendeeUpdateStatus, _
    attendeeUpdateMessage, AttendeeEmailsUnresolved)
public int Add(
    string icalText,
    string organizer,
    out short nMeetingCount,
    out int attendeeUpdateStatus,
    out string attendeeUpdateMessage,
    out string[] AttendeeEmailsUnresolved
)

Parameters

  • icalText
    Type: System.String

    A string that contains the iCalendar representation of a meeting.

  • organizer
    Type: System.String

    A string that contains the e-mail address of the meeting organizer, specified as email_address@domain.ext. This parameter is used in delegate scenarios. If the meeting organizer is not a delegate, you can pass an empty string. In that case, the user who runs the application is considered to be the meeting organizer.

  • nMeetingCount
    Type: System.Int16

    A reference to a variable that will receive the total number of meeting instances that are associated with the current Meeting Workspace or, in the case of a recurring meeting, a value that is equal to the MeetingCountRecurring constant.

  • attendeeUpdateStatus
    Type: System.Int32

    A reference to a variable that will receive the attendee update status. Possible values are listed in the following table.

    Value

    Description

    0

    No error occurred.

    -2130575232

    Some attendees could not be granted permission to access the workspace.

    -2130575231

    Some attendees were not added due to user quota limit.

  • attendeeUpdateMessage
    Type: System.String

    A reference to a variable that will receive the attendee update message.

  • AttendeeEmailsUnresolved
    Type: []

    A reference to an array variable that will receive the e-mail addresses that fail to be resolved as users of SharePoint Foundation.

Return Value

Type: System.Int32
The instance ID of the meeting. If the iCalendar string represents a recurring meeting, the return value is 0. Otherwise, the return value is greater than 0.

Remarks

This overload of the Add method accepts event data in the format defined by RFC 2445, "Internet Calendaring and Scheduling Core Object Specification (iCalendar)". Many scheduling applications can export event data in iCalendar format, including the Microsoft Windows Calendar.

The Add method creates a new meeting instance in the Meeting Workspace site. An appointment is not added to the SharePoint Foundation calendar.

Examples

The following example is a console application that reads text from an iCalendar file into a string variable and then passes the variable to the Add method.

Before running the console application, save the following text in a file named Test Sharepoint.ics and then place it in the application’s bin\Debug directory.

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Microsoft Corporation//Windows Calendar 1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:Pacific Time (US & Canada)
BEGIN:STANDARD
DTSTART:20071104T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
TZNAME:Pacific Standard Time
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20070311T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
TZNAME:Pacific Daylight Time
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20090224T222033Z
DTSTART;TZID=Pacific Time (US & Canada):20100301T130000
DTEND;TZID=Pacific Time (US & Canada):20100301T133000
RRULE:FREQ=WEEKLY;COUNT=5;BYDAY=MO,TU,WE,TH,FR
SUMMARY:Test Sharepoint
UID:0EE4D0CD-305A-4ED3-B530-0350A89CC324
END:VEVENT
END:VCALENDAR
Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Meetings

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")
         Using web As SPWeb = site.OpenWeb()

            Dim fileName As String = "Test Sharepoint.ics"
            Dim workspaceName As String = fileName.Substring(0, fileName.Length - 4)

            ' Create a Meeting Workspace site.
            Dim mwsWeb As SPWeb = CreateWorkspace(web, 0, workspaceName, workspaceName, "This is a test workspace.")

            ' Get the meeting information for the workspace.
            Dim meeting As SPMeeting = SPMeeting.GetMeetingInformation(mwsWeb)

            '  Get an iCalendar event.
            Dim icalText As String = ReadICal(fileName)

            If Not String.IsNullOrEmpty(icalText) Then

               ' Create output parameters.
               Dim meetingCount As Short = 0
               Dim attendeeUpdateStatus As Integer = 0
               Dim attendeeUpdateMessage As String = String.Empty
               Dim attendeeEmailsUnresolved() As String = {String.Empty}

               ' Add the meeting.
               Try
                  Dim instanceID As Integer = meeting.Add(icalText, _
                                                          String.Empty, _
                                                          meetingCount, _
                                                          attendeeUpdateStatus, _
                                                          attendeeUpdateMessage, _
                                                          attendeeEmailsUnresolved)

                  ' Interpret the attendeeUpdateStatus output.
                  Dim updateStatus As String
                  Select Case attendeeUpdateStatus
                     Case -2130575232
                        updateStatus = _
                           "Some attendees could not be granted permission to access the workspace."
                     Case -2130575231
                        updateStatus = "Some attendees were not added due to user quota limit."
                     Case Else
                        updateStatus = "No errors."
                  End Select
                  ' Print the URL and number of meetings.
                  Dim mswUrl As String = mwsWeb.Url + "/default.aspx?InstanceID=" + instanceID.ToString()
                  Console.WriteLine(mswUrl)
                  Console.WriteLine("Meeting count: {0} | Update status: {1}", meetingCount, updateStatus)
               Catch ex As Exception
                  Console.WriteLine(ex.Message)
               End Try
            End If

            ' Clean up.
            mwsWeb.Dispose()

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub

   Function CreateWorkspace(ByVal parentWeb As SPWeb, ByVal templateNumber As System.UInt32, ByVal internalName As String, ByVal title As String, ByVal description As String) As SPWeb
      If 5 <= templateNumber Then
         Throw New ArgumentException("The templateNumber argument must be less than 5.")
      End If

      Dim templateName As String = SPWebTemplate.WebTemplateMWS + "#" + templateNumber.ToString()

      If String.IsNullOrEmpty(title) Then
         title = "Untitled"
      End If

      Dim mwsName As String = MakeUniqueName(parentWeb.Webs.Names, internalName)

      Dim language As System.UInt32 = CType(parentWeb.Locale.LCID, System.UInt32)

      Return parentWeb.Webs.Add(mwsName, title, description, language, templateName, False, False)
   End Function

   Function MakeUniqueName(ByVal names() As String, ByVal name As String) As String
      Dim NewName As String = name.Replace(";", "").Replace("'", "")
      Dim baseName As String = name
      Dim n As Integer = 0

      Dim pos As Integer = name.LastIndexOf("("c)
      If pos > -1 And name.EndsWith(")") Then
         baseName = name.Substring(0, pos)
         Dim ext As String = name.Substring(baseName.Length + 1).Replace(")", "")
         Dim IsNumber As Boolean = Integer.TryParse(ext, n)
         If IsNumber Then
            n = n + 1
         End If
      End If

      Dim i As Integer = Array.IndexOf(names, name)
      If i >= 0 Then
         baseName = baseName + "(" + n.ToString() + ")"
         NewName = MakeUniqueName(names, baseName)
      End If

      Return NewName
   End Function

   Function ReadICal(ByVal fileName As String) As String
      Dim sb As StringBuilder = New StringBuilder()
      If Not File.Exists(fileName) Then
         Console.WriteLine("{0} does not exist.", fileName)
         Return sb.ToString()
      End If
      Using sr As StreamReader = File.OpenText(fileName)
         Dim input As String
         Do
            input = sr.ReadLine()
            sb.AppendLine(input)
         Loop Until input Is Nothing
         sr.Close()
      End Using
      Return sb.ToString()
   End Function

End Module
using System;
using System.IO;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Meetings;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               string fileName = "Test Sharepoint.ics";
               string workspaceName = fileName.Substring(0, fileName.Length - 4);

               // Create a Meeting Workspace site.
               SPWeb mwsWeb = CreateWorkspace(web, 0, workspaceName, workspaceName, "This is a test workspace.");

               // Get the meeting information for the workspace.
               SPMeeting meeting = SPMeeting.GetMeetingInformation(mwsWeb);

               // Get an iCalendar event.
               string icalText = ReadICal(fileName);

               if (!String.IsNullOrEmpty(icalText))
               {
                  // Create output parameters.
                  short meetingCount;
                  int attendeeUpdateStatus;
                  string attendeeUpdateMessage;
                  string[] attendeeEmailsUnresolved;

                  // Add the meeting.
                  try
                  {
                     int instanceID = meeting.Add(icalText,
                                                  String.Empty,
                                                  out meetingCount,
                                                  out attendeeUpdateStatus,
                                                  out attendeeUpdateMessage,
                                                  out attendeeEmailsUnresolved);

                     // Interpret the attendeeUpdateStatus output.
                     string updateStatus;
                     switch (attendeeUpdateStatus)
                     {
                        case -2130575232:
                           updateStatus =
                              "Some attendees could not be granted permission to access the workspace.";
                           break;
                        case -2130575231:
                           updateStatus = "Some attendees were not added due to user quota limit.";
                           break;
                        default:
                           updateStatus = "No errors.";
                           break;
                     }
                     // Print the URL and number of meetings.
                     string mswUrl = mwsWeb.Url + "/default.aspx?InstanceID=" + instanceID.ToString();
                     Console.WriteLine(mswUrl);
                     Console.WriteLine("Meeting count: {0} | Update status: {1}", meetingCount, updateStatus);
                  }
                  catch (Exception ex)
                  {
                     Console.WriteLine(ex.Message);
                  }
               }
               // Clean up
               mwsWeb.Dispose();
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }

      static SPWeb CreateWorkspace(SPWeb parentWeb, uint templateNumber, string internalName, string title, string description)
      {
         if (5 <= templateNumber)
            throw new ArgumentException("The templateNumber argument must be less than 5.");

         string templateName = SPWebTemplate.WebTemplateMWS + "#" + templateNumber.ToString();

         if (String.IsNullOrEmpty(title))
            title = "Untitled";

         string mwsName = MakeUniqueName(parentWeb.Webs.Names, internalName);

         uint language = (uint)parentWeb.Locale.LCID;

         return parentWeb.Webs.Add(mwsName, title, description, language, templateName, false, false);
      }

      static string MakeUniqueName(string[] names, string name)
      {
         string newName = name.Replace(";", "").Replace("'", "");
         string baseName = name;
         int n = 0;

         int pos = name.LastIndexOf('(');
         if (pos > -1 & name.EndsWith(")"))
         {
            baseName = name.Substring(0, pos);
            string ext = name.Substring(baseName.Length + 1).Replace(")", "");
            bool IsNumber = int.TryParse(ext, out n);
            if (IsNumber) n++;
         }

         int i = Array.IndexOf(names, name);
         if (i >= 0)
         {
            baseName = baseName + "(" + n.ToString() + ")";
            newName = MakeUniqueName(names, baseName);
         }
         return newName;
      }

      static string ReadICal(string fileName)
      {
         StringBuilder sb = new StringBuilder();
         if (!File.Exists(fileName))
         {
            Console.WriteLine("{0} does not exist.", fileName);
            return sb.ToString();
         }
         using (StreamReader sr = File.OpenText(fileName))
         {
            String input;
            while ((input = sr.ReadLine()) != null)
            {
               sb.AppendLine(input);
            }
            sr.Close();
         }
         return sb.ToString();
      }
   }
}

See Also

Reference

SPMeeting Class

SPMeeting Members

Add Overload

Microsoft.SharePoint.Meetings Namespace

MeetingCount

InstanceId

Update(String, Boolean, Int32, String, [])