Csharp:user WebControl Read Adobe PDF Files In Your Web Browser_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Csharp:user WebControl Read Adobe PDF Files In Your Web Browser

Csharp:user WebControl Read Adobe PDF Files In Your Web Browser

 2013/10/10 18:29:45  ?Geovin Du Dream Park?  博客园  我要评论(0)
  • 摘要:namespaceGeovinDu.PdfViewer{[DefaultProperty("FilePath")][ToolboxData("<{0}:ShowPdfrunat=server></{0}:ShowPdf>")]publicclassShowPdf:WebControl{#region"Declarations"//GeovinDu塗聚文20131010privatestringmFilePath
  • 标签:file files Web ARP Adobe
class="brush:csharp;gutter:true;">namespace GeovinDu.PdfViewer
{
    [DefaultProperty("FilePath")]
    [ToolboxData("<{0}:ShowPdf runat=server></{0}:ShowPdf>")]   
    public class ShowPdf : WebControl
    {
        
#region "Declarations" 
        //Geovin Du 塗聚文 20131010
        private string mFilePath;

#endregion



        #region "Properties" 

        [Category("Source File")]
        [Browsable(true)]
        [Description("Set path to source file.")]
        [Editor(typeof(System.Web.UI.Design.UrlEditor), typeof(System.Drawing.Design.UITypeEditor))]
        public string FilePath
        {
            get
            {
                return mFilePath;
            }
            set
            {
                if (value == string.Empty)
                {
                    mFilePath = string.Empty;
                }
                else
                {
                    int tilde = -1;
                    tilde = value.IndexOf('~');
                    if (tilde != -1)
                    {
                        mFilePath = value.Substring((tilde + 2)).Trim();
                    }
                    else
                    {
                        mFilePath = value;
                    }
                }
            }
        }   // end FilePath property


#endregion


        
#region "Rendering"
        /// <summary>
        ///  Geovin Du 塗聚文 20131010
        /// </summary>
        /// <param name="writer"></param>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<iframe src=" + FilePath.ToString() + " ");
                sb.Append("width=" + Width.ToString() + " height=" + Height.ToString() + " ");
                sb.Append("<View PDF: <a href=" + FilePath.ToString() + "</a></p> ");
                sb.Append("</iframe>");

                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.Write(sb.ToString());
                writer.RenderEndTag();
            }
            catch
            {
                // with no properties set, this will render "Display PDF Control" in a
                // a box on the page
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.Write("Display PDF Control");
                writer.RenderEndTag();
            }  // end try-catch
        }   // end RenderContents


        #endregion

    }   // end class
}       // end namespace  Geovin Du 塗聚文 20131010

 

发表评论
用户名: 匿名