Ejemplo n.º 1
0
        protected override void OnPreRender(EventArgs e)
        {
            if (Resource != null)
            {
                // build a definition list just for this item
                using (HtmlGenericControl dl = new HtmlGenericControl("dl"))
                {
                    using (HtmlGenericControl dt = new HtmlGenericControl("dt"))
                    {
                        using (HtmlGenericControl dd = new HtmlGenericControl("dd"))
                        {
                            dl.Controls.Add(dt);
                            dl.Controls.Add(dd);

                            // get file extension
                            string format = Resource.Values["umbracoExtension"].Replace(".", "").ToLower(CultureInfo.CurrentCulture);
                            dt.Attributes["class"] = format;

                            // link to file using name of format
                            using (HtmlAnchor link = new HtmlAnchor())
                            {
                                switch (format)
                                {
                                case "rtf":
                                    format = "Rich text";
                                    link.Attributes["type"] = "application/rtf";
                                    break;

                                case "doc":
                                    format = "Word";
                                    link.Attributes["type"] = "application/msword";
                                    break;

                                case "xls":
                                    format = "Excel";
                                    link.Attributes["type"] = "application/excel";
                                    break;

                                case "pdf":
                                    format = "Acrobat (PDF)";
                                    link.Attributes["type"] = "application/pdf";
                                    break;

                                case "ppt":
                                    format = "PowerPoint";
                                    link.Attributes["type"] = "application/powerpoint";
                                    break;

                                case "xml":
                                    format = "XML";
                                    link.Attributes["type"] = "text/xml";
                                    break;

                                default:
                                    format = "Alternative format";
                                    break;
                                }
                                link.HRef      = AttachmentUrl.ToString();
                                link.InnerText = Resource.Name;
                                link.Title     = "View '" + link.InnerText + "' in " + format + " format";
                                dt.Controls.Add(link);
                            }

                            // display the description, if present
                            if (Resource.Values.ContainsKey("Description") && !String.IsNullOrEmpty(Resource.Values["Description"]))
                            {
                                dd.InnerHtml = HttpUtility.HtmlEncode(Resource.Values["Description"]);
                                dd.Visible   = true;
                            }
                            else
                            {
                                dd.Visible = false;
                            }
                        }
                    }
                    this.Controls.Add(dl);
                }
                this.Visible = true;
            }
            else
            {
                this.Visible = false;
            }
        }
Ejemplo n.º 2
0
        protected override void OnPreRender(EventArgs e)
        {
            if (Resource != null)
            {
                // get file extension
                string format = Resource.Values["umbracoExtension"].ToLower(CultureInfo.CurrentCulture);

                // start with icon for file format
                using (HtmlGenericControl also = new HtmlGenericControl("span"))
                {
                    also.Attributes.Add("class", "downloadAlso");
                    also.InnerText = "Also in: ";
                    this.Controls.Add(also);
                }

                // link to file using name of format
                using (HtmlAnchor link = new HtmlAnchor())
                {
                    link.Title = "View "; // default action
                    switch (format)
                    {
                    case "rtf":
                        link.InnerText          = "Rich text";
                        link.Attributes["type"] = "application/rtf";
                        break;

                    case "doc":
                        link.InnerText          = "Word";
                        link.Attributes["type"] = "application/msword";
                        break;

                    case "xls":
                        link.InnerText          = "Excel";
                        link.Attributes["type"] = "application/excel";
                        break;

                    case "pdf":
                        link.InnerText          = "Acrobat (PDF)";
                        link.Attributes["type"] = "application/pdf";
                        break;

                    case "ppt":
                        link.InnerText          = "PowerPoint";
                        link.Attributes["type"] = "application/powerpoint";
                        break;

                    case "mp3":
                        link.InnerText          = "MP3";
                        link.Attributes["type"] = "audio/mpeg3";
                        link.Title = "Listen to ";     // change action
                        break;

                    case "wma":
                        link.InnerText          = "Windows Media";
                        link.Attributes["type"] = "audio/x-ms-wma";
                        link.Title = "Listen to ";     // change action
                        break;

                    case "xml":
                        link.InnerText          = "XML";
                        link.Attributes["type"] = "text/xml";
                        break;

                    default:
                        link.InnerText = "Alternative format";
                        break;
                    }
                    link.Attributes["class"] = format + " no-meta";
                    link.HRef = AttachmentUrl.ToString();
                    string docTitle = "'" + Resource.Name + "'";
                    link.Title += docTitle + " in " + link.InnerText + " format";
                    this.Controls.Add(link);


                    // display the file size in brackets
                    string size = CmsUtilities.GetResourceFileSize(Resource);
                    if (size.Length > 0)
                    {
                        using (var sizeElement = new HtmlGenericControl("span"))
                        {
                            ;
                            sizeElement.InnerText = " (" + size + ")";
                            sizeElement.Attributes.Add("class", "downloadSize");
                            link.Controls.Add(sizeElement);
                        }
                    }
                }
                this.Visible = true;
            }
            else
            {
                this.Visible = false;
            }
        }