Solved

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

Posted on 2006-11-13
10
3,562 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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