84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using BLL;
|
|
|
|
namespace FineUIPro.Web.FileManager
|
|
{
|
|
public partial class Read : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
doGetDocData();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 从数据库或者磁盘中读取文件并发送给客户端
|
|
/// </summary>
|
|
public void doGetDocData()
|
|
{
|
|
SqlDataReader objReader = null;
|
|
SqlConnection conn = new SqlConnection(BLL.Funs.ConnString);
|
|
if (conn.State == ConnectionState.Closed) conn.Open();
|
|
try
|
|
{
|
|
string strcmd = string.Empty;
|
|
string docid = Request.QueryString["docid"];
|
|
string typeFlag = Request.QueryString["typeFlag"];
|
|
|
|
if (!string.IsNullOrEmpty(docid))
|
|
{
|
|
if (!string.IsNullOrEmpty(strcmd))
|
|
{
|
|
SqlCommand command = new SqlCommand(strcmd, conn);
|
|
command.CommandType = CommandType.Text;
|
|
objReader = command.ExecuteReader();
|
|
|
|
if (objReader.Read())
|
|
{
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + objReader[0].ToString());
|
|
Response.AppendHeader("Contenttype", "application/msword");
|
|
//读取数据
|
|
byte[] buffer = new Byte[10240];
|
|
long datalen = objReader.GetBytes(1, 0, null, 0, 0);//["filedata"]
|
|
//Response.Write("datalen=" + datalen.ToString());
|
|
//*
|
|
long curPos = 0;
|
|
long readsize = 0;
|
|
readsize = objReader.GetBytes(1, curPos, buffer, 0, 10240);
|
|
while (readsize == 10240)
|
|
{
|
|
curPos += readsize;
|
|
Response.BinaryWrite(buffer);
|
|
Response.Flush();
|
|
readsize = objReader.GetBytes(1, curPos, buffer, 0, 10240);
|
|
}
|
|
byte[] rBuf = new Byte[readsize];
|
|
objReader.GetBytes(1, curPos, rBuf, 0, (int)readsize);
|
|
Response.BinaryWrite(rBuf);
|
|
Response.Flush();
|
|
|
|
//*/
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
finally
|
|
{
|
|
if (objReader != null)
|
|
{
|
|
objReader.Close();
|
|
}
|
|
conn.Close();
|
|
}
|
|
}
|
|
}
|
|
} |