2009-06-07 4 views

Répondre

0

Demandez-vous comment trouver l'URL d'une discussion individuelle dans un forum de discussion? Ou une réponse individuelle à une discussion?

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
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 [email protected]"<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(); 


      } 
     } 
    } 
+0

Modifier votre autre message la prochaine fois. Ne postez pas deux réponses. – trgraglia

0

Pour générer l'URL directe à un élément de discussion particulier, sur le côté client (via un appel API REST), vous pouvez essayer ceci:

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); 
}); 

Hope this helps!

0

Vous pouvez utiliser une utilisation « TopicPageUrl » colonne de champ pour obtenir directement le sujet de discussion en utilisant 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 

Le code ci-dessus est également utile pour obtenir la discussion dernière mise à jour, la réponse count (son enregistrée dans le dossier), dernière réponse par.

Questions connexes