我们正在使用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中。有人知道我做错了什么吗?
发布于 2016-04-14 21:49:38
看肯蒂科的我提供的答案 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();发布于 2016-04-14 21:50:30
我认为这段代码不会对实际文件进行任何操作/处理--它只是将对该文件的引用保存到数据库中。如果要将其保存在文件系统中的特定位置,则必须实现适当的功能。请参阅一些使用附件的API的示例。
https://stackoverflow.com/questions/36632093
复制相似问题