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.</p>
</div>
我希望输出为
"Please follow plan of action."
请指南。
答案 0 :(得分:0)
如果您要从内容中删除HTML,此答案将对您有所帮助:
How can I strip HTML tags from a string in ASP.NET?
有很多解决方案,例如Regex的解决方案。你只需要这行代码:
txtContent.Text=WebUtility.HtmlDecode(Regex.Replace(getAnnouncement["Body"].ToString(), "<[^>]*(>|$)", string.Empty))
答案 1 :(得分: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"]);
答案 2 :(得分:0)
SPHttpUtility.ConvertSimpleHtmlToText(text, text.Length - 1);