【问题标题】:How to get the text value from Multiline text field in sharepoint using C#如何使用 C# 从 sharepoint 中的多行文本字段中获取文本值
【发布时间】:2015-02-18 09:09:43
【问题描述】:

我试过这段代码:

using (SPSite oSite = new SPSite("http://omar:2020/Lists/Calendar1/AllItems.aspx"))
{
    using (SPWeb oWeb = oSite.OpenWeb())
    {
        SPList oList = oWeb.Lists["Calendar"];
        SPListItem item = oList.GetItemById(7);

        txtArea_desc.InnerText = item["Description"].ToString();

    }
}

但它给了我“class="ExternalClassD6E6296DE90F457892C156ABE9631AC6Hello" 在文本区域中。

有什么建议吗?

【问题讨论】:

  • txtArea_desc是什么类?

标签: c# sharepoint


【解决方案1】:

Event 内容类型中的Description 字段具有以下声明:

<Field ID="{9da97a8a-1da5-4a77-98d3-4bc10456e700}"
    Type="Note"
    RichText="TRUE"
    Name="Comments"
    Group="_Hidden"
    DisplayName="$Resources:core,Comments;"
    Sortable="FALSE"
    SourceID="http://schemas.microsoft.com/sharepoint/v3"
    StaticName="Comments">
</Field> 

由于RichText属性设置为true,它的值包含html内容。

使用SPField.GetFieldValueAsText Method 获取字段值作为纯文本

示例

using (var site = new SPSite(siteUrl))
{
    using (var web = site.OpenWeb())
    {
        var list = web.Lists.TryGetList(listTitle);
        var item = list.GetItemById(itemId);
        var eventDescField = list.Fields.GetFieldByInternalName("Description");
        var eventDesc = item[eventDescField.Id];
        var eventDescText = eventDescField.GetFieldValueAsText(eventDesc);

    }
}

【讨论】:

    【解决方案2】:

    您的多行文本字段必须在设置中处于粗略文本模式,否则您将拥有像您的示例一样的 css 类

    【讨论】:

      猜你喜欢
      • 2019-10-09
      • 2021-08-17
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多