Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Base64 Decode

Status
Not open for further replies.

nondrinker

Programmer
Jan 23, 2002
53
US
I have an ASP page, where i am trying to decode a base64 file back to its origianl pdf format. In another process, i am already able to convert the pdf file to base64, but now i was wondering if there is any code out there where i can decode the file back to the original pdf?

Thank you.
 
If that is ASP.Net heres some c# code I wrote a little while ago:

Code:
public string base64Decode(string data)
{
    try
    {
        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();  
        System.Text.Decoder utf8Decode = encoder.GetDecoder();
    
        byte[] todecode_byte = Convert.FromBase64String(data);
        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;
    }
    catch(Exception e)
    {
        throw new Exception("Error in base64Decode" + e.Message);
    }
}

HTH,

Stephan
 
Thank you very much, but actually my page is a just an ASP page.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top