首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kentico中的AddAttachment方法

Kentico中的AddAttachment方法
EN

Stack Overflow用户
提问于 2016-04-14 19:20:12
回答 2查看 217关注 0票数 1

我们正在使用Kentico v9,并将博客文章从Wordpress导入到Kentico。我们在将附件导入博客文章时遇到了问题。下面是当前使用的代码:

代码语言:javascript
复制
var attachmentNode = TreeNode.New(FILE_PAGE_TYPE);
attachmentNode.DocumentName = filename;
attachmentNode.DocumentCulture = postNode.DocumentCulture;
attachmentNode.Insert(postNode);
DocumentHelper.AddAttachment(attachmentNode, "ce4c5d10-c143-4ada-9d8a-7e7481b167ef", localFileLocation, postNode.TreeProvider);
attachmentNode.Update();

这不会产生任何错误,而且该文件的数据库中有一个记录。然而,文件本身并不在Kentico中。有人知道我做错了什么吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-14 21:49:38

看肯蒂科的我提供的答案 DevNet。

代码语言:javascript
复制
        TreeNode newNode = TreeNode.New(PageType, tree);
        newNode.DocumentName = mediaFile.FileName;
        newNode.DocumentName = fileName.Trim();
        newNode.SetValue("FileDate", fileDate);
        DocumentHelper.InsertDocument(newNode, parentNode.NodeID);

        AttachmentInfo newAttachment = null;

        // Path to the file to be inserted. This example uses an explicitly defined file path. However, you can use an object of the HttpPostedFile type (uploaded via an upload control).
        string filePath = MediaLibraryPath + @"\" + mediaFile.FileName + mediaFile.FileExtension;

        // Insert the attachment and update the document with its GUID
        newAttachment = DocumentHelper.AddUnsortedAttachment(newNode, Guid.NewGuid(), filePath, tree, ImageHelper.AUTOSIZE, ImageHelper.AUTOSIZE, ImageHelper.AUTOSIZE);

        // attach the new attachment to the page/document
        newNode.SetValue("FileAttachment", newAttachment.AttachmentGUID);
        DocumentHelper.UpdateDocument(newNode);
        newNode.Publish();
票数 0
EN

Stack Overflow用户

发布于 2016-04-14 21:50:30

我认为这段代码不会对实际文件进行任何操作/处理--它只是将对该文件的引用保存到数据库中。如果要将其保存在文件系统中的特定位置,则必须实现适当的功能。请参阅一些使用附件的API的示例

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36632093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档