无法使用导入工具包将文件导入页面

  • 本文关键字:导入 文件 工具包 kentico
  • 更新时间 :
  • 英文 :


我正在使用Kentico 12的Kentico Import Toolkit进行导入。

我的目的是将内容从CSV文件导入到Kentico的页面中。它基本上是有效的,但是,我无法让它在文件系统上获取 PDF 并将其作为二进制对象引入 Kentico 页面属性。

在我的CSV文件中,我有一个名为"文件名"的列,在Kentico中,我有一个名为"资产"的页面类型,该页面类型具有名为"文件"的属性,其类型为文件。

在我的列映射中,我映射了"File"属性,如下所示:

#<file>c:tempfilesfortesting{%FileName%}

导入将运行并创建页面,但实际上不会导入任何文件并将其映射到页面上的 File 属性。

关于如何解决此问题的任何建议? 我有映射权吗?

我想您要导入的是作为页面附件导入的。在这种情况下,您需要先导入页面,然后在第二次运行中导入页面附件。创建一个简单的工具并使用 API 进行迁移可能会更容易。

首先,我将澄清肯蒂科中的附件类型:

  • 未排序的附件:这些是通过例如添加的附件 所见即所得编辑器,可在页面的属性->附件中找到 标签

  • 分组附件:这些是使用 附件表单控件。您可以更改附件的顺序 并在"表单"选项卡上管理它们

  • 内容管理系统。文件和直接文件字段附件:这些是文件 使用直接上传者表单上传到"表单"选项卡上的页面 控制。

因此,在导入工具包中,您将选择要导入的页面附件,然后配置源并将附件导入CMS_Attachment表中。

导入工具包仅支持导入未排序的附件。因此,如果要移动附件,可能需要多次运行+执行一些API代码。 导入附件时,您需要设置 WHERE 条件以匹配您的页面,就我而言,我使用的是/news/% 路径: 其中条件:
AttachmentDocumentID IN (SELECT DocumentID FROM CMS_Document WHERE DocumentNamePath LIKE '/news/%')

然后,选择一些虚拟页面来导入所有附件。 还记得吗?KIT 将附件导入为未排序。在本例中,我使用了DocumentID = 1063的父/news页面,因此所有附件都分配给此页面。

然后,执行类似于以下内容的代码,将附件移动到相应的页面:

// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
// Gets  the parent page
TreeNode page = tree.SelectNodes()
.Path("/news")
.OnCurrentSite()
.Culture("en-us")
.TopN(1)
.FirstOrDefault();
if (page != null)
{
foreach (DocumentAttachment attachment in page.AllAttachments)
{
// Perform any action with the attachment object (DocumentAttachment), NewsTeaser is the target page’s direct file upload field where I want to get the attachment
TreeNode targetPage = tree.SelectNodes()
.Type("CMS.News")
.Where("NewsTeaser = '" + attachment.AttachmentGUID + "'")
.TopN(1)
.Culture("en-us")
.OnCurrentSite()
.FirstOrDefault();
if (targetPage != null)
{
// Edits the attachment's metadata (name, title and description) and set the right AttachmentDocumentID and AttachmentIsUnsorted to false
attachment.AttachmentDocumentID = targetPage.DocumentID;
attachment.AttachmentIsUnsorted = false;
// Ensures that the attachment can be updated without supplying its binary data
attachment.AllowPartialUpdate = true;
// Saves the modified attachment into the database
attachment.Update();
}
}
}

最新更新