How to find which media library "library" a document is in from a "permanent" link using getmedia?

Tim Valdez asked on September 26, 2024 20:58

We have a custom MVC Kentico 11 website. I have access to the MVC (website) and Kentico (CMS) databases as well. Is there a query I can run that will allow me to find out which library and folder in that library in our ML a document is located based on just the permanent link URL? Our forms person is cleaning up the ML folders and needs to relink documents but there is no easy way to find where the document is located in our ML hierarchy. So I'm wondering if I can take the /getmedia/[GUID]/filename link from a webpage and figure out where in the ML that file is stored...any ideas?

Correct Answer

John Lougee answered on September 26, 2024 21:49

Hi Tim,

Yes, using the GUID, you can get this information by running a SQL query similar to the following:

SELECT Media_File.FileName, Media_Library.LibraryName, Media_Library.LibraryFolder
  FROM Media_File
  INNER JOIN Media_Library ON Media_File.FileLibraryID = Media_Library.LibraryID
  WHERE FileGUID = '<the GUID for your media file>'

This would return the image name, Media Library name, and Media Library folder it is in but there are many other fields from those tables that you could return as well depending on your needs.

I hope this helps!

1 votesVote for this answer Unmark Correct answer

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