【问题标题】:Renaming Sitecore Media Item using c#使用 c# 重命名 Sitecore 媒体项目
【发布时间】:2015-04-14 18:52:01
【问题描述】:

我想重命名或想为上传的媒体项目命名,但它总是以未命名的项目(媒体)名称上传。以下是我的代码。

    public static void UploadImage(int customerID,FileUpload fup)
    {
        using (new SecurityDisabler())
        {
            var options = new Sitecore.Resources.Media.MediaCreatorOptions
            {
                AlternateText =customerID.ToString(),
                FileBased = false,
                IncludeExtensionInItemName = false,
                KeepExisting = false,
                Versioned = false,
                Destination = "/sitecore/media library/temp",
                Database = Sitecore.Configuration.Factory.GetDatabase("master")
            };

            var filepath =  HttpContext.Current.Server.MapPath(fup.FileName);
            var creator = new MediaCreator();
            var mediaItem = creator.CreateFromStream(fup.PostedFile.InputStream, filepath, options);
            MediaItem myFile = mediaItem;

            myFile.Name = customerID.ToString(); // unable to give becasue it read only

        }
    }

【问题讨论】:

    标签: c# asp.net sitecore


    【解决方案1】:

    尝试重命名前调用.InnerItem.Editing.BeginEdit(),重命名后调用.InnerItem.Editing.EndEdit()

    myFile.InnerItem.Editing.BeginEdit();
    myFile.InnerItem.Name = customerID.ToString();
    myFile.InnerItem.Editing.EndEdit();
    

    欲了解更多信息,请参阅章节3.1.5 How to Place an Item in Editing Modehttp://sdn.sitecore.net/upload/sitecore6/content_api_cookbook-a4.pdf

    【讨论】:

    • 我试过了。它给出了编译错误。因为它显示只读。
    • 查看编辑后的答案。也许.InnerItem 会为你工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    相关资源
    最近更新 更多