是啊,是将已经上传过的文件显示在网页中.我的代码是这样的.
protected void Page_Load(object sender, EventArgs e)
{
string ID = Request["ID"].ToString();
Label1.Text = ID;
Label1.Visible = false;
SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
meteor.Open();
SqlCommand comm = new SqlCommand("select uploadfile from studentinformation where studentname ='" + Label1.Text.ToString().Trim() + "'", meteor);
SqlDataReader dr = comm.ExecuteReader();
string tmp;
if (dr.Read())
{
tmp = dr["uploadfile"].ToString();
if (tmp.Length > 0)
{
show();
}
else
{
Response.Write("<script language=javascript>alert('对不起,该生简历不存在!');window.close()</script>");
}
}
meteor.Close();
}
private void show()
{
SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
meteor.Open();
SqlCommand comm = new SqlCommand("select * from studentinformation where studentname ='" + Label1.Text.ToString().Trim() + "'", meteor);
SqlDataReader dr = comm.ExecuteReader();
if (dr.Read())
{
Label2.Text = dr.GetString(17);
Label2.Visible = false;
}
meteor.Close();
string strFileUploadPath = Server.MapPath("~/upload/");
string strFileName = Label2.Text;
string FullFileName = strFileUploadPath + strFileName;
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader("Content-Disposition ", "attachment;filename= "
+ HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}