【问题标题】:Save a Image using ContentService in Umbraco在 Umbraco 中使用 ContentService 保存图像
【发布时间】:2014-06-17 07:11:31
【问题描述】:

我想在 umbraco 中使用 contentservice 添加图像,可以简单地使用 setValue 方法完成,我需要将什么传递给 setValue 方法?

【问题讨论】:

    标签: umbraco umbraco6 umbraco7


    【解决方案1】:

    您应该使用MediaService 而不是内容服务。

    // check ApplicationContext.Current != null
    var ms = ApplicationContext.Current.Services.MediaService;
    var newMediaItem = ms.CreateMedia(file.FileName, <parentId>, Constants.Conventions.MediaTypes.Image);
    newMediaItem.SetValue(Constants.Conventions.Media.File, file);
    ms.Save(newMediaItem);  
    

    【讨论】:

    • ms.Save(mimage); ?我认为这里的“mimage”应该是“newMediaItem”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 2015-11-20
    相关资源
    最近更新 更多