Sitecore - 如何以编程方式更新FileDropAreaField?

时间:2016-10-25 05:49:52

标签: sitecore

有没有人知道如何在site-core和asp.net中以编程方式更新filedropareafield?
按照以下代码:

Prod.Editing.BeginEdit();
using (new EditContext(Prod))
{
     prod["image"]=
}

1 个答案:

答案 0 :(得分:0)

        var database = Sitecore.Configuration.Factory.GetDatabase("master");
        var item = database.GetItem("{5306CEEC-AE8F-43D5-BA97-9F9551B2E50B}");
        var field = (FileDropAreaField)item.Fields["FileDropArea"];
        using (new EditContext(item))
        {
            var mediaCreator = new Resources.Media.MediaCreator();
            MediaItem mediaItem = mediaCreator.CreateFromFile("D:\\Images\\myimage.jpg",
                        new MediaCreatorOptions()
                        {
                            FileBased = false,
                            Database = database,
                            IncludeExtensionInItemName = false,
                            Versioned = false,
                            Destination = "/sitecore/media library/imagefolder/uploaded/myimage",
                            Language = Language.Parse("en")
                        });
            field.ChangeMediaFolder(database.GetItem("/sitecore/media library/imagefolder/uploaded"));
        }

The answer on Sitecore community