試圖創建一個可視Web部件來將SharePoint 2010討論板呈現爲樹形視圖。 我可以找回所有主題作爲父節點和每個主題的所有答覆作爲子節點,但不是與層次結構。因此,所有回覆(即使是對較早回覆的回覆)都位於同一節點級別。有一個名爲ThreadIndex的屬性,可用於跟蹤層次結構上的回覆的級別(無論是第一個回覆還是回覆第一個回覆,或者是回覆第一個回覆的回覆等)。兩個線路是threadingindex值,你可以看到第一個回覆怎麼有一定的線程索引值和回覆它與附加到它的一些隨機字符串它的線程索引值..SharePoint討論列表TreeView Visual webpart
這是什麼樣子: what mine looks like http://www.resizr.com/resized/d2eb.jpg
這就是我想要它看起來像: Desired http://www.resizr.com/resized/8249.jpg
可有一個人給我一些暗示?
public partial class HDRDiscussionTreeUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> allTopics = new List<string>();
List<string> allreplies = new List<string>();
List<int> allpids = new List<int>();
HDRDiscussionTV.Nodes.Clear();
TreeNode node;
SPSite currentSite = SPContext.Current.Site;
SPWeb web = currentSite.RootWeb;
//Get the Discussion list
SPList lst = web.Lists["SP2017Discussion"];
SPQuery query0 = new SPQuery();
//get all topics
query0.Query = "<Where><IsNotNull><FieldRef Name=\"Title\" /></IsNotNull></Where>";
SPListItemCollection col = lst.GetItems(query0);
foreach (SPListItem item in col)
{
//listItem.Fields["Parent Folder Id"].GetFieldValueAsText(listItem["Parent Folder Id"]).ToString()
//string pfid = item.Fields["Parent Folder Id"].GetFieldValueAsText(item["Parent Folder Id"]).ToString();
int id = item.ID;
SPQuery query = new SPQuery();
SPListItem topic = item;
//allTopics.Add(item.Title);
node = new TreeNode(item.Title);
HDRDiscussionTV.Nodes.Add(node);
SPQuery query1 = new SPQuery();
query1.Folder = item.Folder;
//get all replies
SPListItemCollection relatedDiscussions = lst.GetItems(query1);
try
{
if (relatedDiscussions.Count != 0)
{
int n = 1;
TreeNode parentNode1 = node;
for (int i = 0; i <= relatedDiscussions.Count; i++)
{
//int parentListID = Convert.ToInt32(relatedDiscussions[i].Fields["Parent Folder Id"].GetFieldValueAsText(relatedDiscussions[i]["Parent Folder Id"]));
string threading = relatedDiscussions[i]["ThreadIndex"].ToString();
string checkthreading = relatedDiscussions[n]["ThreadIndex"].ToString();
node = new TreeNode(relatedDiscussions[i]["ows_TrimmedBody"].ToString()+"|" + threading + "|");
parentNode1.ChildNodes.Add(node);
n = i + 1;
}
}
}
catch
{
}
}
}