失忆的硬盘

从服务器上传和下载

==============================================

上传

==============================================            

            GetDb_IT myGetDb_IT = new GetDb_IT();
            SqlDataReader dr;
            string mysql = "";
            string DB_Path="";
            string path = "";
            DB_Path = "Document/" + Path.GetFileName(myFU.PostedFile.FileName);
            mysql = "select 路径 from 文档管理 where 项目号='" + Session["PNO"].ToString() + "'";
            dr = myGetDb_IT.GetDataReader(mysql);
            if (dr.Read())
            {
                path = Server.MapPath(DB_Path);
                myFU.PostedFile.SaveAs(path); //保存文件
                myLBL.Text = "上传成功!";
                mysql = "update 文档管理 set 路径='" + DB_Path + "',上传人='" + HttpUtility.UrlDecode(Request.Cookies["User"].Value).ToString().Trim()+"',上传时间='"+System.DateTime.Now.ToShortDateString()+"' where 项目号='"+Session["PNO"].ToString()+"'";
                myGetDb_IT.Update(mysql);
            }
            dr.Close();
            myGetDb_IT.close();

 

===============================================

下载

===============================================

            string fileName = HttpUtility.UrlEncode("aaaa.xls").ToString();
            string filePath = Server.MapPath(dr["路径"].ToString());//路径
            FileInfo fileInfo = new FileInfo(filePath);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "binary");
            Response.ContentType = "application/octet-stream";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.WriteFile(fileInfo.FullName);
            Response.Flush();
            Response.End();

posted on 2009-02-20 15:54  失忆的硬盘  阅读(181)  评论(0编辑  收藏  举报