?
Solved

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

Posted on 2006-11-13
10
Medium Priority
?
3,604 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
LVL 16

Accepted Solution

by:
muzzy2003 earned 1500 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
 
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

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.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

764 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