问题
I am creating a custom web part for my project, so I need to select files (.pdf, ,doc, etc...) from a media library. I am using kentico's media selection form control and getting the value on my code behind like this:
public string DocumentInfo
{
get
{
return ValidationHelper.GetString(GetValue("MediaInfo"), "")
}
}
Doing this I am getting the path of my file (e.g ~/BlankSite/media/Office/test-file.pdf?ext=.pdf) but what I need is the ID, so I can get the Media Info with Kentico's MediaFileInfoProvider, for example:
MediaFileInfo info = MediaFileInfoProvider.GetMediaFileInfo(int mediaFileID);
The real question, is how can I get the ID from the media selection and use it in the previous provider? Or how can I get the Media Info from my file with an other approach?
回答1:
Have you tried MediaFileInfoProvider info = MediaFileInfoProvider.GetMediaFileInfo(string siteName, string mediaFilePath, string libraryFolder);
?
So you might call:
MediaFileInfoProvider info = MediaFileInfoProvider.GetMediaFileInfo(CurrentSite.SiteName, "~/BlankSite/media/Office/test-file.pdf?ext=.pdf", null);
来源:https://stackoverflow.com/questions/46637570/how-to-get-media-files-id-from-kenticos-media-selection