Пример #1
0
    protected void btn_OK_Click(object sender, EventArgs e)
    {
        #region 帖子的回复

        #region 添加帖子的回复
        BBS_ForumReplyBLL replybll = new BBS_ForumReplyBLL();
        replybll.Model.ItemID    = Convert.ToInt32(ViewState["ItemID"]);
        replybll.Model.Title     = Title.Value;
        replybll.Model.Content   = ckedit_content.Text;
        replybll.Model.Replyer   = Session["UserName"].ToString();
        replybll.Model.ReplyTime = DateTime.Now;
        replybll.Model.IPAddress = Request.ServerVariables.Get("REMOTE_ADDR").ToString();
        int replyid = replybll.Add();    // 返回已经回复的帖子的ID

        //修改论坛文章的留言量
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL(Convert.ToInt32(ViewState["ItemID"]));
        itembll.UpdateAddReplyTimes(Convert.ToInt32(ViewState["ItemID"]));
        #endregion

        #region 添加留言的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~"))
                {
                    path = Server.MapPath(path);
                }
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[]     buff   = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path   = "";
                att.ItemID = (int)ViewState["ItemID"];

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream         s             = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024)
                            {
                                width = 1024;
                            }

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize             = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                att.Reply = replyid;
                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string uploadcontent  = "";    //插入主表中

                switch (att.ExtName.ToLower())
                {
                case "jpg":
                case "gif":
                case "bmp":
                case "png":
                    uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                    break;

                case "mp3":
                    uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "avi":
                    uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "swf":
                    uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                    break;

                default:
                    uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                    break;
                }
                ViewState["Content"] += uploadcontent + "<br/>";
            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到回复主表中去
            replybll.Model.Content += "<br/><font color=red><b>附件列表:</b></font><br/>" + ViewState["Content"].ToString();
            replybll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                this.lbx_AttList.Items.RemoveAt(i);
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        #endregion

        Response.Redirect("display.aspx?ID=" + ViewState["ItemID"].ToString() + "&BoardID=" + ViewState["BoardID"].ToString());
    }
    private void Download(Guid id)
    {
        BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL(id);
        if (bll == null) Response.End();

        Response.Clear();

        #region 确定ContentType
        switch (bll.Model.ExtName.ToLower())
        {
            case "jpg":
            case "jpeg":
            case "jpe":
                Response.ContentType = "image/jpeg";
                break;
            case "gif":
                Response.ContentType = "image/gif";
                break;
            case "bmp":
                Response.ContentType = "image/bmp";
                break;
            case "png":
                Response.ContentType = "image/png";
                break;
            case "tiff":
            case "tif":
                Response.ContentType = "image/tiff";
                break;
            case "doc":
            case "docx":
                Response.ContentType = "application/ms-word";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
                break;
            case "xls":
            case "xlsx":
                Response.ContentType = "application/ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
                break;
            case "ppt":
            case "pptx":
                Response.ContentType = "application/ms-powerpoint";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
                break;
            case "pdf":
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
                break;
            case "zip":
                Response.ContentType = "application/zip";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
                break;
            case "rar":
                Response.ContentType = "application/rar";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
                break;
            case "txt":
                Response.ContentType = "text/plain";
                break;
            case "htm":
            case "html":
                Response.ContentType = "text/html";
                break;
            default:
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
                break;
        }
        #endregion

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetData();
            if (data != null) Response.OutputStream.Write(data, 0, data.Length);
        }
        else
        {
            string filepath = bll.Model.Path;

            if (filepath.StartsWith("~") || filepath.StartsWith("AttachFiles")) filepath = Server.MapPath(filepath);

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, @"附件在服务器上不存在!", this.ResolveClientUrl("~/SubModule/desktop.aspx"));
                return;
            }

            Response.WriteFile(filepath);
        }

        Response.Flush();
        Response.End();
    }
Пример #3
0
    protected void cmdOK_ServerClick(object sender, System.EventArgs e)
    {
        #region 添加论文的主题内容
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL();
        itembll.Model.Board         = Convert.ToInt32(ViewState["BoardID"]);
        itembll.Model.Title         = Title.Value;
        itembll.Model.Content       = ckedit_content.Text;
        itembll.Model.Sender        = Session["UserName"].ToString();
        itembll.Model.SendTime      = DateTime.Now;
        itembll.Model.HitTimes      = 0;                                   //点击次数默认的设置为0
        itembll.Model.ReplyTimes    = 0;                                   //回复次数默认的设置为0
        itembll.Model.LastReplyer   = Session["UserName"].ToString();      //默认的设置为本人
        itembll.Model.LastReplyTime = DateTime.Now;
        itembll.Model.IPAddr        = Request.ServerVariables.Get("REMOTE_ADDR").ToString();

        itembll.Model["IsTop"]  = "N"; //是否置顶
        itembll.Model["IsPith"] = "N"; //是否是精贴

        int itemid = itembll.Add();    // 返回已经发布的论文的ID
        #endregion

        #region 添加论文的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            string _content = "<br/><font color=red><b>附件列表:</b></font><br/>";

            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~"))
                {
                    path = Server.MapPath(path);
                }
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[]     buff   = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path   = "";
                att.ItemID = itemid;

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream         s             = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024)
                            {
                                width = 1024;
                            }

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize             = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string _uploadcontent = "";     //插入主表中

                switch (att.ExtName.ToLower())
                {
                case "jpg":
                case "gif":
                case "bmp":
                case "png":
                    _uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                    break;

                case "mp3":
                    _uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "avi":
                    _uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "swf":
                    _uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                    break;

                default:
                    _uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                    break;
                }
                _content += _uploadcontent + "<br/>";
            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到发帖主表中去
            itembll.Model.Content += _content;
            itembll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        Server.Transfer("listview.aspx?Board=" + ViewState["BoardID"].ToString());
    }
Пример #4
0
    protected void btn_OK_Click(object sender, EventArgs e)
    {
        #region 帖子的回复

        #region 添加帖子的回复
        BBS_ForumReplyBLL replybll = new BBS_ForumReplyBLL();
        replybll.Model.ItemID = Convert.ToInt32(ViewState["ItemID"]);
        replybll.Model.Title = Title.Value;
        replybll.Model.Content =ckedit_content.Text;
        replybll.Model.Replyer = Session["UserName"].ToString();
        replybll.Model.ReplyTime = DateTime.Now;
        replybll.Model.IPAddress = Request.ServerVariables.Get("REMOTE_ADDR").ToString();
        int replyid = replybll.Add();    // 返回已经回复的帖子的ID

        //修改论坛文章的留言量
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL(Convert.ToInt32(ViewState["ItemID"]));
        itembll.UpdateAddReplyTimes(Convert.ToInt32(ViewState["ItemID"]));
        #endregion

        #region 添加留言的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~")) path = Server.MapPath(path);
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[] buff = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path = "";
                att.ItemID = (int)ViewState["ItemID"];

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream s = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024) width = 1024;

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                att.Reply = replyid;
                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string uploadcontent = "";     //插入主表中

                switch (att.ExtName.ToLower())
                {
                    case "jpg":
                    case "gif":
                    case "bmp":
                    case "png":
                        uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                        break;
                    case "mp3":
                        uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                        break;
                    case "avi":
                        uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                        break;
                    case "swf":
                        uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                        break;
                    default:
                        uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                        break;
                }
                ViewState["Content"] += uploadcontent + "<br/>";

            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到回复主表中去
            replybll.Model.Content += "<br/><font color=red><b>附件列表:</b></font><br/>" + ViewState["Content"].ToString();
            replybll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                this.lbx_AttList.Items.RemoveAt(i);
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        #endregion

        Response.Redirect("display.aspx?ID=" + ViewState["ItemID"].ToString() + "&BoardID=" + ViewState["BoardID"].ToString());
    }
Пример #5
0
    protected void cmdOK_ServerClick(object sender, System.EventArgs e)
    {
        #region 添加论文的主题内容
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL();
        itembll.Model.Board = Convert.ToInt32(ViewState["BoardID"]);
        itembll.Model.Title = Title.Value;
        itembll.Model.Content = ckedit_content.Text;
        itembll.Model.Sender = Session["UserName"].ToString();
        itembll.Model.SendTime = DateTime.Now;
        itembll.Model.HitTimes = 0;                                        //点击次数默认的设置为0
        itembll.Model.ReplyTimes = 0;                                      //回复次数默认的设置为0
        itembll.Model.LastReplyer = Session["UserName"].ToString();        //默认的设置为本人
        itembll.Model.LastReplyTime = DateTime.Now;
        itembll.Model.IPAddr = Request.ServerVariables.Get("REMOTE_ADDR").ToString();

        itembll.Model["IsTop"] = "N";       //是否置顶
        itembll.Model["IsPith"] = "N";      //是否是精贴

        int itemid = itembll.Add();// 返回已经发布的论文的ID
        #endregion

        #region 添加论文的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            string _content = "<br/><font color=red><b>附件列表:</b></font><br/>";

            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~")) path = Server.MapPath(path);
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[] buff = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path = "";
                att.ItemID = itemid;

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream s = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024) width = 1024;

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string _uploadcontent = "";     //插入主表中

                switch (att.ExtName.ToLower())
                {
                    case "jpg":
                    case "gif":
                    case "bmp":
                    case "png":
                        _uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                        break;
                    case "mp3":
                        _uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                        break;
                    case "avi":
                        _uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                        break;
                    case "swf":
                        _uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                        break;
                    default:
                        _uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                        break;
                }
                _content += _uploadcontent + "<br/>";
            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到发帖主表中去
            itembll.Model.Content += _content;
            itembll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        Server.Transfer("listview.aspx?Board=" + ViewState["BoardID"].ToString());
    }
Пример #6
0
    private void Download(Guid id)
    {
        BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL(id);

        if (bll == null)
        {
            Response.End();
        }

        Response.Clear();

        #region 确定ContentType
        switch (bll.Model.ExtName.ToLower())
        {
        case "jpg":
        case "jpeg":
        case "jpe":
            Response.ContentType = "image/jpeg";
            break;

        case "gif":
            Response.ContentType = "image/gif";
            break;

        case "bmp":
            Response.ContentType = "image/bmp";
            break;

        case "png":
            Response.ContentType = "image/png";
            break;

        case "tiff":
        case "tif":
            Response.ContentType = "image/tiff";
            break;

        case "doc":
        case "docx":
            Response.ContentType = "application/ms-word";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
            break;

        case "xls":
        case "xlsx":
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
            break;

        case "ppt":
        case "pptx":
            Response.ContentType = "application/ms-powerpoint";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
            break;

        case "pdf":
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
            break;

        case "zip":
            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
            break;

        case "rar":
            Response.ContentType = "application/rar";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
            break;

        case "txt":
            Response.ContentType = "text/plain";
            break;

        case "htm":
        case "html":
            Response.ContentType = "text/html";
            break;

        default:
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            Response.AppendHeader("Content-Length", bll.Model.FileSize.ToString());
            break;
        }
        #endregion

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetData();
            if (data != null)
            {
                Response.OutputStream.Write(data, 0, data.Length);
            }
        }
        else
        {
            string filepath = bll.Model.Path;

            if (filepath.StartsWith("~") || filepath.StartsWith("AttachFiles"))
            {
                filepath = Server.MapPath(filepath);
            }

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, @"附件在服务器上不存在!", this.ResolveClientUrl("~/SubModule/desktop.aspx"));
                return;
            }

            Response.WriteFile(filepath);
        }


        Response.Flush();
        Response.End();
    }