2009-08-26 69 views
1

我有以下代碼:SharePoint:插入帶有格式化超鏈接的列表項的最佳方法?

web.AllowUnsafeUpdates = true; 
SPList list = web.Lists[this.ListName]; 
SPListItem item = list.Items.Add(); 
item["linktoAttachment"] = this.SiteAddress + file.Url; 

我的問題是我怎麼能有友情鏈接的文字...

像一個典型的超級鏈接你有

<a href="technical link">friendly link here</a> 

感謝

回答

3

YOur LinkToAttachment字段應輸入Url類型,則可以使用以下內容:

item["linktoAttachment"] = string.Format("{0},{1}", this.SiteAddress + file.Url, "friendly link here"); 

另一種選擇是:

SPListItem newLink = list.Items.Add(); 
SPFieldUrlValue value = new SPFieldUrlValue(); 
value.Description = "friendly link here"; 
value.Url = this.SiteAddress + file.Url; 
newLink["linktoAttachment"] = value; 
+0

感謝,正是我一直在尋找 – 2009-08-26 17:27:14