Get random document kentico 11

Stepan Ryabukhin asked on June 4, 2020 07:30

Hi all! I use a custom web part in Kentico 11. There is a need to get a random document. The variant ".OrderBy (Guid.NewGuid ())" from the page does not work . Orderby is expecting a string. Tell me there are other options for obtaining a random document in one request? I receive all documents DocumentHelper.GetDocuments()

Correct Answer

Brenden Kehren answered on June 4, 2020 08:03

In your document query, use SQL syntax vs C# syntax.


The NEWID() function generates a unique GUID when called in T-SQL. Also be sure to set caching to 0 minutes on that document query so it doesn't cache that order by clause.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Stepan Ryabukhin answered on June 4, 2020 08:55

.OrderBy("NEWID()") it works. thank

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.