【问题标题】:How to programmatically add value to GeneralField in SiteCore如何以编程方式为 SiteCore 中的 GeneralField 添加值
【发布时间】:2012-09-14 11:22:11
【问题描述】:

我们正在尝试以编程方式向 SiteCore 添加值。其中一个字段是 GeneralLink。我们已经上传了一个可执行文件并试图将该文件链接到这个 GeneralLink 字段。但它不起作用。通过 SiteCore 编辑器,如果我们选择“插入链接”并选择可执行文件(在媒体库中),它就可以工作了。

【问题讨论】:

  • 那么你想做什么?通过 C# 链接还是通过 CMS 本身链接?
  • 您可以发布您用于进行字段更新的代码吗?

标签: sitecore


【解决方案1】:

找到上述问题的答案。下面是代码sn-p。

// Create the media item 

MediaItem mediaItem = mediaCreator.CreateFromFile(fileName, mediaCrtrOptions);

// Create the internal link

Sitecore.Data.Fields.LinkField link = newItem.Fields[fieldName];

// this should be your complete media library path

link.Url = mediaItem.MediaPath;

link.LinkType = "internal";

link.Target = "";

link.TargetID = mediaItem.ID;

这对我们有用。希望它能帮助更多有需要的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    • 2011-03-15
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    相关资源
    最近更新 更多