Reputation: 73
We are trying to programmatically add values to SiteCore. One of the fields is a GeneralLink. We have uploaded an executable file and trying to link that file to this GeneralLink field. But it is not working. Through the SiteCore Editor, if we choose the 'Insert Link' and select the executable file (in the media library), it is working.
Upvotes: 2
Views: 2173
Reputation: 73
Found out the answer to the above question. Below is the code snippet.
// 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;
This worked for us. Hope it will help few more who are in need of this.
Upvotes: 4