473,396 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 23643
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 not work if the path does not exist. I am looking...
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: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
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 the local filesystem. What I want to do is use a...
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, oFolder, Fil Sub MainExtractData()
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 Kåre Olsen.txt" If I use this path as a link in...
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 control system), and is constantly changing his word...
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 handle this. I know I can do some text replacing...
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 java so that you can conceal sensitive information...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.