asp.net调用windows系统自动的播放器Media player

 前台代码

<embed src="<%=VUrl%>" noerror="true" style="width: 579px; height: 321px"></embed>

 

后台代码

  //观看视频
    protected void seeVi()
    {
        try
        {
            string sql = "select * from tb_Video where VideoID=" + Convert.ToInt32(Request.QueryString["VideoID"]);
            OleDbDataReader odr = mydo.row(sql);//调用数据库操作类中的row方法         
            odr.Read();          //前进一条记录
            VUrl = "Video" + "\\" + odr["VideoUrl"].ToString();   //存储视频教程的路径
            if (!File.Exists(Server.MapPath(".") + "\\" + VUrl))//判断此教程是否存在
            {
                string dlsql = "delete from tb_Video where VideoID=" + Convert.ToInt32(Request.QueryString["VideoID"]);
                mydo.adlData(dlsql);
                Page.RegisterStartupScript("true", "<script>alert('文件不存在!请返回!');location='index.aspx'</script>");
            }
            VideoTitle = odr["VideoName"].ToString();
            Content = odr["VideoContent"].ToString();
            Name = odr["Name"].ToString();
            FBDate = odr["FBDate"].ToString();
            ClickSum = odr["ClickSum"].ToString();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }
    }

文件下载:

if (Session["UserName"] != null)
        {
            string path = Server.MapPath(".\\") + VUrl;
            //初始化 FileInfo 类的实例,它作为文件路径的包装
            FileInfo fi = new FileInfo(path);
            Response.Write(path);
            //   判断文件是否存在
            if (fi.Exists)
            {
                // 将文件保存到本机上
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
                Response.AddHeader("Content-Length", fi.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.Filter.Close();
                Response.WriteFile(fi.FullName);
                Response.End();
            }

 

posted @ 2010-07-01 14:25  你妹的sb  阅读(2410)  评论(0编辑  收藏  举报
百度一下