Click here to Skip to main content
16,017,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a website which allows users to upload videos to my site. I want to display the uploaded videos dynamically i.e. the videos should be visible whenever an user uploads a video. To do this I have a custom control video player built. It works fine if I provide the "mp4url" directly. However, if I pass the mp4url using querystring, it is not working.

I have a submit page which allows users to upload videos using a fileupload control, and these are uploaded to "Uploads" folder

//Move through the "Uploads" folder and display the thumbnails of the videos after file has been uploaded
    private void LoadThumbnails()
    {
        foreach (string strfile in Directory.GetFiles(Server.MapPath("~/Uploads")))
        {
            ImageButton imageButton = new ImageButton();
            FileInfo fi = new FileInfo(strfile);
            imageButton.ImageUrl = "~/Uploads/" + fi.Name;
            imageButton.Height = Unit.Pixel(100);
            imageButton.Style.Add("padding", "5px");
            imageButton.Width = Unit.Pixel(100);
            imageButton.Click += new ImageClickEventHandler(imageButton_Click);
            Panel1.Controls.Add(imageButton);
        }
    }

    //Redirect to the "Videos" page using Querystring
    protected void imageButton_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Videos.aspx?VideoURL=" + ((ImageButton)sender).ImageUrl);
    }

There is a page called "Videos" which has a video player, it receives "Mp4Url" using the querystring

ASP.NET
<cc1:VideoPlayer ID="VideoPlayer1"  runat="server" Mp4Url='<%# Request.QueryString["VideoURL"]%>'  Width="400" Height="300" />


This is not working, any idea of what changes will rectify this issue?(Issue is the video player is not playing the video)

P.S.
C#
protected void Page_Load(object sender, EventArgs e)
      {
        VideoPlayer1.Mp4Url = Request.QueryString["VideoURL"];
      }

Even the above code in the code behind file for the Videos page is not working.

If i use

ASP.NET
<cc1:VideoPlayer ID="VideoPlayer1"  runat="server" Mp4Url="Uploads/movie.mp4"  Width="400" Height="300" />

it's working fine. However, that requires manual allocation of the mp4url.
Posted

This does not look valid to me, trying to assign the url from the query string.

You redirect to "Videos.aspx" using this line:

Response.Redirect("Videos.aspx?VideoURL=" + ((ImageButton)sender).ImageUrl);


In the Page_Load (or the suitable page method as per your need) of "Videos.aspx", you can check the query string and assign it to the custom control?

protected void Page_Load(object sender, EventArgs e)
{
   var url = Request.QueryString["VideoURL"];
   
   if (!string.IsNullOrEmpty(url))
   {
       VideoPlayer1.Mp4Url = url;
   }
}


The <%# .. %> format should be used for "data-binding" and this is not a suitable case for data binding. For example, you could use this in a grid view to bind the value of a property to a grid view column.
 
Share this answer
 
I managed to correct the code. It was the "~/" which was causing the problem
imageButton.ImageUrl = "Uploads/" + fi.Name;

The above change made it work!
 
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