Spaces in the file names causing the problem

FileInfo[] FileList1 = Dir.GetFiles("*.doc", SearchOption.AllDirectories);
foreach (FileInfo FI in FileList1)
{
    Response.Write(
        "<td><a href= view5.aspx?file=" + strheadlinesid + "\\" + 
        FI.Name + " target=_self;> " +FI.Name + "</a></td>");
}

When I tried to print file names with spaces, it adds '#' instead of space in the file name, which creates problems for me. Can anyone tell a solution for

+3
source share
2 answers

URL coding ensures that all browsers will correctly convey text in URL strings. Characters such as the question mark (?), Ampersand (&), label (/), and spaces may be truncated or damaged by some browsers. As a result, these characters must be encoded in tags or in query strings, where strings can be re-sent by the browser in the query string.

fileName = HttpServerUtility.UrlEncode(fileName);
+5
source

Try using quote tags!

FileInfo[] FileList1 = Dir.GetFiles("*.doc", SearchOption.AllDirectories);
foreach (FileInfo FI in FileList1)
{
    Response.Write(
        "<td><a href=\"view5.aspx?file=" + strheadlinesid + "\\" + 
        FI.Name + "\" target=\"_self\"> " +FI.Name + "</a></td>");
}
+2
source

All Articles