0
TextBox txtContent = new TextBox();

SPList announcementList = mySite.Lists["Announcements"];
SPListItem getAnnouncement = announcementList.Items[0];
txtContent.Text = getAnnouncement["Body"].ToString();

这给出了输出

<div class="ExternalClass61EB4AB2F639401D9141EADFC30FEDFE">
    <p>Please follow plan of action.​&lt;/p>
</div>

我想要输出为

"Please follow plan of action."

请指导。

4

3 回答 3

0
SPHttpUtility.ConvertSimpleHtmlToText(text, text.Length - 1);
于 2013-04-10T02:17:04.007 回答
0

如果您要从内容中删除 HTML,此答案将对您有所帮助:

如何从 ASP.NET 中的字符串中去除 HTML 标记?

那里有许多解决方案,例如使用 Regex 的解决方案。你只需要这行代码:

txtContent.Text=WebUtility.HtmlDecode(Regex.Replace(getAnnouncement["Body"].ToString(), "<[^>]*(>|$)", string.Empty))
于 2013-03-26T19:41:17.343 回答
0

SPFieldMultiLineText像下面这样使用:

SPListItem getAnnouncement = announcementList.Items[0];
SPFieldMultiLineText bodyField = getAnnouncement.Fields.GetField("Body") as SPFieldMultiLineText;
string txt = bodyField.GetFieldValueAsText(getAnnouncement["Body"]);
string html = bodyField.GetFieldValueAsHtml(getAnnouncement["Body"]);
于 2013-03-26T23:46:31.067 回答