Passing base64 string using c# string variable. Error: Index was outside the bounds of the array

后端 未结 1 844
轮回少年
轮回少年 2021-01-29 11:59

Still A Newbie. I would like to replace the long Base64 string with a variable but keep getting error: Index was outside the bounds of the array.

Scenario: I am retrievi

1条回答
  •  隐瞒了意图╮
    2021-01-29 12:55

    It looks as though:

    ClientSigImg = reader[0].ToString();
    

    Is NOT returning a string with a comma in it (please debug and confirm). This means that you will see the error you are describing when this line of code runs:

    ClientSigImg1 = ClientSigImg.Split(',')[1];
    

    This is because index 1 will not exist. So, check that you are actually getting the correct data returned from your query.

    In addition, once your query does return the correct data you can tidy your code and simply use:

    byte[] imageBytes = Convert.FromBase64String(ClientSigImg1);
    

    That is because:

    string base64 = @""+ ClientSigImg1 +"";
    

    Doesn't actually do anything other than add empty string before and after your string, hence, doesn't add anything!

    0 讨论(0)
提交回复
热议问题