473,396 Members | 2,154 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 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 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.

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.

Regards

Anders Olsen
Nov 23 '05 #1
2 3183
"Anders K. Olsen" wrote ...
And not even MSIE likes the conversion of 'å' to %c3%a5.


Hi Anders,

If it were me I would do the following...

Store the references to the documents in a database, store the "original"
name, but also a browser friendly name, ie, strip out all special
characters, spaces and anything else which potentially could cause problems.
Have a function that will "ProperCase" the remaining words, join them all
together and store this as the file name.

Create a "download" page which takes an id from your hyperlink and runs off
to the database to get the file. It can then pick up both names, the
original one to locate the file on your pc/server, and the browser friendly
one to give/send to the user.

Your URL that you display may look something like this:

http://www.yoursite.com/Download.aspx?fid=123

You could in addition then, also add to that page a routine to determine if
the file should be available to the user or not, based on perhaps a flag,
and obsolete date or whatever, thus increasing the scope of what you can do.

I trust this information is of use to you.

Regards

Rob
Nov 23 '05 #2
"Rob Meade" <ku***************@edaem.bor> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Anders K. Olsen" wrote ...
And not even MSIE likes the conversion of 'å' to %c3%a5.


Hi Anders,

If it were me I would do the following...

Store the references to the documents in a database, store the "original"
name, but also a browser friendly name, ie, strip out all special
characters, spaces and anything else which potentially could cause
problems. Have a function that will "ProperCase" the remaining words, join
them all together and store this as the file name.

Create a "download" page which takes an id from your hyperlink and runs
off to the database to get the file. It can then pick up both names, the
original one to locate the file on your pc/server, and the browser
friendly one to give/send to the user.

Your URL that you display may look something like this:

http://www.yoursite.com/Download.aspx?fid=123

You could in addition then, also add to that page a routine to determine
if the file should be available to the user or not, based on perhaps a
flag, and obsolete date or whatever, thus increasing the scope of what you
can do.


Hello Rob

Thank you for your fast answer. I might be able to do some of what you are
suggesting.

The files are located on a file server and I'm not allowed to change
anything on the files.

My webapplication lists some of the files, and the user must be able to open
the file dirrectly from my webpage. But this might still be possible with
the Download.aspx page you suggest. I guess it would be possible to return
the browserfriendly name as a link to the file on the fileserver.

I'm already storing the file paths in a database, and the reason for asking
this qustion was that I was unsure of how to generate the browser frinedly
name. I was hoping that there was some function in .Net that I could use for
this purpose.

But I will deffinately give some more thought to what you suggested with the
Downloads.aspx page.

Regards

Anders
Nov 23 '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 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...
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...
5
by: sonu | last post by:
hey good morning ...... how to convert a video file in .flv format in php for linux hosting......is there any package whis provide this facility . Can i use ffmpeg for linux hosting...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.