kentico is not able to trim a string, error outOfBoundException

Connor Kemp asked on December 1, 2020 04:58

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

Recent Answers


Brenden Kehren answered on December 1, 2020 18:26

I don't think this is a Kentico issue at all. It sounds more like a data issue. Maybe you're parsing your stored content incorrectly. Secondly, if you want to do .Substring(26), you should probably first check to see that your source has 26 characters in it. I'm willing to bet when you debug your code you'll find the data is not as you expect it to be.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.