C# Kentico中的AddAttachment方法

C# Kentico中的AddAttachment方法,c#,attachment,kentico,C#,Attachment,Kentico,我们正在使用Kentico v9,并将博客文章从Wordpress导入Kentico。将附件导入博客帖子时遇到问题。以下是当前正在使用的代码: var attachmentNode = TreeNode.New(FILE_PAGE_TYPE); attachmentNode.DocumentName = filename; attachmentNode.DocumentCulture = postNode.DocumentCulture; attachmentNode.Insert(postNo

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

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中。有人知道我做错了什么吗?

请参阅Kentico DevNet中的

        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();
请参阅Kentico DevNet中的

        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();

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

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