• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3644
  • 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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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