如何在SQL SERVERK上存储一个文件呢?
还有就是一点.存在此SQL SERVER上是数据吧.我给用户下载时是用超级链接的.那在文件系统中没有这个文件我要如何才能下载呢?
就像SharePoint那样,他东西都在SQL SERVER上.但是它还能像下一个硬盘上有的文件一样下载它.这是怎么完成的呢?
还有就是一点.存在此SQL SERVER上是数据吧.我给用户下载时是用超级链接的.那在文件系统中没有这个文件我要如何才能下载呢?
就像SharePoint那样,他东西都在SQL SERVER上.但是它还能像下一个硬盘上有的文件一样下载它.这是怎么完成的呢?
<input type="file" id="importfile" runat="server" name="importfile">
用image来保存文件。
上传:(filecontent字段为image类型)
HttpFile hf = new HttpFile();
byte [] filebyte = hf.getFileByte(importfile.PostedFile);
SqlConnection con = new SqlConnection();
SqlCon sc = new SqlCon();
string constr = sc.getconstr();
con.ConnectionString = constr;
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select * from i_monthAnalyse",con);
SqlCommandBuilder Builder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet();
adapter.Fill(ds,"table");
DataRow newrow;
newrow = ds.Tables["table"].NewRow();
newrow["person"] = Session["logonperson"].ToString();
newrow["filename"] = hf.getFileName(importfile.PostedFile);
newrow["filecontent"] = filebyte;
newrow["filedate"] = DropDownList1.SelectedValue+"-"+DropDownList2.SelectedValue;
ds.Tables["table"].Rows.Add(newrow);
adapter.Update(ds,"table");
con.Close();
下载页面,把文件名做一个超联接到一个asp文件上:
asp文件如下:
Response.ContentType = "application/x-msdownload"Response.AddHeader "content-disposition", "attachment;filename=" & rs(0)
Response.BinaryWrite(rs(1).GetChunk(7500000))
rs(0)是文件名,rs(1)是image字段值