我想做出的是点击LinkButton弹出下载对话框,
=========================================
下面我的做法VS.net提示错误说:
未将对象引用设置到对象的实例。
private void LinkButton1_Click(object sender, System.EventArgs e)
行 96:  {
行 97:  string fileName = FileUrl.Substring(FileUrl.LastIndexOf("/"),(FileUrl.Length - FileUrl.LastIndexOf("/")));
==========================================
数据库中的
表:Videos
字段:VideoID,FileUrl
FileUrl里面的存储的是相对文件地址:例如:../UpLoads/Videos/XX.rar
即:
Table:Videos(VideoID,FileVrl)
                 1   , ../UpLoads/Videos/2004.rar
                 2   , ../UpLoads/Videos/2005.rar
...   ...
==========================================
下面是程序代码namespace Video
{

public class ShowVideo : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection myConnection;
protected System.Data.SqlClient.SqlCommand myCommand;
protected System.Data.DataSet myDataSet;
protected System.Data.SqlClient.SqlDataAdapter myDataAdapter;
protected System.Data.SqlClient.SqlDataReader myDataReader;

public string FileUrl; protected System.Web.UI.WebControls.LinkButton lbtnFile;

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
getVideos();
}
} public void getVideos()
{
myConnection = new SqlConnection(DataBaseDB.ConnectionString);
myCommand = new SqlCommand("select * from Videos where VideoID=@VideoID",myConnection);
myCommand.Parameters.Add(new SqlParameter("@VideoID",SqlDbType.BigInt));
myCommand.Parameters["@VideoID"].Value = Request["VideoID"]; myConnection.Open();
myDataReader = myCommand.ExecuteReader();

if(myDataReader.Read()==true)
{
FileUrl = myDataReader.GetString(1);
myConnection.Close();
}
myConnection.Close(); } private void LinkButton1_Click(object sender, System.EventArgs e)
{ string fileName = FileUrl.Substring(FileUrl.LastIndexOf("/"),(FileUrl.Length - FileUrl.LastIndexOf("/")));
fileName = (Server.MapPath(Request.ApplicationPath) + "\\UpLoads\\Videos\\" + fileName);
if(!System.IO.File.Exists(fileName))
{
Response.Write("<script>alert(\"对不起,下载视频不存在\")</script>");
return;
} Response.Clear();
Response.ClearHeaders();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/octet-strem";
FileInfo fi= new FileInfo(fileName);
Response.AddHeader("Content-Disposition","attachment; filename="
+ HttpUtility.UrlEncode(fi.Name));
Response.AddHeader("Content-Length",fi.Length.ToString());
byte[] tmpbyte = new byte[1024*8];
FileStream fs = fi.OpenRead();
int count;
while((count = fs.Read(tmpbyte,0,tmpbyte.Length))>0)
{
Response.BinaryWrite(tmpbyte);
Response.Flush();
}
fs.Close();
Response.End();     }