2

I am using permanent urls for Kentico's media selection in a custom webpart. What I want is the GUID from the url it shows, so I can get the media's info from the data base (using file media provider).

This is an example of the URL

~/getmedia/998dd0ab-10d3-4cc1-bfbd-8e7bec48cf8c/sample_doc.doc

What I need is the 998dd0ab-10d3-4cc1-bfbd-8e7bec48cf8c number. I tried every helper with no success.

1 Answer 1

3

The way I normally get the GUID is through a regular expression rather than the Kentico API. Try the following:

string pattern = @"[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}";
string input = "~/getmedia/998dd0ab-10d3-4cc1-bfbd-8e7bec48cf8c/sample_doc.doc";

var guid = Regex.Match(input, pattern, RegexOptions.IgnoreCase).Value;

The guid variable will be set to 998dd0ab-10d3-4cc1-bfbd-8e7bec48cf8c which you cna then use o get the info you're after.

2
  • Awesome!!, a last one, do you how to get Media Library Direct Path from permanent url or guid, without unchecking "Use Permanent URL" from settings??, I want to download the file with c# HttpResponse so and TransmitFile but I need the direct path for that Oct 31, 2017 at 2:07
  • Try looking at CMS.MediaLibrary.Web.UI.MediaLibraryFunctions.GetMediaFileDirectUrl(), once you have the MediaFileInfo you should have what you need to call that.
    – mnield
    Oct 31, 2017 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.