Displaying list of files - issue

  • Thread starter Thread starter hartbypass
  • Start date Start date
H

hartbypass

Hello all,

I have a small piece of code that goes and gets the files in a
directory and displays them as hyperlinks on a webpage so people can
access those files. I am running into an issue where is the filename
has a space it breaks the link. Meaning if have /Docs/Files/My First
File.pdf, all I get in the link is /Docs/Files/My

I thouht maybe I needed to somehow parse the file and replace spaces
with %20, but I am not sure. I would like to find a solution other
than Don't have spaces in the file name.

Thanks,
Greg
 
Well I came up with this.

newName = f.Name.Replace(" ","%20");
newName = appPath + newName;

Seems to work, but is it the right way?
 
Greg,

What you want to do is run the file name through the UrlPathEncode
method exposed on the HttpServerUtility object exposed through the Server
property on the Page object and set your link to the return value of that.

Hope this helps.
 
Back
Top