在Datalist ASP .NET C#中绑定视频

时间:2014-10-22 12:10:53

标签: c# sql asp.net video upload

我是一名新的.NET开发人员,并使用带有c#语言的Visual Studio 2010。 我在网站上传和检索视频时遇到问题。我正在使用eval by path上传照片并将其检索到数据库中。 这是HTML源代码:

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" 
        Width="962px">
        <ItemTemplate>
             <asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("news_image")%>'  Height="200px" Width="300px" />
        </ItemTemplate>
    </asp:DataList>

以下是将图像插入db:

的代码
 if (FileUpnewsimg.HasFile)
            {
                str = FileUpnewsimg.FileName;
                FileUpnewsimg.PostedFile.SaveAs(Server.MapPath(".") + "../images/Uploaded Images/" + str);
                string patth = "/$AdminPanel$/images/Uploaded Images/";
                path = patth + str.ToString();
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                con.ConnectionString = conn.connction();
                con.Open();
                cmd.Connection = con;
                cmd.CommandText = "insert into web_content (news_head,news_content_par1,news_content_par2,news_content_par3,news_content_par4,news_image,news_image_binary) values ('" + txttitle.Text.Replace("'", "''") + "','" + txtsection1.Text.Replace("'", "''") + "','" + txtsection2.Text.Replace("'", "''") + "','" + txtsection3.Text.Replace("'", "''") + "','" + txtsection4.Text.Replace("'", "''") + "','" + path + "','" + FileUpnewsimg.FileContent + "')";
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Redirect("News-Admin.aspx");
            }

我想以相同的方式将视频上传到数据库。 有人可以帮我吗?

2 个答案:

答案 0 :(得分:0)

在DataList中

     <ItemTemplate>
    <u>
        <%# Eval("Name") %></u>
    <hr />
    <a class="player" style="height: 300px; width: 300px; display: block" href='<%# Eval("Id","           "FileCS.ashx?Id={0}") %>'>
    </a>
</ItemTemplate>

1)添加JS

  <script src="FlowPlayer/flowplayer-3.2.12.min.js" type="text/javascript"></script>
  <script type="text/javascript">
   flowplayer("a.player", "FlowPlayer/flowplayer-3.2.16.swf", {
    plugins: {
        pseudo: { url: "FlowPlayer/flowplayer.pseudostreaming-3.2.12.swf" }
    },
    clip: { provider: 'pseudo', autoPlay: false},
    });
 </script>

2)点击上传代码

    protected void Upload_Click(object sender, EventArgs e)
     {

     using (BinaryReader reader= new BinaryReader(FileUpload1.PostedFile.InputStream))
     {
      byte[] bytes = reader.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length);
      // Add Here your sql query and give upload path
      }
     and on your page load Bind the DataList 

3)使用Generic Handler实现来自数据库的实时流媒体视频文件

答案 1 :(得分:0)