Example #1
0
        internal static void RenderAttachmentLink(TextWriter output, AttachmentWellType wellType, AttachmentWellInfo attachmentInfoObject, string itemId, UserContext userContext, ArrayList previousAttachmentDisplayNames, AttachmentWell.AttachmentWellFlags flags, bool prependSemicolon = false)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (attachmentInfoObject == null)
            {
                throw new ArgumentNullException("attachmentInfoObject");
            }
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            if (string.IsNullOrEmpty(itemId))
            {
                throw new ArgumentException("itemId may not be null or empty string");
            }
            SanitizedHtmlString value = null;
            string fileExtension      = string.Empty;
            SanitizedHtmlString sanitizedHtmlString = null;

            AttachmentUtility.AttachmentLinkFlags attachmentLinkFlag = AttachmentUtility.GetAttachmentLinkFlag(wellType, attachmentInfoObject);
            if ((flags & AttachmentWell.AttachmentWellFlags.RenderReachedMaxEmbeddedDepth) != (AttachmentWell.AttachmentWellFlags) 0)
            {
                string format = "<a id=\"{0}\" href=\"#\" onclick=\"{1}\" title=\"{2}\">{3}";
                string text   = AttachmentUtility.TrimAttachmentDisplayName(attachmentInfoObject.AttachmentName, previousAttachmentDisplayNames, false);
                value = SanitizedHtmlString.Format(format, new object[]
                {
                    "lnkAtmt",
                    "return alert(L_ErrRchMxEmbDpth)",
                    attachmentInfoObject.AttachmentName,
                    text
                });
            }
            else
            {
                string format2 = "<a id=\"{0}\" href=\"attachment.ashx?attach=1&{1}\" target=_blank onclick=\"{2}\" title=\"{3}\">{4}";
                SanitizingStringBuilder <OwaHtml> sanitizingStringBuilder = new SanitizingStringBuilder <OwaHtml>();
                if (AttachmentWell.AttachmentWellFlags.RenderEmbeddedAttachment != (flags & AttachmentWell.AttachmentWellFlags.RenderEmbeddedAttachment))
                {
                    sanitizingStringBuilder.Append("id=");
                    sanitizingStringBuilder.Append(Utilities.UrlEncode(itemId));
                    sanitizingStringBuilder.Append("&attid0=");
                    sanitizingStringBuilder.Append(Utilities.UrlEncode(attachmentInfoObject.AttachmentId.ToBase64String()));
                    sanitizingStringBuilder.Append("&attcnt=1");
                }
                else
                {
                    sanitizingStringBuilder.Append(AttachmentWell.RenderEmbeddedQueryString(itemId));
                    sanitizingStringBuilder.Append(Utilities.UrlEncode(attachmentInfoObject.AttachmentId.ToBase64String()));
                }
                sanitizedHtmlString = sanitizingStringBuilder.ToSanitizedString <SanitizedHtmlString>();
                if (attachmentInfoObject.AttachmentLevel == AttachmentPolicy.Level.ForceSave)
                {
                    string text2 = AttachmentUtility.TrimAttachmentDisplayName(attachmentInfoObject.AttachmentName, previousAttachmentDisplayNames, false);
                    value = SanitizedHtmlString.Format(format2, new object[]
                    {
                        "lnkAtmt",
                        sanitizedHtmlString,
                        "return onClkAtmt(2)",
                        attachmentInfoObject.AttachmentName,
                        text2
                    });
                }
                if (attachmentInfoObject.AttachmentLevel == AttachmentPolicy.Level.Allow)
                {
                    string text3 = AttachmentUtility.TrimAttachmentDisplayName(attachmentInfoObject.AttachmentName, previousAttachmentDisplayNames, false);
                    value = SanitizedHtmlString.Format(format2, new object[]
                    {
                        "lnkAtmt",
                        sanitizedHtmlString,
                        "return onClkAtmt(3)",
                        attachmentInfoObject.AttachmentName,
                        text3
                    });
                }
            }
            if (prependSemicolon)
            {
                output.Write("; ");
            }
            output.Write("<span id=\"spnAtmt\" tabindex=\"-1\" level=\"");
            output.Write((int)attachmentInfoObject.AttachmentLevel);
            if (AttachmentUtility.AttachmentLinkFlags.AttachmentClickLink != (AttachmentUtility.AttachmentLinkFlags.AttachmentClickLink & attachmentLinkFlag) && (flags & AttachmentWell.AttachmentWellFlags.RenderReachedMaxEmbeddedDepth) == (AttachmentWell.AttachmentWellFlags) 0)
            {
                output.Write("\" class=\"dsbl");
            }
            output.Write("\">");
            output.Write("<img class=\"sI\" src=\"");
            if (attachmentInfoObject.FileExtension != null)
            {
                fileExtension = attachmentInfoObject.FileExtension;
            }
            SmallIconManager.RenderFileIconUrl(output, userContext, fileExtension);
            output.Write("\" alt=\"\">");
            if (AttachmentUtility.AttachmentLinkFlags.AttachmentClickLink == (AttachmentUtility.AttachmentLinkFlags.AttachmentClickLink & attachmentLinkFlag) || (flags & AttachmentWell.AttachmentWellFlags.RenderReachedMaxEmbeddedDepth) != (AttachmentWell.AttachmentWellFlags) 0)
            {
                output.Write(value);
            }
            else
            {
                Utilities.SanitizeHtmlEncode(AttachmentUtility.TrimAttachmentDisplayName(attachmentInfoObject.AttachmentName, previousAttachmentDisplayNames, false), output);
            }
            if (AttachmentWell.AttachmentWellFlags.RenderAttachmentSize == (flags & AttachmentWell.AttachmentWellFlags.RenderAttachmentSize))
            {
                long size = attachmentInfoObject.Size;
                if (size > 0L)
                {
                    output.Write(userContext.DirectionMark);
                    output.Write(" ");
                    output.Write(SanitizedHtmlString.FromStringId(6409762));
                    Utilities.RenderSizeWithUnits(output, size, true);
                    output.Write(userContext.DirectionMark);
                    output.Write(SanitizedHtmlString.FromStringId(-1023695022));
                }
            }
            output.Write("</a>");
            if (AttachmentUtility.AttachmentLinkFlags.OpenAsWebPageLink == (AttachmentUtility.AttachmentLinkFlags.OpenAsWebPageLink & attachmentLinkFlag))
            {
                output.Write("<span class=\"wvsn\">[<a id=\"wvLnk\" href=\"#\" onclick=\"");
                output.Write("opnWin('WebReadyView.aspx?t=att&");
                output.Write(sanitizedHtmlString);
                output.Write("')\">");
                output.Write(SanitizedHtmlString.FromStringId(1547877601));
                output.Write("</a>]</span>");
            }
            output.Write("</span>");
        }