Hi smile,
Refer below example.
HTML
C#
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<%if (!string.IsNullOrEmpty(this.FileName)) {%>
<span><%= this.FileName %></span>
<hr />
<video controls src='<%= ResolveUrl("~/Files/" + this.FileName) %>' width="200" height="250" />
<%} %>
<asp:Timer runat="server" OnTick="OnTick" Interval="2000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
VB.Net
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<%If Not String.IsNullOrEmpty(Me.FileName) Then %>
<span><%= Me.FileName %></span>
<hr />
<video controls src='<%= ResolveUrl("~/Files/" + Me.FileName) %>' width="200" height="250" />
<%End If %>
<asp:Timer runat="server" OnTick="OnTick" Interval="2000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.FileName = Path.GetFileName(Directory.GetFiles(Server.MapPath("~/Files/"))[0]);
}
}
protected string FileName { get; set; }
protected void OnTick(object sender, EventArgs e)
{
this.SetIndex();
string[] fileNames = Directory.GetFiles(Server.MapPath("~/Files/"));
int index = Convert.ToInt32(ViewState["Count"]);
if (fileNames.Length > index)
{
this.FileName = Path.GetFileName(fileNames[index]);
}
}
protected void SetIndex()
{
int counter;
if (ViewState["Count"] != null)
{
counter = Convert.ToInt32(ViewState["Count"]);
}
else
{
counter = 0;
}
counter = counter + 1;
ViewState["Count"] = counter;
}
VB.Net
Protected Property FileName As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.FileName = Path.GetFileName(Directory.GetFiles(Server.MapPath("~/Files/"))(0))
End If
End Sub
Protected Sub OnTick(ByVal sender As Object, ByVal e As EventArgs)
Me.SetIndex()
Dim fileNames As String() = Directory.GetFiles(Server.MapPath("~/Files/"))
Dim index As Integer = Convert.ToInt32(ViewState("Count"))
If fileNames.Length > index Then
Me.FileName = Path.GetFileName(fileNames(index))
End If
End Sub
Protected Sub SetIndex()
Dim counter As Integer
If ViewState("Count") IsNot Nothing Then
counter = Convert.ToInt32(ViewState("Count"))
Else
counter = 0
End If
counter = counter + 1
ViewState("Count") = counter
End Sub
Screenshot