• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3623
  • Last Modified:

How to Encode URL in Base64 in C# windows application?

Hi,

I want to encode an URL in to Base64 in c# windows application.
Please help me.
0
vikasbapat
Asked:
vikasbapat
  • 5
  • 3
  • 2
1 Solution
 
ozymandiasCommented:
Get the URL string as byte[] and then do Convert.ToBase64String(byte[]);
0
 
vikasbapatAuthor Commented:
0
 
muzzy2003Commented:
This ought to work:

using System.Text;

byte[] urlBytes = Encoding.ASCII.GetBytes(url);
string urlB64 = Convert.ToBase64String(urlBytes);

If you want the URL treated as, for example, Unicode, you would change the encoding like so:

byte[] urlBytes = Encoding.Unicode.GetBytes(url);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
muzzy2003Commented:
(or something like that - typed outside of VS)
0
 
vikasbapatAuthor Commented:
It is working fine.

Thanks for quick responce.
0
 
ozymandiasCommented:
Thanks, I tell you how to encode to base64 and you award points for converting a string to bytes.
You could have at least split the points there.
0
 
muzzy2003Commented:
Yes, agreed. And a B?
0
 
muzzy2003Commented:
(BTW ozymandias, hadn't intended to steal this one, just saw it in passing. Assumed you'd already basically won the points ...)
0
 
ozymandiasCommented:
Don't worry about it, these things happen.
I nearly came back and added the bit about converting a string to bytes but thought that was kinda overkill.
0
 
muzzy2003Commented:
:)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now