Ask Your Question
3

How to retrieve content through a path in EpiServer?

asked 2021-10-15 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-05 04:00:00 +0000

woof gravatar image

To retrieve content through a path in EpiServer, we can use the following code snippet:

//Get the content repository
var contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();

//Get the content by its path
var content = contentRepository.GetByPath("/path/to/content");

//Check if the content is not null
if(content != null)
{
    //Do something with the content
}

In the above code, we first get an instance of the content repository using the ServiceLocator class. Then we retrieve the content by its path using the GetByPath method of the content repository. We provide the path of the content as an input parameter to this method.

Finally, we check if the retrieved content is not null and then perform the required operations on it.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-15 11:00:00 +0000

Seen: 8 times

Last updated: Nov 05 '22