Solved

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

Posted on 2006-11-13
10
3,570 Views
Last Modified: 2008-01-09
Hi,

I want to encode an URL in to Base64 in c# windows application.
Please help me.
0
Comment
Question by:vikasbapat
  • 5
  • 3
  • 2
10 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17929074
Get the URL string as byte[] and then do Convert.ToBase64String(byte[]);
0
 

Author Comment

by:vikasbapat
ID: 17929308
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17929363
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
 
LVL 16

Accepted Solution

by:
muzzy2003 earned 500 total points
ID: 17929364
(or something like that - typed outside of VS)
0
 

Author Comment

by:vikasbapat
ID: 17929416
It is working fine.

Thanks for quick responce.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:ozymandias
ID: 17929433
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
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17929730
Yes, agreed. And a B?
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17930036
(BTW ozymandias, hadn't intended to steal this one, just saw it in passing. Assumed you'd already basically won the points ...)
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17930163
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
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17930184
:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now