您可以根据 Dataverse 搜索在门户上查看和搜索知识文章附件。 要实现此目的,您必须从门户配置分面搜索结果 Web 模板。
- 在 Portal Management 的站点地图中,转到 Content 区域,然后选择 Web 模板。 您可以从多个位置登录到 Portal Management。 有关详细信息,请参阅 Portal Management 应用程序概述。
- 从 可用 Web 模板 下拉列表中,选择您的知识文章 Web 模板。
- 在 Web 模板 页面上,选择 常规 选项卡,将以下代码片段添加到 源 字段。
{{#if relatedAttachments}}
{{#each relatedAttachments}}
<li class="note-item">
{{#if isImage}}
<a id="kbattachment-{{entityID}}" href="javascript:downloadKbAttachmentFile('kbattachment-{{entityID}}', '{{title}}', {{fileSize}}, '{{fileType}}', '{{downloadBlockUrl}}', '{{initializeDownloadUrl}}')"><span class="glyphicon glyphicon-file" aria-hidden="true"></span> {{title}}</a>
{{else}}
<a id="kbattachment-{{entityID}}" title="{{title}}" href="javascript:downloadKbAttachmentFile('kbattachment-{{entityID}}', '{{title}}', {{fileSize}}, '{{fileType}}', '{{downloadBlockUrl}}', '{{initializeDownloadUrl}}')"><span class="glyphicon glyphicon-file" aria-hidden="true"></span> {{title}}</a>
{{/if}}
<p class="fragment text-muted">{{{fragment}}}</p>
</li>
{{/each}}
{{/if}}
<script type="text/javascript">
function downloadKbAttachmentFile(attachmentElementId, fileName, fileSize, mimeType, downloadBlockUrl, initializeUrl) {
// Download block API supports max 4MB block size
const blockSizeInBytes = 4096 * 1024;
const totalNumberOfBlocks = parseInt(fileSize / blockSizeInBytes + 1);
var fileContinuationToken = "";
var contentString = "";
var numberOfBlocksDownloaded = 0;
var blockNumberToContentMap = {};
function downloadBlockCallback(i, result) {
numberOfBlocksDownloaded++;
blockNumberToContentMap[i] = result;
if (numberOfBlocksDownloaded == totalNumberOfBlocks) {
for (var j = 0; j < totalNumberOfBlocks; j++) {
contentString += blockNumberToContentMap[j];
}
var isImage = mimeType.startsWith('image/');
const attachmentElement = document.getElementById(attachmentElementId);
if (isImage) {
const bodyByteString = atob(contentString);
const bodyBuffer = new ArrayBuffer(bodyByteString.length);
const bodyView = new Uint8Array(bodyBuffer);
for (var k = 0; k < bodyByteString.length; k++) {
bodyView[k] = bodyByteString.charCodeAt(k);
}
var imageUrl = URL.createObjectURL(new Blob([bodyBuffer], { type: mimeType }));
attachmentElement.href = imageUrl;
attachmentElement.target = "_blank";
}
else {
const linkSource = 'data:' + mimeType + ';base64,' + contentString;
attachmentElement.href = linkSource;
attachmentElement.download = fileName;
}
attachmentElement.click();
}
}
shell.ajaxSafePost({
type: 'GET',
url: initializeUrl,
success: function (result) {
fileContinuationToken = encodeURIComponent(result);
for (var i = 0; i < totalNumberOfBlocks; i++) {
url = downloadBlockUrl + "&blockNumber=" + i + "&fileContinuationToken=" + fileContinuationToken + "&blockSize=" + blockSizeInBytes;
var x = downloadBlockCallback.bind(this,i);
shell.ajaxSafePost({
type: 'GET',
url: url,
success: (result) => { x(result) }
});
}
}
});
}
</script>
- 选择“保存”。