这是代码
string musicURL=reader1.GetString(0);
 musicURL是文件的相对路径,以musicURL="flv/2.wmv"为例;
怎么加代码在下面,才能实现下载功能
         
//Response.Redirect( musicURL);删
Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment;FileName="+musicURL);
        Response.BinaryWrite();
        Response.End();

解决方案 »

  1.   


        public void DownloadExcelFile(string musicURL,string FName )
        {
            if (musicURL!= "" && musicURL!= null)
            {
                System.IO.FileInfo file = new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + musicURL);
                if (file.Exists)
                {
                    string ExtendName = file.Name;
                    if (ExtendName.Length > 4)
                    {
                        string FileName =FName ;
                        int i = ExtendName.LastIndexOf(".");
                        ExtendName = ExtendName.Substring(i);
                        FileName += ExtendName;
                    }
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;                 
                    filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
                    HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
                    HttpContext.Current.Response.ContentType = "application/octet-stream";
                    HttpContext.Current.Response.Filter.Close();
                    HttpContext.Current.Response.WriteFile(file.FullName);
                    HttpContext.Current.Response.End();
                }
                else
                {
                    HttpContext.Current.Response.Write("对不起,文件" + AppDomain.CurrentDomain.BaseDirectory + fileName + "不存在");
                }
            }
        }
      

  2.   

    上面的代码是我临时在以前的一个项目临时改过来的,这个电脑没有.net
    在记事本中改的...
    自己用时在看看,能不能对你有帮助..