Link Properties

Link Properties

Link Properties

  • LinkType indicates whether the link is an internal, media, external, mailto, anchor, or javascript link
  • IsInternal indicates whether the link is an internal link
  • InternalPath is the full path to an internal link item
  • IsMediaLink indicates whether the link is a media link
  • MediaPath is the full path to a media item
  • TargetID is the ID of the item specified by internal or media links
  • TargetItem is the Sitecore.Data.Items.Item specified by an internal or media link
  • QueryString indicates the query string parameters to add to the URL
  • Anchor is the name attribute of the HTML element, without the hash (“#”)
  • Class is the class attribute of the HTML element
  • Target is the target attribute of the HTML element
  • Text is the text content of the HTML element
  • Title is the title attribute of the HTML element
  • URL is the URL of the link, except for media items where it indicates the path to the media item relative to /Sitecore/Media Library

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.LinkField
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil

Link Properties C# Web Control Code

//get General Links metadata item from context database using item guid
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("{BF877EFB-4A8B-4F6A-8198-415C1DAAD1C5}");
if (item == null) return;

Sitecore.Data.Fields.LinkField linkFld = item.Fields["internal link"];
if (linkFld == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
//using : for colon and   for space
output.Write("{0}: {1}", "Field", linkFld.InnerField.DisplayName);
output.RenderEndTag(); //P

//using true for line break
Sitecore.MainUtil.Out("Can Read? " + "<b>" + linkFld.InnerField.CanRead.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Can Write? " + "<b>" + linkFld.InnerField.CanWrite.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Contains Standard Value? " + "<b>" + linkFld.InnerField.ContainsStandardValue.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Definition: " + "<b>" + linkFld.InnerField.Definition.Name + "</b>", true);
Sitecore.MainUtil.Out("Description: " + "<b>" + linkFld.InnerField.Description + "</b>", true);
Sitecore.MainUtil.Out("Display Name: " + "<b>" + linkFld.InnerField.DisplayName + "</b>", true);
Sitecore.MainUtil.Out("Has Blob Stream? " + "<b>" + linkFld.InnerField.HasBlobStream.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Has Value? " + "<b>" + linkFld.InnerField.HasValue.ToString() + "</b>", true);
Sitecore.MainUtil.Out("ID: " + "<b>" + linkFld.InnerField.ID.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Contains Inherited Value? " + "<b>" + linkFld.InnerField.InheritedValue + "</b>", true);
Sitecore.MainUtil.Out("Is Blob Field? " + "<b>" + linkFld.InnerField.IsBlobField.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Has Been Modified? " + "<b>" + linkFld.InnerField.IsModified.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Key: " + "<b>" + linkFld.InnerField.Key + "</b>", true);
Sitecore.MainUtil.Out("Language: " + "<b>" + linkFld.InnerField.Language.Name + "</b>", true);
Sitecore.MainUtil.Out("Name: " + "<b>" + linkFld.InnerField.Name + "</b>", true);
Sitecore.MainUtil.Out("Reset Blank On? " + "<b>" + linkFld.InnerField.ResetBlank.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Section Name: " + "<b>" + linkFld.InnerField.Section + "</b>", true);
Sitecore.MainUtil.Out("Sort Order: " + "<b>" + linkFld.InnerField.Sortorder.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Shared? " + "<b>" + linkFld.InnerField.Shared.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Source: " + "<b>" + linkFld.InnerField.Source + "</b>", true);
Sitecore.MainUtil.Out("Title: " + "<b>" + linkFld.InnerField.Title + "</b>", true);
Sitecore.MainUtil.Out("Tooltip: " + "<b>" + linkFld.InnerField.ToolTip + "</b>", true);
Sitecore.MainUtil.Out("Translatable? " + "<b>" + linkFld.InnerField.Translatable.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Type: " + "<b>" + linkFld.InnerField.Type + "</b>", true);
Sitecore.MainUtil.Out("Type Key: " + "<b>" + linkFld.InnerField.TypeKey + "</b>", true);
Sitecore.MainUtil.Out("Unversioned? " + "<b>" + linkFld.InnerField.Unversioned.ToString() + "</b>", true);
Sitecore.MainUtil.Out("Validation Regex: " + "<b>" + linkFld.InnerField.Validation + "</b>", true);
Sitecore.MainUtil.Out("Validation Message: " + "<b>" + linkFld.InnerField.ValidationText + "</b>", true);
Sitecore.MainUtil.Out("Value: " + "<b>" + linkFld.InnerField.Value + "</b>", false);

output.RenderEndTag(); //Div