Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

I want to create Video gallary in ASP.NET using C#.
how to display video on web page whose link is stored in database.
Which control is used for that.
i m using MS-SQL 2005.
Plz help me out...................
Posted
Comments
Anil Honey 206 19-Oct-11 4:46am    
you want to display youtube vedios or anything else?
Vandana87 19-Oct-11 5:43am    
youtube will be good but even an flash player would be implemented.

Dear Friend,

For YouTube Vedios Iam Posting Sample Code Follow that.

Design Code:
<table>
<tr>
<td align="left" class="links2">
Title :</td>
<td align="left" class="links2">
<asp:TextBox ID="txtTitle" runat="server"></asp:TextBox><asp:RequiredFieldValidator
ID="rfvName" runat="server" ControlToValidate="txtTitle" Display="Dynamic" ErrorMessage="Enter Title"
SetFocusOnError="True" ValidationGroup="add">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="left" class="links2" valign="top">
Link :</td>
<td class="links2" align="left">
<asp:TextBox ID="txtLink" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvDesc" runat="server" ControlToValidate="txtLink"
Display="Dynamic" ErrorMessage="Enter Link" SetFocusOnError="True" ValidationGroup="add">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="txtdelete" runat="server" Text="Delete"
onclick="txtdelete_Click1" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="add" OnClick="btnSubmit_Click" /><asp:ValidationSummary
ID="vsAdd" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="add" />
<asp:Repeater ID="Repeater1" runat="server" DataSourceID ="SqlDataSource1">
<ItemTemplate>
<object width="480" height="385"><param name="movie" value='<%#DataBinder.Eval(Container.DataItem, "url") %>'></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src='<%#DataBinder.Eval(Container.DataItem, "url") %>' type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385">
</embed>
</object>
<br />
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:sqlCon%>"
SelectCommand="SELECT [url], [description], [id] FROM [YouTubeVideos]">
</asp:SqlDataSource>
</td>
</tr>
</table>

C# Code:


private string GetYouTubeID(string youTubeUrl)
{
//RegEx to Find YouTube ID
Match regexMatch = Regex.Match(youTubeUrl, "^[^v]+v=(.{11}).*",
RegexOptions.IgnoreCase);
if (regexMatch.Success)
{
return "http://www.youtube.com/v/" + regexMatch.Groups[1].Value +
"&hl=en&fs=1";
}
return youTubeUrl;
}


in submit button event:


protected void btnSubmit_Click(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlCon"].ToString());
string url = txtLink .Text;
if (url.Contains("youtube.com"))
{
string ytFormattedUrl = GetYouTubeID(url);

if (!CheckDuplicate(ytFormattedUrl))
{
DataSet ds = new DataSet();
SqlDataAdapter ad = new SqlDataAdapter("select * from YouTubeVideos", con);
ad.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
SqlCommand cmd = new SqlCommand("INSERT INTO YouTubeVideos ([url]) VALUES ('" + ytFormattedUrl + "')", con);
using (con)
{
con.Open();
int result = cmd.ExecuteNonQuery();
if (result != -1)
{
Repeater1.DataBind();
}
else
{ Response.Write("Error inserting new url!"); }
con.Close();

}
}
else
{
Response.Write("already you uploaded the video");
}
}
else { Response.Write("This video already exists in our database!"); }
}
else
{
Response.Write("This URL is not a valid YOUTUBE video link because it does not contain youtube.com in it");
}
}

public bool CheckDuplicate(string youTubeUrl)
{
bool exists = false;
//con=new SqlConnection ();
//con.ConnectionString = "Data Source=SH-3\\SQLEXPRESS;Initial Catalog=VarenyaCollege;Integrated Security=True";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlCon"].ToString());
SqlCommand cmd = new SqlCommand(String.Format("select * from YouTubeVideos where url='{0}'", youTubeUrl), con);

using (con)
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
exists = (dr.HasRows) ? true : false;
}

return exists;
}

Analize and Execute

Regards

Anilkumar.D
 
Share this answer
 
Can you be a bit clear. Can you post a sample link of your video which is stored in database?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900