以编程方式将文件添加到 Kentico 媒体库
使用 CMSDesk 并单击“工具”选项卡,然后单击“媒体库”,我可以将文件添加到内置的 Kentico 媒体库。有没有办法使用他们的 API 来做到这一点?
Using CMSDesk and click on the Tools tab, then Media Library I can add files to the inbuilt Kentico Media Library. Is there a way to do this using their API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Kentico API 来完成此操作。它实际上非常丰富,但文档和示例有点缺乏。
以下是一个示例方法(实际上用作 Web 服务方法,因为我们有远程和本地页面都使用它)和调用它的示例方法(例如从“编辑”网页)。
文件徽标->受保护的System.Web.UI.WebControls.FileUpload fileLogo;
You can do this using the Kentico API. It is actually quite rich but the documentation and samples out there are a bit lacking.
Following is a sample method (actually used as a web service method as we have both remote and local pages that use it) and a sample method that calls it (say from an 'edit' web page).
fileLogo - > protected System.Web.UI.WebControls.FileUpload fileLogo;
将其保留为原始版本链接 似乎已失效。
发表于 2010 年 6 月 23 日,作者:kevin
那么,如果您曾经使用过基于 .NET 的 CMS Kentico (http://www.kentico.com),您就会知道媒体库可以是一个非常强大的工具用于组织非站点数据,包括图像、文档以及您需要存储并与 CMS 集成的任何其他内容。只要您不尝试在代码端对其进行任何操作,这一切都会非常有效。至少可以说,这就是事情变得有趣的地方。
Kentico 文档网站 (http://devnet.kentico.com/documentation.aspx) 非常它在使用和操作代码中的树方面很有用,但在一般媒体库的操作和使用方面提供的很少。因此,我花了很多时间浏览模块,看看 Kentico 做了什么以及它是如何做的,这样您就不必这样做了。
由于这是我的第一篇文章,而且我对整个“写作”的事情还有些生疏,所以让我们开始编写代码。
我认为这是非常不言自明的,我们创建一个 MediaFileInfo 对象,在其中设置一些内容,然后将其插入 MediaFileInfoProvider 中。 MediaFileInfo 对象中有许多附加属性,例如 FileSize,它(如属性名称所示)以 long 形式存储文件大小。专业提示 – 使用 CMS.GlobalHelper.DataHelper.GetSizeString 函数将 long 转换为字符串,并将其格式化为用户可读的数据。
这实际上只是触及了您可以在代码隐藏中使用媒体库执行的操作的表面。仔细查看
MediaFileInfo
和MediaFIleInfoProvider
类,以及MediaLibraryHelper
、MediaLibraryInfo
、MediaLibraryInfoProvider
类。没有什么是做不到的。Keeping it here as the original link seems to be dead.
Posted on June 23, 2010 by kevin
So, if you’ve ever worked with the .NET based CMS Kentico (http://www.kentico.com), you’ll know that Media Libraries can be a very powerful tool for organizing your non-site data, including images, documents, and anything else that you need storing and integrating with your CMS. And it all works fantastically, as long as you don’t try to do anything with it code-side. That’s where things get interesting, to say the least.
The Kentico documentation website (http://devnet.kentico.com/documentation.aspx) is very useful in terms of working with and manipulating the tree from the code, it offers very little in terms of manipulating and working-with in general with Media Libraries. So I spent a good amount of time looking through the Modules seeing what Kentico does and how it does it so you don’t have to.
Since this is my first post, and I’m still a little rusty on the whole “writing” thing, so let’s just get to the code.
I think this is pretty self explanatory, we create a MediaFileInfo object, set some stuff in it, and then insert it into the MediaFileInfoProvider. There are a lot of additional properties within the MediaFileInfo object, such as FileSize, which (as the name of the property suggests), stores the file size in a long. Pro tip – use the
CMS.GlobalHelper.DataHelper.GetSizeString
function to convert the long to a string, formatting it into user-readable data.This really just scratches the surface on what you can do with Media Libraries in the code-behind. Take a closer look at the
MediaFileInfo
andMediaFIleInfoProvider
classes, along with theMediaLibraryHelper
,MediaLibraryInfo
,MediaLibraryInfoProvider
classes. There’s very little that can’t be done.