Refer the below sample code and implement code in your code as per your code logic.
Video Files in Project Folder
HTML (C# Page)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onload = function () {
var myvid = document.getElementById('myvideo');
// Get values for video from Files Property
var myvids = <%=this.Files %>;
var activeVideo = 0;
// Set first video as src for video element as default src
myvid.setAttribute("src", myvids[0]);
myvid.addEventListener('ended', function (e) {
// update the new active video index
activeVideo = (++activeVideo) % myvids.length;
// update the video source and play
myvid.src = myvids[activeVideo];
myvid.play();
});
}
</script>
</head>
<body>
<video id="myvideo" width="320" height="240" controls autoplay>
</video>
</body>
</html>
C#
// Property to hold files name
public string Files { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
// Set Video Files List Value as Json string array to Files property
Files = FileList();
}
}
private string FileList()
{
// Folder Name from Your Project
string folderName = "Videos";
// Get all Videos files from Folder
DirectoryInfo info = new DirectoryInfo(Server.MapPath(folderName));
// Set the Path as Folder Name and file name
List<string> files = info.GetFiles().Select(p => string.Format("{0}/{1}", folderName, p.Name)).ToList();
// return Json Array as string
return (new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(files));
}
HTML (VB.Net Page)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onload = function () {
var myvid = document.getElementById('myvideo');
// Get values for video from Files Property
var myvids = <%=Me.Files %>;
var activeVideo = 0;
// Set first video as src for video element as default src
myvid.setAttribute("src", myvids[0]);
myvid.addEventListener('ended', function (e) {
// update the new active video index
activeVideo = (++activeVideo) % myvids.length;
// update the video source and play
myvid.src = myvids[activeVideo];
myvid.play();
});
}
</script>
</head>
<body>
<video id="myvideo" width="320" height="240" controls autoplay>
</video>
</body>
</html>
VB.Net
Inherits System.Web.UI.Page
'Property to hold files name
Public Property Files As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
'Set Video Files List Value as Json string array to Files property
Files = FileList()
End If
End Sub
Private Function FileList() As String
'Folder Name from Your Project
Dim folderName As String = "Videos"
'Get all Videos files from Folder
Dim info As IO.DirectoryInfo = New IO.DirectoryInfo(Server.MapPath(folderName))
'Set the Path as Folder Name and file name
Dim files As List(Of String) = info.GetFiles().[Select](Function(p) String.Format("{0}/{1}", folderName, p.Name)).ToList()
'return Json Array as string
Return (New System.Web.Script.Serialization.JavaScriptSerializer().Serialize(files))
End Function
Screenshot