Solved

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

Posted on 2006-11-13
10
3,583 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 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