03
2015
06

【C#、Asp.Net 工具类大全】创建显示图像的标签常用操作类

使用实例:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsP
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        flashInfo();
    }
}
/// <summary>
/// 创建显示图像的标签
/// </summary> ostBack)
    {
        flashInfo();
    }
}
/// <summary>
/// 创建显示图像的标签
/// </summary>
private void flashInfo()
{
    Response.Write(FlashHelper.CreateTag("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png", "百度Logo", "image/pjpeg") + "<br />");
    Response.Write(FlashHelper.CreateTag("http://www.webjx.com/files/media/liuyexiaoyu.swf", "测试Flash", "application/x-shockwave-flash") + "<br />");
    Response.Write(FlashHelper.CreateTag("http://5.26923.com/download/ring/000/105/dd3d8b7b3ea1ecaf31eaf29f746c356a.wma", "音乐测试", "audio/x-ms-wma") + "<br />");
    Response.Write(FlashHelper.CreateTag("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png", "百度Logo", "image/pjpeg", "http://www.baidu.com", 500, 350) + "<br />");
    Response.Write(FlashHelper.CreateTag("http://www.webjx.com/files/media/liuyexiaoyu.swf", "测试Flash", "application/x-shockwave-flash", "", 500, 350) + "<br />");
    Response.Write(FlashHelper.CreateTag("http://5.26923.com/download/ring/000/105/dd3d8b7b3ea1ecaf31eaf29f746c356a.wma", "音乐测试", "audio/x-ms-wma", "", 500, 350) + "<br />");
    Response.Write(FlashHelper.CreateTag2("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png", "百度Logo", "image/pjpeg", "http://www.baidu.com", 500, 350) + "<br />");
    Response.Write(FlashHelper.CreateTag2("http://www.webjx.com/files/media/liuyexiaoyu.swf", "测试Flash", "application/x-shockwave-flash", "", 500, 350) + "<br />");
    Response.Write(FlashHelper.CreateTag2("http://5.26923.com/download/ring/000/105/dd3d8b7b3ea1ecaf31eaf29f746c356a.wma", "音乐测试", "audio/x-ms-wma", "", 500, 350) + "<br />");
}

类库信息:

public class FlashHelper
{
    #region 创建显示图像的标签
    /// <summary>
    /// 创建显示图像的标签(重载),无宽高限制,(flash加点击)
    /// </summary>
    public static string CreateTag(string filename, string desc, string FileType)
    {
        StringBuilder TagStr = new StringBuilder();
        switch (FileType)
        {
            case "image/gif":
            case "image/bmp":
            case "image/pjpeg":
                { 
                    TagStr.Append(" <IMG alt=\"" + desc + "\"");
                    TagStr.Append(" src=\"" + filename + "\"");
                    TagStr.Append(" border=\"0\">");
                    break;
                }
            case "application/x-shockwave-flash":
                {
                    TagStr.Append("<object ");
                    TagStr.Append(" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"  ");
                    TagStr.Append(" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\"> ");
                    TagStr.Append(" <param name=\"wmode\" value=\"opaque\"> ");
                    TagStr.Append(" <param name=\"quality\" value=\"autohigh\"> ");
                    TagStr.Append(" <embed  ");
                    TagStr.Append(" src=\"" + filename);
                    TagStr.Append("\" ");
                    TagStr.Append(" quality=\"autohigh\" wmode=\"opaque\" type=\"application/x-shockwave-flash\"  ");
                    TagStr.Append(" plugspace=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"> ");
                    TagStr.Append(" </embed></object> ");
                }
                break;
            case "video/x-ms-wmv":
            case "video/mpeg":
            case "video/x-ms-asf":
            case "video/avi":
            case "audio/mpeg":
            case "audio/mid":
            case "audio/wav":
            case "audio/x-ms-wma":
                TagStr.Append("<embed");
                TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                break;
            default:
                break;
        }
        return TagStr.ToString();
    }
    /// <summary>
    /// 创建显示图像的标签(flash加点击)
    /// </summary>
    public static string CreateTag(string filename, string desc, string FileType, string LinkURL, int Width, int High)
    {
        StringBuilder TagStr = new StringBuilder();
        switch (FileType)
        {
            case "image/gif":
            case "image/bmp":
            case "image/pjpeg":
                {
                    if ((LinkURL.Trim() != "") && (LinkURL.Trim() != "http://"))//非空
                    {
                        TagStr.Append("<a href=\"" + LinkURL);
                        TagStr.Append("\"");
                        TagStr.Append(" target=\"_blank\">");
                    }
                    TagStr.Append(" <IMG alt=\"" + desc + "\"");
                    TagStr.Append(" src=\"" + filename + "\"");
                    TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\" ");
                    TagStr.Append(" border=\"0\">");
                    if ((LinkURL.Trim() != "") && (LinkURL.Trim() != "http://"))
                    {
                        TagStr.Append("</a>");
                    }
                    break;
                }
            case "application/x-shockwave-flash":
                {
                    TagStr.Append(" <embed ");
                    TagStr.Append(" src=\"" + filename + "\" ");
                    TagStr.Append(" width=" + Width + " height=" + High + "  ");
                    TagStr.Append(" quality=\"high\" ");
                    TagStr.Append(" ></embed>");
                }
                break;
            case "video/x-ms-wmv":
            case "video/mpeg":
            case "video/x-ms-asf":
            case "video/avi":
            case "audio/mpeg":
            case "audio/mid":
            case "audio/wav":
            case "audio/x-ms-wma":
                TagStr.Append("<embed");
                TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\"");
                TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                break;
            default:
                break;
        }
        return TagStr.ToString();
    }
    /// <summary>
    /// 创建显示图像的标签(flash无点击)
    /// </summary>
    public static string CreateTag2(string filename, string desc, string FileType, string LinkURL, int Width, int High)
    {
        StringBuilder TagStr = new StringBuilder();
        switch (FileType)
        {
            case "image/gif":
            case "image/bmp":
            case "image/pjpeg":
                {
                    TagStr.Append("<a href=\"" + LinkURL);
                    TagStr.Append("\"");
                    TagStr.Append(" target=\"_blank\">");
                    TagStr.Append(" <IMG alt=\"" + desc + "\"");
                    TagStr.Append(" src=\"" + filename + "\"");
                    TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\" ");
                    TagStr.Append(" border=\"0\">");
                    TagStr.Append("</a>");
                    break;
                }
            case "application/x-shockwave-flash":
                {
                    TagStr.Append(" <embed src=\"" + filename + "\" ");
                    TagStr.Append(" quality=\"high\" bgcolor=\"#f5f5f5\" ");
                    TagStr.Append(" ></embed>");
                }
                break;
            case "video/x-ms-wmv":
            case "video/mpeg":
            case "video/x-ms-asf":
            case "video/avi":
            case "audio/mpeg":
            case "audio/mid":
            case "audio/wav":
            case "audio/x-ms-wma":
                TagStr.Append("<embed");
                TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\"");
                TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                break;
            default:
                break;
        }
        return TagStr.ToString();
    }
    /// <summary>
    /// 创建显示图像的标签(重载),无宽高限制,(flash无点击)
    /// </summary>
    public static string CreateTag2(string filename, string desc, string FileType, string LinkURL)
    {
        StringBuilder TagStr = new StringBuilder();
        switch (FileType)
        {
            case "image/gif":
            case "image/bmp":
            case "image/pjpeg":
                {
                    TagStr.Append("<a href=\"" + LinkURL);
                    TagStr.Append("\"");
                    TagStr.Append(" target=\"_blank\">");
                    TagStr.Append(" <IMG alt=\"" + desc + "\"");
                    TagStr.Append(" src=\"" + filename + "\"");
                    TagStr.Append(" border=\"0\">");
                    TagStr.Append("</a>");
                    break;
                }
            case "application/x-shockwave-flash":
                {
                    TagStr.Append(" <embed src=\"" + filename + "\" ");
                    TagStr.Append(" quality=\"high\" bgcolor=\"#f5f5f5\" ");
                    TagStr.Append(" ></embed>");
                }
                break;
            case "video/x-ms-wmv":
            case "video/mpeg":
            case "video/x-ms-asf":
            case "video/avi":
            case "audio/mpeg":
            case "audio/mid":
            case "audio/wav":
            case "audio/x-ms-wma":
                TagStr.Append("<embed");
                TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                break;
            default:
                break;
        }
        return TagStr.ToString();
    }
    #region 创建显示图像的标签
    /// <summary>
    /// 创建显示图像的标签
    /// </summary>
    /// <param name="filename"></param>
    /// <param name="desc"></param>
    /// <param name="FileType"></param>
    /// <param name="LinkURL"></param>
    /// <param name="Width"></param>
    /// <param name="High"></param>
    /// <returns></returns>
    public static string CreateTagOld(string filename, string desc, string FileType, string LinkURL, int Width, int High)
    {
        StringBuilder TagStr = new StringBuilder();
        switch (FileType)
        {
            case "image/gif":
            case "image/bmp":
            case "image/pjpeg":
                {
                    TagStr.Append("<a href=\"" + LinkURL);
                    TagStr.Append("\"");
                    TagStr.Append(" target=\"_blank\">");
                    TagStr.Append(" <IMG alt=\"" + desc + "\"");
                    TagStr.Append(" src=\"" + filename + "\"");
                    TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\" border=\"0\">");
                    TagStr.Append("</a>");
                    break;
                }
            case "application/x-shockwave-flash":
                {
                    TagStr.Append("<a href=\"" + LinkURL);
                    TagStr.Append("\"");
                    TagStr.Append(" target=\"_blank\">");
                    TagStr.Append(" <embed src=\"" + filename + "\" ");
                    TagStr.Append(" quality=\"high\" bgcolor=\"#f5f5f5\"");
                    TagStr.Append(" ></embed>");
                    TagStr.Append("</a>");
                }
                break;
            case "video/x-ms-wmv":
            case "video/mpeg":
            case "video/x-ms-asf":
            case "video/avi":
            case "audio/mpeg":
            case "audio/mid":
            case "audio/wav":
            case "audio/x-ms-wma":
                TagStr.Append("<a href=\"" + LinkURL);
                TagStr.Append("\"");
                TagStr.Append(" target=\"_blank\">");
                TagStr.Append("<embed");
                TagStr.Append(" src=\"" + filename + "\" border=\"0\" width=\"" + Width + "\" height=\"" + High + "\"");
                TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                TagStr.Append("</a>");
                break;
            default://其他类型作为附件链接下载
                TagStr.Append("不允许该格式文件显示!");
                break;
        }
        return TagStr.ToString();
    }
    #endregion
    #endregion
}

显示效果:

以上类库内容来源互联网,站长稍作整理

« 上一篇下一篇 »

评论列表:

1.威客圈子  2015/6/3 13:40:52 回复该留言
纯干货,其它繁琐的都没有的

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。