SPMeeting.Add method (String, String, Int16, Int32, String, String[])
新增至目前的會議工作區網站中網際網路行事曆 (iCalendar) 格式表示會議執行個體。
Namespace: Microsoft.SharePoint.Meetings
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
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
'用途
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
)
參數
icalText
Type: System.Stringstring包含會議iCalendar方式呈現。
organizer
Type: System.Stringstring包含會議召集人,指定為email_address@domain.ext的電子郵件地址。此參數用於委派案例。如果會議召集人不代理人,您可以傳遞空字串。在此情況下,執行應用程式的使用者會被視為會議召集人。
nMeetingCount
Type: System.Int16將會收到總數與目前的會議工作區,或者為週期性會議,等於MeetingCountRecurring常數的值在相關聯的會議執行個體的變數參照。
attendeeUpdateStatus
Type: System.Int32將會收到出席者更新狀態的變數參照。下表列出可能的值。
值
描述
0
沒有產生錯誤。
-2130575232
某些出席者無法被授與存取工作區的權限。
-2130575231
因為使用者配額限制而沒有新增一些出席者。
attendeeUpdateMessage
Type: System.String變數,將會收到出席者更新訊息參照。
AttendeeEmailsUnresolved
Type: []參考 (英文) 給陣列變數,將會收到無法解析為SharePoint Foundation的使用者的電子郵件地址。
傳回值
Type: System.Int32
會議的執行個體識別碼。如果iCalendar字串代表週期性會議,則傳回的值為 0。否則,傳回的值大於 0。
備註
此方法的多載Add接受RFC 2445,所定義的格式中的事件資料 「 網際網路行事曆功能和排程核心物件規格 (iCalendar) 」。許多排程的應用程式可以匯出iCalendar格式,包括 Microsoft Windows 行事曆的事件資料。
Add方法會在會議工作區網站中建立新的會議執行個體。約會不會新增至SharePoint Foundation行事曆。
Examples
下列範例會為主控台應用程式會讀取來自iCalendar檔案的文字,將字串變數,然後將變數傳遞給Add方法。
執行之前主控台應用程式,將下列文字儲存在名為 Test Sharepoint.ics 檔案並再將它放在應用程式的 bin\Debug 目錄。
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();
}
}
}