如何从kentico的媒体选择中获取媒体文件的ID?

时间:2017-10-09 01:07:33

标签: c# kentico

我正在为我的项目创建自定义Web部件,因此我需要从媒体库中选择文件(.pdf,doc等)。我正在使用kentico的媒体选择表格控件,并在我的代码背后获取价值:

<?php include("../config/includes.php") ?>
<?
$request = $_REQUEST["request"];

$hint = "";

if ($request !== "") {

$uncorrect = $Helper->UncorrectUnique();

$correct = $Helper->CorrectUnique();

$dict = array_combine($uncorrect, $correct);

$hint = preg_replace_callback("/\pL+/u", function ($m) use ($dict) {
    $word = mb_strtolower($m[0]);
    if (isset($dict[$word])) {
        $repl = $dict[$word];
        // Check for some common ways of upper/lower case
        // 1. all lower case
        if ($word === $m[0]) return $repl;
        // 2. all upper case
        if (mb_strtoupper($word) === $m[0]) return mb_strtoupper($repl);
        // 3. Only first letters are upper case
        if (mb_convert_case($word,  MB_CASE_TITLE) === $m[0]) return mb_convert_case($repl,  MB_CASE_TITLE);
        // Otherwise: check each character whether it should be upper or lower case
        for ($i = 0, $len = mb_strlen($word); $i < $len; ++$i) {
            $mixed[] = mb_substr($word, $i, 1) === mb_substr($m[0], $i, 1) 
                ? mb_substr($repl, $i, 1)
                : mb_strtoupper(mb_substr($repl, $i, 1));
        }
        return implode("", $mixed);
    }
    return $m[0]; // Nothing changes
}, $request);

$hint = $Helper->specialCheck($hint);
}

echo $hint === "" ? "" : preg_replace('~[\r\n]+~', '', $hint);

?>

这样做我得到了我文件的路径(例如〜/ BlankSite / media / Office / test-file.pdf?ext = .pdf),但我需要的是ID,所以我可以获取媒体信息Kentico的MediaFileInfoProvider,例如:

public string DocumentInfo 
{ 
   get 
   { 
     return ValidationHelper.GetString(GetValue("MediaInfo"), "") 
   }
}

真正的问题是,如何从媒体选择中获取ID并在之前的提供商中使用它?或者我如何通过其他方法从我的文件中获取媒体信息?

1 个答案:

答案 0 :(得分:0)

您是否尝试过MediaFileInfoProvider info = MediaFileInfoProvider.GetMediaFileInfo(string siteName, string mediaFilePath, string libraryFolder);

所以你可以打电话:

MediaFileInfoProvider info = MediaFileInfoProvider.GetMediaFileInfo(CurrentSite.SiteName, "~/BlankSite/media/Office/test-file.pdf?ext=.pdf", null);