I am trying to switch from iframe tag to < a > tag by taking the src of youtube iframe and use it as a src for < a> tag, I have already put the video sources as a large string in the page form and split it to smaller parts by this char '|' so each < a> tag will know which src index he'll have to reference. my problem is that I want to take the image of youtube video by using this format:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
from the split string, so to get this image i am trying to resplit the source string , to get the video Id (and therefore get the video image) below is my code:
protected void Page_Load(object sender, EventArgs e)
{
string [] values = ImageFieldValues.Split('|');
if (values.Length != 0) {
foreach (string source in values)
{
litCon.Text = "<a name='testiFrame' data-fancybox-type='iframe' id='runtimeIFrame' class='col-xs-3 various fancybox.iframe' style='margin-bottom: 10px;float: right;' href='" + source+ "'><img id='iframeImage' src='http://img.youtube.com/vi/"+ source.Substring(26) + "/hqdefault.jpg'/></a>";
AddToDivImages.Controls.Add(litCon);
}
}
}
this is a custom control used within a transformation in kentico project, video sources are loading fine, the only problem is with source.substring(26), it is returning an error saying that index is out of boundaries, it is only working for index (0), any number larger than zero will return the same error, I also tried to trim, split, Remove... its like it is taking the whole string as one block, here is a screenshot for the event log in kentico