我正在使用用于Kentico 12的Kentico Import Toolkit进行导入。
我的目的是将CSV文件中的内容导入Kentico中的页面。它从根本上是可行的,但是,我无法在文件系统上获取PDF并将其作为二进制对象引入Kentico页面属性。
在我的CSV文件中,我有一列名为“ FileName”,在Kentico中,我有一个页面类型为“ Asset”,其页面属性为“ File”,其属性为File。
在我的列映射中,我将“ File”属性映射如下:
#<file>c:\temp\filesfortesting\{%FileName%}
运行导入并创建页面,但是实际上没有文件被导入并映射到页面上的File属性。
关于如何解决此问题的任何建议?我有对应的地图吗?
答案 0 :(得分:0)
我想您要导入的是page attachment。在这种情况下,您需要先导入页面,然后在第二次运行中导入页面附件。创建一个简单的工具并使用API进行迁移可能会更容易。
首先,我将澄清Kentico中附件的类型:
未排序的附件:这些附件是通过例如 所见即所得编辑器,可在页面的属性->附件中找到 标签
分组附件:这些是使用 附件表单控件。您可以更改附件的顺序 然后您可以在“表单”标签上对其进行管理
CMS.File和直接文件字段附件:这些是文件 使用直接上载器表单将其上载到“表单”选项卡上的页面 控制。
因此,在导入工具包中,您将选择要导入的页面附件,然后配置源并将附件导入到CMS_Attachment表中。
导入工具包仅支持导入未排序附件。因此,如果您要移动附件,则可能需要多次运行并执行一些API代码。
导入附件时,您需要设置WHERE条件以匹配您的页面,在我的情况下,我使用的是/ news /%path:
条件:
AttachmentDocumentID IN (SELECT DocumentID FROM CMS_Document WHERE DocumentNamePath LIKE '/news/%')
然后,选择一些虚拟页面,在其中导入所有附件。记得? KIT会将附件导入为未排序。在这种情况下,我使用了 / news 父页面和 DocumentID = 1063 ,因此所有附件都分配到了该页面。
然后,执行与此类似的代码以将附件移至相应页面:
// 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();
}
}
}