如何获取SharePoint讨论板条目的URL?

时间:2009-06-07 11:27:43

标签: sharepoint sharepoint-2007 moss

如何检索讨论区项目的URL?也就是说,当您将鼠标悬停在主题行上时显示的URL(一旦将列表作为Web部件添加到页面中)。

7 个答案:

答案 0 :(得分:1)

protected void gvForum_RowDataBound(object sender, GridViewRowEventArgs e)
{
    SPListItem item = e.Row.DataItem as SPListItem;
    Label lblTitle = e.Row.FindControl("lblTitle") as Label;
    HtmlAnchor aURL = e.Row.FindControl("aURL") as HtmlAnchor;
    if (item != null)
    {
        if (lblTitle != null && aURL != null)
        {
            aURL.HRef = "~/" + item.Url;
            lblTitle.Text = item["Title"].ToString();                    
        }
    }
}

答案 1 :(得分:1)

    protected global::System.Web.UI.WebControls.GridView gvForum;
    public string Region
    {
        get
        {
            return "";
        }
    }
    public string DefaultRegion { get; set; }
    public int Top { get; set; }
    public string ListName
    {
        get
        {

            string listName=string.Empty;
            if (!string.IsNullOrEmpty(this.Region))
                listName=string.Format("{0} {1}","Forum",this.Region);
            else
                listName = string.Format("{0} {1}", "Forum", this.DefaultRegion);
            return listName;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }

    private void BindGrid()
    {
        string region = this.Region;
        string caml=@"<OrderBy><FieldRef Name=""Modified"" /></OrderBy>";
        try
        {
            using (SPSite spSite = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {
                    SPQuery spQ = new SPQuery();
                    spQ.Query = caml;
                    spQ.RowLimit = (uint)this.Top;
                    SPList spList = spWeb.Lists[ListName];
                    SPListItemCollection items = spList.GetItems(spQ);
                    if (items != null && items.Count > 0)
                    {
                        gvForum.DataSource = items;
                        gvForum.DataBind();
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Logger.Log(ex.Message, System.Diagnostics.EventLogEntryType.Error);
        }

    }
    protected void gvForum_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        SPListItem item = e.Row.DataItem as SPListItem;
        Label lblTitle = e.Row.FindControl("lblTitle") as Label;
        HtmlAnchor aURL = e.Row.FindControl("aURL") as HtmlAnchor;
        if (item != null)
        {
            if (lblTitle != null && aURL != null)
            {
                aURL.HRef = "~/" + item.Url;
                lblTitle.Text = item["Title"].ToString();


            }
        }
    }

答案 2 :(得分:0)

您是否在讨论如何在讨论区中查找单个讨论的URL?或个人回复讨论?

答案 3 :(得分:0)

您可以只提供http://site/discussion/lists/discussionboard/ discusontitlename或主题等主题名称

答案 4 :(得分:0)

您可能没有列表项,但如果只查看“FileRef”属性。它看起来像“https://mycompany.sharepoint.com/sites/Lists/discussion/”。如果我将该URL放在浏览器中(我正在使用SharePoint Online),它会将我重定向到https://mycompany.sharepoint.com/Lists/Discussion/Flat.aspx?RootFolder= ... URL。

答案 5 :(得分:0)

要在客户端(使用REST API调用)生成特定讨论项的直接URL,您可以尝试这样做:

var jqXhr = $.ajax({
        url:"/DiscussionSite/_api/lists/getByTitle('Discussions')/items?
        $select=ID,FileRef,ContentTypeId,Title,Body&
        $filter=ContentType eq 'Discussion'",       
        headers: { 'Accept': 'application/json;odata=verbose'}
    });

// Fetch only the discussions from the Discussion list (excl. Messages)
jqXhr.done(function(data){
    // Picking only the first item for testing purpose
    // Feel free to loop through the response if necessary
    var firstItem = data.d.results[0],
    firstItemUrl = '/DiscussionSite/Lists/Discussions/Flat.aspx?RootFolder=' + firstItem.FileRef + '&FolderCTID' + firstItem.ContentTypeId;

    // Result - /DiscussionSite/Lists/Discussions/Flat.aspx?RootFolder=/DiscussionSite/Lists/Discussions/My Discussion Topic 1&FolderCTID0x01200200583C2BEAE375884G859D2C5A3D2A8C06
    // You can append "&IsDlg=1" to the Url for a popup friendly display of the Discussion Thread in a SharePoint Modal Dialog
    console.log(firstItemUrl);
});

希望这有帮助!

答案 6 :(得分:0)

您可以使用&#34; TopicPageUrl&#34;字段列,使用REST api URL直接获取讨论主题

http://sp2013.in/_api/web/Lists/GetByTitle('Discussion')/Items?$select=Title,TopicPageUrl,DiscussionLastUpdated,Folder/ItemCount,LastReplyBy/Title,Author/Title&$expand=Folder,LastReplyBy,Author&$orderby=DiscussionLastUpdated desc

以上代码对于上次更新讨论,回复计数(保存在文件夹中),最后回复时也很有用。