[英]How to get a String in a StringList ? C#
我的Exchange约会有一个小问题。 想法是将会议从共享点日历同步到个人交换日历。
我的CalendarItem类中有以下StringList:
private StringList m_Category;
public StringList Category { get { return m_Category; } }
它应该去:
Microsoft.Exchange.WebServices.Data.Appointment xApointment = new Appointment(m_Service)
xApointment.Categories = xItem.Category; //xItem = Instance of CalendarItem
在Microsoft.Exchange.WebService.Data.Appointment
我具有预定义的StingList Categories
。
现在发生的是,我正在通过一个XML文件进行解析,如下所示:
<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema"
xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<rs:data ItemCount="1">
<z:row ows_ContentTypeId="0x010200C5A7325634A3154BB8249D1C36246E00"
ows_Title="Test GetAllViewFields"
ows_Location="Testhausen"
ows_EventDate="2014-12-15 08:00:00"
ows_EndDate="2014-12-15 09:00:00"
ows_Description="Ein Test meeting"
ows_fAllDayEvent="0"
ows_fRecurrence="0"
ows_EventType="0"
ows_RecurrenceID="2014-12-15 08:00:00"
ows_Duration="3600"
ows_ParticipantsPicker=""
***ows_Category="Geschäftlich"***
然后,我将整个XML代码解析为字符串,然后检查名称是否存在:
private void initFromXmlAttribute(System.Xml.Linq.XAttribute x)
{
string AttributeName = x.Name.LocalName.Replace("ows_", "");
try
{
if
(AttributeName == "Category")
{
m_Category= x.Value; //Error implicite convert not possible StringList to String
return;
}
该错误是因为m_Category = StringList
和x.Value = String
。
有谁知道如何解决这个小问题?
我对StringList类不熟悉,但是我猜它是一个Collection。 您可以简单地使用其中的字符串初始化一个新的StringList:
m_Category = new StringList() { x.Value };
您应该能够使用所需的值创建一个新的Stringlist(StringList 继承自List(Of String),因此非常简单:
myStringList = new StringList()
myStringList.add(x.Value)
顺便说一句,由于您正在有效地设置“类别”属性,因此您可能需要考虑在属性中包含“设置”语句,而不是直接修改私有变量。 实际上,您可以使用以下命令完全跳过定义私有变量的步骤:
public StringList Category { get; set; }
Category = new StringList()
编译器将为您完成其余的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.