Convert file path to URL

  • Thread starter Thread starter Anders K. Olsen
  • Start date Start date
A

Anders K. Olsen

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
 
...
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
 
Rob Meade said:
...


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