How to get media file's ID from kentico's media selection?

℡╲_俬逩灬. 提交于 2021-02-08 11:31:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!