Try our conversational search powered by Generative AI!

How to find where content is located based on url


I have a pdf document somewhere hidden in my filestructure. The search in Media doesn't return it. But I do have the public url, which contains an ID: /contentassets/539a7275ce4540dda9b5388aefb26ae5/laptopspecificaties-cmi-opleidingen.pdf. How can I find this file under Media to be able to delete this, since there's no EPiServer ID, only the contentasset ID?

Jun 24, 2020 11:50

I would start by getting the getting the content link

            var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
            IContent contentData = urlResolver.Route(new UrlBuilder("/contentassets/539a7275ce4540dda9b5388aefb26ae5/laptopspecificaties-cmi-opleidingen.pdf"));
            var contentLinkID = contentData.ContentLink.ID;

Then you can load the parents and figure out where thy are.

Jun 25, 2020 10:51

Thanks Johan. But we do have this problem on a more regular basis, so I was hoping there is something in EPi itself that an editor can use to find items like these.

Jun 25, 2020 11:50

Create an admin tool that calls the code snippet privided by Johan.

Input: public URL

Output: link to edit mode URL

Jun 26, 2020 9:26

Thanks for the tip. Would be an option, but the user wouldn't be able to delete the file, because he doesn't know where it's located. The edit mode doesn't show that path. So we would need the actual folder. And... it's strange that it doesn't come out of the box. Surely we aren't the only ones who have this issue of not being able to locate files in the epi filesystem based on the url. 

Jun 26, 2020 9:56
Tomas Hensrud Gulla - Jun 26, 2020 10:07
You could add a delete button to the admin tool, but I would not suggest doing that. You want users to get the warning of any incoming links before deleting.

If you provide an link to edit mode for the pdf, i.e something like: you will see the actual location at the top left, above the file name.
Tomasz Madeyski - May 07, 2021 8:31
This is true, but in case of assets created with "for this page" location seen above file name is not much of use: all it says is "For this page > fileName.jpg"
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.