我创建了一个创建到 MemoryStream 的 iTextSharp PDF 文件。但我现在需要将此文件传递给 Kentico 媒体库。
如果有人能告诉我如何做到这一点,我将不胜感激。我目前的代码是:
//Media Library Info - takes Media Library Name and Website Name
MediaLibraryInfo libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyLibrary", CMSContext.CurrentSiteName);
//Folder in Media Library where Item will be Inserted
string mediaLibraryFolder = folder;
//create media file info item - takes the relative path to the document, the library ID, and the folder name where the document will be located within the media library
MediaFileInfo fileInfo = new MediaFileInfo();
fileInfo.FileLibraryID = libraryInfo.LibraryID;
fileInfo.FileBinaryStream = file;
fileInfo.FileName = title.Replace(" ", "").Trim();
fileInfo.FileTitle = title;
fileInfo.FileDescription = description;
fileInfo.FileExtension = ".pdf";
fileInfo.FileMimeType = "application/pdf";
fileInfo.FilePath = String.Concat("/", folder, "/", title.Replace(" ", "").Trim(), ".pdf");
// Save media file info
MediaFileInfoProvider.ImportMediaFileInfo(fileInfo);
由于可空列(例如 FileSize、FileExtension 等),我不断收到数据库错误。由于我使用的是 MemoryStream,我找不到提供所有这些信息的方法。
我是否错误地将 MediaFileInfo API 与 MemoryStream 文件结合使用?