求 实现视频文件下载的代码, 视频文件最大 5m。谢谢了 。。

解决方案 »

  1.   


            //文件下载
            private void FileDownload(string FullFileName)
            {
                FileInfo DownloadFile = new FileInfo(FullFileName);
                string subFileName = DownloadFile.FullName.Substring(DownloadFile.FullName.LastIndexOf("\\") + 1);
                Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(subFileName, System.Text.Encoding.UTF8));
                Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
                Response.WriteFile(DownloadFile.FullName);
                Response.Flush();
                Response.End();
            }
        }
      

  2.   

    如果知道文件地址有很多方法下载,如果通过flash播放视频实现保护,很难下载。
    FileInfo fi = new FileInfo("");
    HttpResponse contextResponse = HttpContext.Current.Response;
    contextResponse.Clear();
    contextResponse.Buffer = true;
    contextResponse.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", Name)); 
    contextResponse.AppendHeader("Content-Length", fi.Length.ToString());
    contextResponse.ContentEncoding = Encoding.Default;
    contextResponse.ContentType = "application/octet-stream"; 
    contextResponse.WriteFile(fi.FullName);
    contextResponse.Flush();
    contextResponse.End();
    还有HttpResponse.TransmitFile
    HttpResponse.BinaryWrite
    HttpResponse.Redirect
      

  3.   

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                Dim path As String = Request("path")
                Dim att_name As String = Request("name")
                Dim MyFileStream As New FileStream(path, FileMode.Open)
                Dim FileSize As Long
                FileSize = MyFileStream.Length
                Dim Buffer As Byte() = New Byte(CInt(FileSize) - 1) {}
                MyFileStream.Read(Buffer, 0, CInt(MyFileStream.Length))
                MyFileStream.Close()
                If Split(att_name, ".")(1) = "mov" Then
                    Response.ContentType = "video/quicktime"
                ElseIf Split(att_name, ".")(1) = "avi" Then
                    Response.ContentType = "video/x-msvideo"
                ElseIf Split(att_name, ".")(1) = "mpg" Then
                    Response.ContentType = "video/mpeg"
                ElseIf Split(att_name, ".")(1) = "wmv" Then
                    Response.ContentType = "video/x-ms-wmv"
                ElseIf Split(att_name, ".")(1) = "3gp" Then
                    Response.ContentType = "video/3gpp"
                End If
               
                Response.AddHeader("content-disposition", "attachment;filename=" + att_name)
                'this fixes the filename 
                Response.BinaryWrite(Buffer)
                Response.End()
            Catch ex As Exception
            End Try
        End Subpath=D:\Projects\TD_web\hub\pledge_video\approved_7175CDC0-82D3-4F07-BF9D-263C84560C5F.wmv但是 下载的时候,没有弹出窗口,也不知道什么原因?
    请大家帮我看看,谢谢了。