Contents
Core Concepts
Sitefinity in Visual Studio
Sitefinity Building Parts
Developing with Sitefinity
Designing with Sitefinity
Security
How-to
API Reference
|
|
| Finding Comments |
Send comments on this topic. |
| See Also |
|
Developing with Sitefinity > Modules > Modules API > Generic Content > Comments > Finding Comments |
There are several ways to retrieve one or more posts. Choose an appropriate function given the particular scenario:
- GetComment(Guid ID) - Get a specific comment by its ID
- GetComments(Guid itemId) - Get all comments by specifying their parent content
item
- GetComments(Guid itemId, bool showVisible, string sortExp) -
Get comments by specifying their parent content item ID, whether they should be Visible (true), ordered by sorting expression
- GetComments(Guid itemId, bool showVisible, string sortExp, string
userName, out int unreadComments) - Get comments by specifying their parent content item ID, whether they should be Visible (true), ordered by sorting
expression, name of the author, and number of unread comments
- GetComments(string sortExp, string filterExp) – Get filtered subset of comments,
ordered by sorting expression
- GetComments(string sortExp, int startRowIndex, int maximumRows, string
filterExp) - Get filtered subset of comments, ordered by sorting expression, with specified starting row and maximum number of rows
- GetComments(string sortExp, int startRowIndex, int maximumRows) - Get
specific subset of comments, ordered by sorting expression, with specified starting row and maximum number of rows
-
GetComments(Guid guid, string userName, out int unreadComments) -
Get comments by specifying their parent content item ID, name of the author, and number of unread comments
 |
The last GetComments method applies to all comments - Visible, Hidden, Archived (here,
showVisible is false). |
Get a specific comment by its ID:
| GetComment(Guid ID) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get all content
items IList listOfContentItems = contentManager.GetContent(); if (listOfContentItems.Count > 0)
{
// get the first content item
Telerik.Cms.Engine.IContent secondContent =
contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[1]).ID);
// get all comments for the content item secondContent
IList listOfComments = contentManager.GetComments(secondContent.ID);
if (listOfComments.Count > 0)
{
// get the first comment item from the list
Telerik.Cms.Engine.IComment firstComment =
contentManager.GetComment(((Telerik.Cms.Engine.IComment)listOfComments[0]).ID);
Response.Write(firstComment.Text + "<br />");
}
}
|
Get all comments by specifying their parent content item:
| GetComments(Guid itemId) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get all content
items IList listOfContentItems = contentManager.GetContent(); if (listOfContentItems.Count > 0)
{
// get the first content item
Telerik.Cms.Engine.IContent secondContent =
contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[1]).ID);
// get all comments for the content item secondContent
IList listOfComments = contentManager.GetComments(secondContent.ID);
if (listOfComments.Count > 0)
{
foreach(Telerik.Cms.Engine.IComment commentItem
in listOfComments)
Response.Write(commentItem.Text + "<br
/>");
}
}
|
Get comments by specifying their parent content item ID, whether they should be Visible (true), ordered by sorting
expression:
The available keys for the sorting expression are:
- "ID" - ID of the comment
- "TextValue" - text of the comment
- "Author" - comment author
- "Email" - email of author
- "WebSite" - web site of author
- "Visible" - visible value (true or false)
- "DateCreated" - date of creation of comment
- "IpAddress" - IP address of author
- "Owner"- owner of comment
- "CntID" - parent content item ID
| GetComments(Guid itemId, bool showVisible, string sortExp) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get all content
items IList listOfContentItems = contentManager.GetContent(); if (listOfContentItems.Count > 0)
{
// get the first content item
Telerik.Cms.Engine.IContent secondContent =
contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[1]).ID);
// get all comments for the content item secondContent, sorted
IList listOfComments = contentManager.GetComments(secondContent.ID, false, "TextValue DESC");
if (listOfComments.Count > 0)
{
foreach (Telerik.Cms.Engine.IComment commentItem
in listOfComments)
Response.Write(commentItem.Text + "<br
/>");
}
}
|
Get comments by specifying their parent content item ID, whether they should be Visible (true),
ordered by sorting expression, name of the author, and number of unread comments:
| GetComments(Guid itemId, bool showVisible, string sortExp, string userName, out int unreadComments) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get all content
items IList listOfContentItems = contentManager.GetContent(); if (listOfContentItems.Count > 0)
{
// get the first content item
Telerik.Cms.Engine.IContent secondContent =
contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[1]).ID);
// create a local variable to later be populated with the number of unread comments for the given user
int unreadCommentsNumber = 0;
// get all comments for the content item secondContent, sorted
IList listOfComments = contentManager.GetComments(secondContent.ID, false, "TextValue ASC", "admin", out
unreadCommentsNumber);
if (listOfComments.Count > 0)
{
foreach (Telerik.Cms.Engine.IComment commentItem
in listOfComments)
Response.Write(commentItem.Text + " . And this is the number
of unread comments for the admin user: " + unreadCommentsNumber.ToString() + "<br
/>");
}
}
|
Get filtered subset of comments, ordered by sorting expression:
The convention for the filtering expression for comments here is the following:
- Single filter: "Key:Value;" .
For example: "User:admin"
- More than one filter: "Key:Value;Key2:Value2;" and so on.
For example: "User:admin;Text:apple;"
- Range filters: "Key:FromValue,ToValue;".
For example: "DateCreated:date1,date2;"
The available keys for Comments are:
- "Text" - uses Like operator
- "Author" - uses Like operator
- "DateCreated" - uses GE (greater-than-or-equal-to) operator. If toDate is provided (see range filters above), the LE
(less-than-or-equal-to) operator is used as well.
- "IpAddress" - uses Like operator
- "Parent" - uses EQ (equal) operator
- "ParentID" - uses EQ (equal) operator
- "GroupID"- uses EQ (equal) operator
| GetComments(string sortExp, string filterExp) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get all content
items IList listOfContentItems = contentManager.GetContent(); if (listOfContentItems.Count > 0)
{
// get the first content item
Telerik.Cms.Engine.IContent secondContent =
contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[1]).ID);
// get all comments for the content item secondContent, sorted, and filtered to contain "First" in the
text
IList listOfComments = contentManager.GetComments("TextValue
ASC", "Text:First;");
if (listOfComments.Count > 0)
{
foreach (Telerik.Cms.Engine.IComment commentItem
in listOfComments)
Response.Write(commentItem.Text + "<br
/>");
}
}
|
Get filtered subset of comments, ordered by sorting expression, with specified starting row and
maximum number of rows:
| GetComments(string sortExp, int startRowIndex, int maximumRows, string filterExp) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get filtered comments, sorted,
get all comments (0,0 means no restriction of number and start) IList listOfComments =
contentManager.GetComments("TextValue ASC", 0, 0, "Text:First;"); if (listOfComments.Count > 0)
{
foreach (Telerik.Cms.Engine.IComment commentItem in
listOfComments)
Response.Write(commentItem.Text + "<br />");
}
|
Get specific subset of comments, ordered by sorting expression, with specified starting row and maximum number
of rows:
| GetComments(string sortExp, int startRowIndex, int maximumRows) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get comments sorted, start from
first comment, get two comments IList listOfComments = contentManager.GetComments("TextValue
ASC", 0, 2); if (listOfComments.Count > 0)
{
foreach (Telerik.Cms.Engine.IComment commentItem in
listOfComments)
Response.Write(commentItem.Text + "<br />");
}
|
Get comments by specifying their parent content item ID, name of the author, and number of unread comments:
| GetComments(Guid guid, string userName, out int unreadComments) |
Copy Code |
|
// create new instance of ContentManager Telerik.Cms.Engine.ContentManager contentManager =
new Telerik.Cms.Engine.ContentManager(); // get all content
items IList listOfContentItems = contentManager.GetContent(); if (listOfContentItems.Count > 0)
{
// get the first content item
Telerik.Cms.Engine.IContent secondContent =
contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[1]).ID);
// create a local variable to later be populated with the number of unread comments for the given user
int unreadCommentsNumber = 0;
// get all comments for the content item secondContent
IList listOfComments = contentManager.GetComments(secondContent.ID, "admin", out unreadCommentsNumber);
if (listOfComments.Count > 0)
{
foreach (Telerik.Cms.Engine.IComment commentItem
in listOfComments)
Response.Write(commentItem.Text + " . And this is the number
of unread comments for the admin user: " + unreadCommentsNumber.ToString() + "<br
/>");
}
}
|
See Also
|