ReadAttachment.aspx.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:2k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. namespace OThinker.H3.Portal
  12. {
  13.     public partial class ReadAttachment : OThinker.H3.Portal.PortalPage
  14.     {
  15.         private string AttachmentID
  16.         {
  17.             get
  18.             {
  19.                 string id = this.Request.QueryString[Param_AttachmentID];
  20.                 if (id == null || id == "")
  21.                 {
  22.                     return Data.Attachment.NullObjectID;
  23.                 }
  24.                 else
  25.                 {
  26.                     return id;
  27.                 }
  28.             }
  29.         }
  30.         protected void Page_Load(object sender, EventArgs e)
  31.         {
  32.             if (!this.IsPostBack)
  33.             {
  34.                 OThinker.H3.Data.Attachment attachment = OThinker.H3.Server.Engine.InstanceDataManager.GetAttachment(this.AttachmentID);
  35.                 
  36.                 if (attachment == null || attachment.Content == null || attachment.Content.Length == 0)
  37.                 {
  38.                     this.Response.Write("附件为空");
  39.                 }
  40.                 else
  41.                 {
  42.                     // 显示该文件
  43.                     this.Response.ContentType = attachment.ContentType;
  44.                     //设置响应头和下载保存的文件名              
  45.                     this.Response.AddHeader("Content-Disposition", "online;filename=" + HttpUtility.UrlEncode(attachment.FileName));
  46.                     // 显示内容
  47.                     this.Response.BinaryWrite(attachment.Content);
  48.                     this.Response.End();
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }