Thursday, 6 April 2017

How to show video in your own website like youtube. with play pause stop controls in Asp.net?

How to show video and provide download link on that using simple code in aspnet c#


Put Video tag inside the aspx page and give it id and runat server so it will be work with the code of aspx.cs file.

Video Page Design

.aspx page 

<video id="videoTag" runat="server"  height="768px" width="1020px" controls>
    <source src="#" type="video/mp4">
    Your browser does not support the video tag.
    </video>
        <asp:Button ID="Button1" runat="server" Text="Download" 
            onclick="Button1_Click" />



Asp.net C# code
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        str ="video.mp4";
        str = ".."+str.Substring(1);
        
        //str="../video/learn.mp4";
        videoTag.Attributes["src"] = str;

}
}

//Download button click event code

 protected void Button1_Click(object sender, EventArgs e)
    {
        filePath = "~//video.mp4";
        Response.ContentType = ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
        Response.WriteFile(filePath);
        Response.End();
    }


Thank you,
Hitesh Vataliya
www.vataliyatuitionclasses.com

No comments:

Post a Comment