请问怎样将这段代码改成支持文档音频上传至数据库呀?
--------------------编程问答-------------------- web.config页面:<connectionStrings>
<add name="FileImageConnectionString" connectionString="Data Source=CGJ;Initial Catalog=FileImage;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings> --------------------编程问答-------------------- ImageUpload.aspx.cs页面(将图片转化为字节流,并保持至数据库中)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.IO;
public partial class ImageUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
byte[] content= FileToByte(FileUpload1.PostedFile.FileName);
SaveFile(content);
Response.Write("<script language='javascript'>alert('上传成功');</script>");
}
private byte[] FileToByte(string filePath)
{
byte[] ib = new Byte[60000];
string strfilepath = filePath;
FileStream fs = new FileStream(strfilepath, FileMode.Open, FileAccess.Read);
fs.Read(ib, 0, 60000);
return ib;
}
private void SaveFile(byte[] content)
{
StringBuilder strSQL = new StringBuilder();
SqlCommand cmd = new SqlCommand();
SqlParameter parm = new SqlParameter("@content", SqlDbType.Image);
parm.Value = content;
cmd.Parameters.Add(parm);
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
strSQL.Append("INSERT INTO fileimageload VALUES(@content)");
conn.Open();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSQL.ToString();
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
}
--------------------编程问答-------------------- ImageDownload.aspx.cs(下载页面脚本设计)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class ImageDownload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btn = (LinkButton)e.Row.Cells[2].Controls[0];
btn.CommandArgument = e.Row.RowIndex.ToString();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "down")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
Response.Redirect("Handler.ashx?PhotoID=" + row.Cells[0].Text);
}
}
}
--------------------编程问答-------------------- --------------------编程问答-------------------- 拜托了lz,it技术很难的,非这个专业就不要来凑这个热闹了。趁早转行是王道 --------------------编程问答--------------------
呵呵,小弟的毕业设计需要用这个……因为有一年的时间没看专业书,很多东西都忘了……还请前辈不惜赐教!
补充:.NET技术 , ASP.NET