2013-03-26 57 views
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.​</p> 
</div> 

我想作爲

"Please follow plan of action." 

請指導輸出。

回答

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"]); 
0

如果您想刪除內容中的HTML,這個答案將幫助您:

How can I strip HTML tags from a string in ASP.NET?

有許多解決方案有,比如一個正則表達式用的。你只需要這行代碼:

txtContent.Text=WebUtility.HtmlDecode(Regex.Replace(getAnnouncement["Body"].ToString(), "<[^>]*(>|$)", string.Empty))