上传下载的代码

Posted on 2007-02-04 13:13  少林  阅读(210)  评论(0编辑  收藏  举报

 private void AttachDownLoad(int intAttachID)
  {
   string strAttachId = intAttachID.ToString();
   string strTable = "Subject_Attach";
   string strSQL = "select * from Subject_Attach where attachid="+strAttachId;
   DataRow objRow = DbTools.GetRow(strSQL);
   byte[] Buffer= (byte[])objRow["filebody"];

   if(!File.Exists(strDownloadPath+strTable+"_"+objRow["Attachid"].ToString()+".tmp"))
   {
    FileStream objFS=new FileStream(strDownloadPath +strTable+"_"+objRow["Attachid"].ToString() + ".tmp",FileMode.OpenOrCreate,FileAccess.Write);
    objFS.Write(Buffer,0,Buffer.Length);
    objFS.Close();
   }
   //Response.ContentType=objDtr["attach_extname"].ToString();
   Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(objRow["filename"].ToString(),System.Text.Encoding.UTF8));
   Response.WriteFile(strDownloadPath + strTable+"_" + objRow["Attachid"].ToString() + ".tmp");
   Response.Flush();
   Response.End();
  }
  #endregion

 

Copyright © 2024 少林
Powered by .NET 8.0 on Kubernetes