How to solve playing video issue in asp.net - asp.net

Helli Guys!
I have a issue with playing video based on path of video on run time in web video player. there is a ASP code:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<video src='<%# GetVideoPlayUrl(Eval("id")) %>' width="900" height="400"
controls="" preload=""></video>
</ItemTemplate>
</asp:Repeater>
I have a video Path in database that is saved in db like this ~\StoreVideo\VQOFY.mp4
protected string GetVideoPlayUrl(object Id)
{
int id = Convert.ToInt32(Id);
string ret = "";
ret = "" + VideoUploads.GetVideoPath(id) + "";
return ret; I'm return value `~\StoreVideo\VQOFY.mp4`
}
The video is not uploading in player i also tried this
protected string GetVideoPlayUrl(object Id)
{
int id = Convert.ToInt32(Id);
string ret = "";
ret = "" + VideoUploads.GetVideoPath(id).Replace("~\\","").Replace("\\","/") + "";
return ret; I'm return value `StoreVideo/VQOFY.mp4`
}
still not working i dont know where was im doing wrong I really need a help in this issue. to know what is the mistake I'm doing here. please correct me with my code where was a mistake.hope some buddy have a solution for me with it.
Thank you

URLs that start with ~/ should be 'resolved' before you use them client-side (the <video> element is a client-side HTML element, it is unaware of ASP.NET on the server). Try the following code inside the src attribute:
<%# ResolveUrl(GetVideoPlayUrl(Eval("id"))) %>
If you are returning "~/videos/some-video.mp4" from the GetVideoPlayUrl(id) method, then the call to ResolveUrl() will 'translate' that, maybe to "../../videos/some-video.mp4" or maybe to "videos/some-video.mp4". It all depends on where the current page is located relative to the location of the file.
You should check in the final HTML that the (relative) path from the ASPX page to the video file is now correct.

Related

Uploaded binary Picture into database and display in listview

I am try to uploaded an image to a database which work but I can't display the image in a ListView which has a sql datasource
This is my upload image code
int img = ImageUpload1.PostedFile.ContentLength;
byte[] msdata = new byte[img];
ImageUpload1.PostedFile.InputStream.Read(msdata, 0, img);
myCommand.Parameters.AddWithValue("#image_1", msdata);
display image
<asp:Image ID="Image1" runat="server" src='<%# DataBinder.Eval(Container.DataItem, "image_1") %>' CssClass="background-image: url(data:image/jpeg;base64,IVB)" />
This is the error I keep getting
Unable to translate Unicode character \uDAFF at index 15 to specified code page.
You don't have to go my way immediately, but I tried it, and worked quite quickly:
I created a method that returns a File object to the browser:
public ActionResult GetThumbnail(Guid id)
{
var fileToRetrieve = Db.Pictures.Find(id);
if (fileToRetrieve == null)
return null;
if (fileToRetrieve.Thumbnail == null)
return null;
return File(fileToRetrieve.Thumbnail, fileToRetrieve.ContentType);
}
In the browser, I just set the img src attribute to that method with the ID I need to retrieve.
<img src="~/Picture/GetThumbnail?id=#item.Id" />

Passing url to Image tag in asp.net C#

I dont know how to pass value from page.aspx.cs (string url = dr["report_image"].ToString();) to page.aspx ( )
i save image filename (eg:sunset.jpg) to sql database and retrieve it using reader (string url = dr["report_image"].ToString();) and i want to use this url (or filename) to use in the main webpage (aspx). I dont know how to pass this value from ".aspx.cs" to ".aspx"
Any help would be appreciated. thank you
<asp:Image ID="img" Runat="Server" />
Аnd in the code:
img.ImageUrl = url
or you can simply generate Image element in aspx.cs side.
the code below
Image img = new Image();
img.ImageUrl = "your string";

Get File ID in page after upload file by AsyncFileUpload(ajaxToolkit)

I am using AsyncFileUpload (ajaxToolkit) control for uploading image file from registration page. uploaded file content are store into DB. So I need to show my uploaded file in asp:image control by httphander like <asp:image id="imgLogo" runat="server" ImageUrl="Images.aspx/id=12" />. So how to do this.
Assuming you are storing the image as a byte[] in DB;
var data = new byte[1]; //Replace this with your values from DB
var mimeType = "application\pdf"; //Replace this with your values from DB
response.ContentType = mimeType ;
response.BinaryWrite(data);
This code should be placed in page_load in images.aspx after you have retrieved the values from the DB.
Your image page handler page_load method will be
Images.aspx
protected void Page_Load(sender s, eventagrs e){
var imagecontent= new byte[XXXX]; // Read DB content as bytes for the passed Id
response.ContentType = 'jpeg/gif/anything' ;
//this should be a valid MIME type saved in database
response.BinaryWrite(imagecontent);
}
Edit:
From your comments you are trying to update the image tag src value
from codebehind using Asp.Net Ajax.
If you want to do this, first make sure your page has access to view state
information about those image tags. This is not a big deal, you simply
wrap the image tags container panel/div with update panel.
So your ajax request will send the information about those viewstate and
push the partial update for those image container panel also.
I have reviewed many site and I got answer of this question..
http://www.mikeborozdin.com/post/AJAX-File-Upload-in-ASPNET-with-the-AsyncFileUpload-Control.aspx
<ajaxToolkit:AsyncFileUpload ID="afuCompanyLogo" runat="server"
OnClientUploadError="uploadError" OnClientUploadComplete="uploadComplete"
UploaderStyle="Modern" UploadingBackColor="#CCFFFF"
ThrobberID="myThrobber"
onuploadedcomplete="afuCompanyLogo_UploadedComplete" />
<asp:Image ID="imgCompanylogo" CssClass="imgCompanylogo" runat="server" Height="80px" Width="80px" AlternateText="" />
protected void afuCompanyLogo_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if(afuCompanyLogo.HasFile)
{
FileManagementEntity fileManagementEntity = new FileManagementEntity();
FileManagement fileManagement = fileManagementEntity.Create();
fileManagement.FileContentType = afuCompanyLogo.ContentType;
fileManagement.FileContent = afuCompanyLogo.FileBytes;
fileManagement.Size = afuCompanyLogo.FileBytes.Count();
fileManagement.OriginalName = afuCompanyLogo.FileName;
fileManagementEntity.Save(fileManagement);
ViewState["logoID"] = fileManagement.FileManagementID;
imgCompanylogo.ImageUrl = "Image.aspx?id=" + fileManagement.FileManagementID.ToString();
ScriptManager.RegisterClientScriptBlock(afuCompanyLogo, afuCompanyLogo.GetType(), "img", "top.document.getElementById('" + imgCompanylogo.ClientID + "').src='Image.aspx?id=" + fileManagement.FileManagementID + "';", true);
}
}

How do I specify that I want my hyperlink to always be absolute path?

I have this link of code where I populate a hyperlink with an address at runtime from the database.
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank"
NavigateUrl='<%#Eval("Source") %>'><%#Eval("Source") %></asp:HyperLink>
The problem is that it's treating the link as relative. so if the link is yahoo.com, it'll go to
http://localhost/yahoo.com
or something to that effect.
If my link source is http://www.yahoo.com, that will work, but I cannot guarantee that the links may or may not have the http:// at the start.
How can I get it to always treat it as an absolute URL.
You can try something like this
NavigateUrl='<%# GetUrl(Eval("Source")) %>'>
with
public string GetUrl(object source)
{
if(source != null)
{
string str = source.ToString();
return str.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) ?
str :
string.Format("http://{0}",str);
}
return string.Empty;
}

How to play media - saved on db as binary - on a website?

I have a table on SQL Server 2008, I saved on it videos and audios as binary.
I have to play these media (videos and audios) on my website.
Can I do that?
Is there a way that I could request the media as a link? so I can embed it...
Any help appreciated.
Sorry for my english.
They are probably other ways to do this but i'll just show mine below.
create an asp.net page (image.aspx for instance) that has no content on the page just the #page attributes... see below.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="image.aspx.cs" Inherits="image" %>
You code behind file might look like below:
public void Page_Load(object s, System.EventArgs e)
{
int id = Request.QueryString["image_id"]; //assuming u are getting it from query string
byte[] bt = GetMediaData(id); //image data from database as byte array
Response.Buffer = true;
Response.ContentType = "audio/mp3"; //set mimetype of appropriate media type
Response.BinaryWrite(abt);
Response.Flush();
}
on the page that needs to use the resource:
<asp:Image runat="server" id="Image1" ImageUrl="image.aspx?image_id=xx" />
i'm sure this can be done using http handlers though.

Resources