Пример #1
0
        public static IHtmlString Render(this IFileField field, string linkText, object attributes)
        {
            if (field.HasValue)
            {
                var sb = new StringBuilder();
                sb.Append("<a href=\"");
                sb.Append(HttpUtility.HtmlEncode(field.Url));
                sb.Append("\"");

                foreach (var attribute in attributes.GetType().GetProperties().Where(x => x.CanRead))
                {
                    var value = attribute.GetValue(attributes, null);

                    if (value == null)
                    {
                        continue;
                    }

                    sb.AppendFormat(" {0}=\"{1}\"", attribute.Name.Replace('_', '-'), HttpUtility.HtmlEncode(value));
                }

                sb.Append(">");
                sb.Append(linkText ?? field.Url);
                sb.Append("</a>");

                return(new MvcHtmlString(sb.ToString()));
            }

            return(new MvcHtmlString(string.Empty));
        }
Пример #2
0
        /// <summary>
        /// Renders a link to the file field as a hyperlink tag. Rendering directives in the Action parameter will construct the body of the link. You may add attributes to the link by adding them to the writer before invoking this method.
        /// </summary>
        public static void RenderFileFieldLink(this HtmlTextWriter writer, IFileField fileField, Action linkBody)
        {
            if (!fileField.HasValue) return;

            writer.AddAttribute("href", fileField.Url);
            writer.RenderBeginTag("a");
            linkBody();
            writer.RenderEndTag();
        }
        /// <summary>
        /// Attaches the HyperLink web control to a FileField as a download link. The control is set to not visible if the media item does not have a value and we aren't page editing. 
        /// </summary>
        public static void AttachToFileField(this HyperLink link, IFileField field)
        {
            if (!field.HasValue && !Sitecore.Context.PageMode.IsPageEditor)
            {
                link.Visible = false;
                return;
            }

            link.NavigateUrl = field.Url;
        }
Пример #4
0
        /// <summary>
        /// Attaches the HyperLink web control to a FileField as a download link. The control is set to not visible if the media item does not have a value and we aren't page editing.
        /// </summary>
        public static void AttachToFileField(this HyperLink link, IFileField field)
        {
            if (!field.HasValue && !Sitecore.Context.PageMode.IsExperienceEditor)
            {
                link.Visible = false;
                return;
            }

            link.NavigateUrl = field.Url;
        }
Пример #5
0
        /// <summary>
        /// Returns the value of the <see cref="IFileField">field</see> having the provided <see cref="System.String">name</see> as
        /// <see cref="System.Type">T</see>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fieldName">The <see cref="System.String">name</see> of the <see cref="IFileField">field</see>.</param>
        /// <returns>The value of the <see cref="IFileField">field</see> expressed as <see cref="System.Type">T</see>.</returns>
        public T Get <T>(string fieldName)
        {
            IFileField field = GetField(fieldName);

            if (field.Type == typeof(FileTable))
            {
                return((T)field);
            }
            if (field?.Value == null)
            {
                return(default);
        /// <summary>
        /// Renders a link to the file field as a hyperlink tag. Rendering directives in the Action parameter will construct the body of the link. You may add attributes to the link by adding them to the writer before invoking this method.
        /// </summary>
        public static void RenderFileFieldLink(this HtmlTextWriter writer, IFileField fileField, Action linkBody)
        {
            if (!fileField.HasValue)
            {
                return;
            }

            writer.AddAttribute("href", fileField.Url);
            writer.RenderBeginTag("a");
            linkBody();
            writer.RenderEndTag();
        }
Пример #7
0
 /// <summary>
 /// .ctor. Must be inherited.
 /// </summary>
 /// <param name="clone">The source <see cref="IFileField">field</see> to clone.</param>
 public FileFieldBase(IFileField clone)
 {
     Encoder       = clone.Encoder;
     Length        = clone.Length;
     Name          = clone.Name;
     Precision     = clone.Precision;
     StartPosition = clone.StartPosition;
     DataFormat    = clone.DataFormat;
     Type          = clone.Type;
     DataFormat    = clone.DataFormat;
     RightAlign    = clone.RightAlign;
     FillByte      = clone.FillByte;
     BoolAsString  = clone.BoolAsString;
 }
Пример #8
0
 /// <summary>
 /// .ctor. Create an instance of this object using the <see cref="IFileField">field</see> layout provided.
 /// </summary>
 /// <param name="field"></param>
 public SerializableField(IFileField field)
 {
     Name          = field.Name;
     Precision     = field.Precision;
     StartPosition = field.StartPosition;
     Length        = field.Length;
     BoolAsString  = field.BoolAsString;
     DataFormat    = field.DataFormat;
     RightAlign    = field.RightAlign;
     BoolAsString  = field.BoolAsString;
     FillByte      = field.FillByte;
     FillCharacter = field.FillCharacter;
     YearFirst     = field.YearFirst;
     Type          = field.Type.ToString();
 }
Пример #9
0
 /// <summary>
 /// .ctor. Creates a new instance of FileField.
 /// </summary>
 /// <param name="clone">The source <see cref="IFileField">field</see> to clone.</param>
 /// <param name="data">The <see cref="System.Array">array</see> of bytes to read.</param>
 public FileField(IFileField clone, byte[] data) : this(clone)
 {
     ByteValue = data;
 }
Пример #10
0
 /// <summary>
 /// .ctor. Creates a new instance of FileField.
 /// </summary>
 /// <param name="clone">The source <see cref="IFileField">field</see> to clone.</param>
 public FileField(IFileField clone) : base(clone)
 {
 }
Пример #11
0
 /// <summary>
 /// .ctor. Leaves <see cref="IFileConditional.Condition">Condition</see> property null.
 /// </summary>
 public FileConditional()
 {
     Fields = new IFileField[] { };
 }
Пример #12
0
 /// <summary>
 /// .ctor. Use as you would <see cref="System.Exception">System.Exception</see>.
 /// </summary>
 /// <param name="ex">The original <see cref="System.Exception">Exception</see> generated during field processing, passed to <see cref="System.Exception.InnerException">InnerException</see>.</param>
 /// <param name="field">The specific field <see cref="IFileField">(IFileField)</see> that generated the <see cref="System.Exception">Exception</see>.</param>
 public FieldException(System.Exception ex, IFileField field) : base(ex.Message, ex)
 {
     Field = field;
 }
Пример #13
0
 /// <summary>
 /// .ctor. Use as you would <see cref="System.Exception">System.Exception</see>.
 /// </summary>
 /// <param name="message">The <see cref="System.String">message</see> for the exception.</param>
 /// <param name="field">The specific field <see cref="IFileField">(IFileField)</see> that generated the <see cref="System.Exception">Exception</see>.</param>
 public FieldException(string message, IFileField field) : base(message)
 {
     Field = field;
 }
Пример #14
0
 public static IHtmlString Render(this IFileField field, string linkText = null, string cssClass = null)
 {
     return(Render(field, linkText, new { @class = cssClass }));
 }