我想从文件夹中使用数据库中的路径获取音频文件,并编写文件下载代码,请回复我。
这是我的处理程序代码。如果我使用这个代码,我只播放一个音频文件,如果上传另一个文件,它也像上传文件音乐一样相同 - 我的意思是一次播放相同的音乐
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="login.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
我的设计代码: -
public class audiofiles : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
int newsid = int.Parse(context.Request.QueryString["newsid"]);
byte[] bytes;
string contentType;
string strConnString = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
string name;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select * from tbl_userpost_newsaudios where newsid=@newsid";
cmd.Parameters.AddWithValue("@newsid", newsid);
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
bytes = (byte[])sdr["audiodata"];
contentType = sdr["contenttype"].ToString();
name = sdr["audioname"].ToString();
con.Close();
}
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name);
context.Response.ContentType = contentType;
context.Response.BinaryWrite(bytes);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}