无法使用导入工具包将文件导入页面
Can't import a file into a page using the import toolkit
我正在使用 Kentico 12 的 Kentico 导入工具包进行导入。
我的目的是将 CSV 文件中的内容导入到 Kentico 的页面中。它基本上可以工作,但是,我无法让它在文件系统上获取 PDF 并将其作为二进制对象引入 Kentico 页面 属性。
在我的 CSV 文件中,我有一个名为 "FileName" 的列,在 Kentico 中,我有一个名为 "Asset" 的页面类型,其中有一个名为 "File" 的 属性,它是文件类型。
在我的列映射中,我将 "File" 属性 映射如下:
#<file>c:\temp\filesfortesting\{%FileName%}
导入运行并创建了页面,但实际上没有文件导入并映射到页面上的文件 属性。
关于如何解决这个问题有什么建议吗?我的映射正确吗?
我猜你想导入是作为 page attachment. In this case, you need to import the pages first and then, in a second run import the page attachments.It might be easier to create a simple tool and use API 来做迁移。
首先我会明确Kentico中的附件类型:
未分类的附件:这些是通过例如添加的附件。
所见即所得编辑器,可在页面的属性 -> 附件中使用
选项卡
分组附件:这些是使用
附件表单控件。您可以更改附件的顺序
您可以在“表单”选项卡上管理它们
CMS.File 和直接文件字段附件:这些是文件
使用直接上传器表单上传到表单选项卡上的页面
控制.
因此,在导入工具包中,您将select要导入的页面附件,然后配置来源并将附件导入CMS_Attachmenttable。
导入工具包仅支持导入未排序 附件。因此,如果您想移动附件,您可能需要多次运行 + 执行一些 API 代码。
导入附件时,您需要设置 WHERE 条件以匹配您的页面,在我的例子中我使用的是 /news/% 路径:
其中条件:
AttachmentDocumentID IN (SELECT DocumentID FROM CMS_Document WHERE DocumentNamePath LIKE '/news/%')
然后,select 一些用于导入所有附件的虚拟页面。记住? 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();
}
}
}
我正在使用 Kentico 12 的 Kentico 导入工具包进行导入。
我的目的是将 CSV 文件中的内容导入到 Kentico 的页面中。它基本上可以工作,但是,我无法让它在文件系统上获取 PDF 并将其作为二进制对象引入 Kentico 页面 属性。
在我的 CSV 文件中,我有一个名为 "FileName" 的列,在 Kentico 中,我有一个名为 "Asset" 的页面类型,其中有一个名为 "File" 的 属性,它是文件类型。
在我的列映射中,我将 "File" 属性 映射如下:
#<file>c:\temp\filesfortesting\{%FileName%}
导入运行并创建了页面,但实际上没有文件导入并映射到页面上的文件 属性。
关于如何解决这个问题有什么建议吗?我的映射正确吗?
我猜你想导入是作为 page attachment. In this case, you need to import the pages first and then, in a second run import the page attachments.It might be easier to create a simple tool and use API 来做迁移。
首先我会明确Kentico中的附件类型:
未分类的附件:这些是通过例如添加的附件。 所见即所得编辑器,可在页面的属性 -> 附件中使用 选项卡
分组附件:这些是使用 附件表单控件。您可以更改附件的顺序 您可以在“表单”选项卡上管理它们
CMS.File 和直接文件字段附件:这些是文件 使用直接上传器表单上传到表单选项卡上的页面 控制.
因此,在导入工具包中,您将select要导入的页面附件,然后配置来源并将附件导入CMS_Attachmenttable。
导入工具包仅支持导入未排序 附件。因此,如果您想移动附件,您可能需要多次运行 + 执行一些 API 代码。
导入附件时,您需要设置 WHERE 条件以匹配您的页面,在我的例子中我使用的是 /news/% 路径:
其中条件:
AttachmentDocumentID IN (SELECT DocumentID FROM CMS_Document WHERE DocumentNamePath LIKE '/news/%')
然后,select 一些用于导入所有附件的虚拟页面。记住? 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();
}
}
}