472,353 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Convert file path to URL

Hello Group

I have a fileserver with several files. Some of the filenames contain danish
characters (e.g. 'æ', 'ø', 'å'). Now I'm trying to make a web application in
C# that presents links to some of the files. I would like the user to be
able to open the file by clicking on the link.

I have the file:

"G:\My Documents\Anders Kåre Olsen.txt"

If I use this path as a link in MSIE, it automatically converts it to:

file:///G:/My%20Documents/Anders%20K%E5re%20Olsen.txt

However Firefox does not do this conversion automatically, and I have a
requirement that says that the page must work in MSIE and Firefox. If I copy
the URL from MSIE to Firefox, it works fine, so I just need to do the
conversion programmatically (in this case, I need to convert ' ' to '%20'
and 'å' to '%E5').

I have tried to use the HttpUtility.UrlPathEncode, but this method
apparantly have problems with the danish characters like 'å'. It converts
last path of the above path to:

/My%20Documents/Anders%20K%c3%a5re%20Olsen.txt

And not even MSIE likes the conversion of 'å' to %c3%a5.

Basically, is there an automatic way to convert the characters to something
that both browsers like. And why does C# convert 'å' to %c3%a5? Is it
because of unicode?

Regards

Anders Olsen

Nov 24 '05 #1
2 23475
Hi,

I am not 100% sure this will solve your problem. Assume that you have
the path in a string called 'str', you might want to try:

string result;
result = System.Web.HttpUtility.UrlEncode (
System.Text.Encoding.GetEncoding ( "ISO-8859-1" ).GetBytes ( str ) );

I think all danish characters should be covered by the ISO-8859-1 codepage.

-Lenard

Anders K. Olsen wrote:
Hello Group

I have a fileserver with several files. Some of the filenames contain danish
characters (e.g. 'æ', 'ø', 'å'). Now I'm trying to make a web application in
C# that presents links to some of the files. I would like the user to be
able to open the file by clicking on the link.

I have the file:

"G:\My Documents\Anders Kåre Olsen.txt"

If I use this path as a link in MSIE, it automatically converts it to:

file:///G:/My%20Documents/Anders%20K%E5re%20Olsen.txt

However Firefox does not do this conversion automatically, and I have a
requirement that says that the page must work in MSIE and Firefox. If I copy
the URL from MSIE to Firefox, it works fine, so I just need to do the
conversion programmatically (in this case, I need to convert ' ' to '%20'
and 'å' to '%E5').

I have tried to use the HttpUtility.UrlPathEncode, but this method
apparantly have problems with the danish characters like 'å'. It converts
last path of the above path to:

/My%20Documents/Anders%20K%c3%a5re%20Olsen.txt

And not even MSIE likes the conversion of 'å' to %c3%a5.

Basically, is there an automatic way to convert the characters to something
that both browsers like. And why does C# convert 'å' to %c3%a5? Is it
because of unicode?

Regards

Anders Olsen

Nov 24 '05 #2
"Lenard Gunda" <ar***********@freemail.hu> wrote in message
news:eB****************@TK2MSFTNGP12.phx.gbl...
Hi,

I am not 100% sure this will solve your problem. Assume that you have the
path in a string called 'str', you might want to try:

string result;
result = System.Web.HttpUtility.UrlEncode (
System.Text.Encoding.GetEncoding ( "ISO-8859-1" ).GetBytes ( str ) );

I think all danish characters should be covered by the ISO-8859-1
codepage.


Yes, all danish characters are covered by ISO-8859-1.

I almost worked. The only problem left was that UrlEncode converted a space
(' ') to a plus ('+'), and the browsers didn't like that. However it was
easy to use String.Replace("+","%20") on the result.

Thank you for your help.

Regards
Anders
Nov 24 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: James Geurts | last post by:
Hi all, I'm trying to convert a string representing a path to Dos 8.3 notation. The code that I have works fine if the path exists, but it will...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: ...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
by: Martin | last post by:
I would like to convert this code to VB.NET. Can someone help. Thanks. Dim X() Dim i As Long Dim objShell, objFolder, objFolderItem Dim FSO,...
2
by: Anders K. Olsen | last post by:
Hello group I would like to make a link to a file, but how do I convert the file path to a URL? I have the file: "G:\My Documents\Anders...
13
by: kbperry | last post by:
Hi all, Background: I need some help. I am trying to streamline a process for one of our technical writers. He is using Perforce (version...
10
by: Andrew Backer | last post by:
I have a few file:///c:/windows/somewhere style uris that I need to convert to the actual physical path. I am hoping there is a built in way to...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.