Click here to Skip to main content
15,886,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(DTourPrNo);----->here i am getting error.

int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char); return result;
Posted
Updated 7-Oct-10 23:34pm
v2
Comments
LittleYellowBird 8-Oct-10 5:25am    
Hi, I think you need to improve your question, could you explain what the error is? Also, what is the data? You may get answers a bit quicker if you can provide more information. Just a sugggestion. :)
spandananair 8-Oct-10 5:34am    
the error is invalid length for base 64 char array

The contents of DTourPrNo isn't properly base 64 encoded. It should be produced using something like this:

string DTourPrNo = Convert.ToBase64String(System.Text.UnicodeEncoding.Unicode.GetBytes("string content"));
 
Share this answer
 
Comments
spandananair 8-Oct-10 7:36am    
i am sending a mail notification to the user as a link abt this page ,wen the user is clicking the link no error,but wen i login to web and doing the same the page is giving error.

tpno = Request.QueryString["tour"].ToString();
tpno = ObjCon.base64Decode(tpno);
tpno = tpno.Replace("P!r@u#o$t", "");

after this code it goes to that loop.
Nathan St 8-Oct-10 7:49am    
That still doesn't show the part where you encode the string - that's where the problem most likely is.
hi ..,

i think you are not passing the correct encoding string to the method
FromBase64String

here am explaining with an example...

let say the original string is rajesh
if you encode it using base64 you will get cmFqZXNoDQo=

if decode the encoded sting you will get original string like this ....

<pre lang="vb">? Convert.FromBase64String("cmFqZXNoDQo=")
{byte[8]}
    [0]: 114
    [1]: 97
    [2]: 106
    [3]: 101
    [4]: 115
    [5]: 104
    [6]: 13
    [7]: 10


Thanks
Rajesh B
 
Share this answer
 
Comments
spandananair 8-Oct-10 7:36am    
i am sending a mail notification to the user as a link abt this page ,wen the user is clicking the link no error,but wen i login to web and doing the same the page is giving error.

tpno = Request.QueryString["tour"].ToString();
tpno = ObjCon.base64Decode(tpno);
tpno = tpno.Replace("P!r@u#o$t", "");

after this code it goes to that loop.

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