Advertisement
Guest User

Untitled

a guest
Apr 12th, 2012
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.09 KB | None | 0 0
  1. <pre lang="c#"></pre><pre lang="c#"><%@ Page Language="C#" %>
  2.  <%@ Import Namespace="System.IO" %>
  3.  <%@ Import Namespace="System.Data" %>
  4.  <%@ Import Namespace="System.Data.SqlClient" %>
  5.  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7.  
  8. &lt;script runat="server">
  9.      
  10.     private void Page_Load(Object sender, EventArgs e)
  11.      {
  12.          string sql = "SELECT * FROM Entry";
  13.          SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
  14.          SqlCommand command = new SqlCommand(sql, connection);
  15.          connection.Open();
  16.          FileList.DataSource = command.ExecuteReader();
  17.          FileList.DataBind();
  18.          connection.Close();
  19.      }
  20.      
  21. &lt;/script>
  22.  
  23. &lt;html xmlns="http://www.w3.org/1999/xhtml" >
  24.  &lt;head runat="server">
  25.      &lt;title>Untitled Page&lt;/title>
  26.  &lt;/head>
  27.  &lt;body>
  28.      &lt;form id="form1" runat="server">
  29.      <div>
  30.          <asp:DataGrid id="FileList" runat="server" AutoGenerateColumns="false" >
  31.              <Columns>
  32.                  <asp:TemplateColumn HeaderText="Entry Name">
  33.                  <ItemTemplate>
  34.                      <%# DataBinder.Eval(Container.DataItem, "EntryName")%>
  35.                  </ItemTemplate>
  36.                  </asp:TemplateColumn>
  37.  
  38.                 <asp:TemplateColumn HeaderText="Entry Media Type">
  39.                  <ItemTemplate>
  40.                      <%# DataBinder.Eval(Container.DataItem, "EntryMediaMIMEType") %>
  41.                  </ItemTemplate>
  42.                  </asp:TemplateColumn>
  43.  
  44.                 <asp:TemplateColumn HeaderText="Entry Media">
  45.                  <ItemTemplate>
  46.                      <a href="FileHandler.ashx?ID=<%# DataBinder.Eval(Container.DataItem, "EntryID") %>">View File</a>
  47.                  </ItemTemplate>
  48.                  </asp:TemplateColumn>
  49.              </Columns>
  50.          </asp:DataGrid>
  51.      </div>
  52.      &lt;/form>
  53.  &lt;/body>
  54.  &lt;/html></pre>
  55.  
  56.  
  57. <b>this is FileHandler.ashx, returns binary stream</b>
  58.  
  59.  
  60. <pre lang="c#"><%@ webhandler language="C#" class="MediaHandler" %>
  61.  using System;
  62. using System.Web;
  63. using System.Data;
  64. using System.Data.SqlClient;
  65.  public class MediaHandler : IHttpHandler
  66. {
  67.     public bool IsReusable { get { return true; } }
  68.    
  69.     public void ProcessRequest(HttpContext ctx)
  70.     {
  71.          string sql = "SELECT * FROM Entry WHERE EntryID = '" + ctx.Request.QueryString["ID"] + "'";
  72.          SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
  73.  
  74.         SqlCommand command = new SqlCommand(sql, connection);
  75.          connection.Open();
  76.          SqlDataReader dr = command.ExecuteReader();
  77.  
  78.         if (dr.Read())
  79.          {
  80.              ctx.Response.Clear();
  81.              ctx.Response.AddHeader("Content-Type", dr["EntryMediaMIMEType"].ToString());
  82.              ctx.Response.BinaryWrite((byte[])dr["EntryMedia"]);
  83.          }
  84.  
  85.         dr.Close();
  86.          connection.Close();
  87.      }
  88. }  </pre>
  89.  
  90.  
  91. <b>this is video.aspx for displaying the video</b>
  92.  
  93. <pre lang="c#">
  94. <%@ Page Language="C#" %>
  95.  <%@Import Namespace="System.IO" %>
  96.  <%@Import Namespace="System.Data" %>
  97.  <%@Import Namespace="System.Data.SqlClient" %>
  98.  
  99. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  100.  
  101. &lt;script runat="server">
  102.  &lt;/script>
  103.  
  104. &lt;html xmlns="http://www.w3.org/1999/xhtml" >
  105.  &lt;head runat="server">
  106.      &lt;title>Untitled Page&lt;/title>
  107.  &lt;/head>
  108.  &lt;body>
  109.      &lt;form id="form1" runat="server">
  110.      <div>
  111.      &lt;object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="player" width="320" height="260">
  112.          <param name="url" value="FileHandler.ashx?ID=4" />
  113.          <param name="showcontrols" value="true" />
  114.          <param name="autostart" value="true" />
  115.      &lt;/object>
  116.      </div>
  117.      &lt;/form>
  118.  &lt;/body>
  119.  &lt;/html></pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement