Reputation: 657
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's adding '#' in the place of space in file name which creating problems for me. Can anybody tell solution to
Upvotes: 3
Views: 983
Reputation: 4854
Try using Quotation Marks!
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>");
}
Upvotes: 2
Reputation: 46919
URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as a question mark (?), ampersand (&), slash mark (/), and spaces might be truncated or corrupted by some browsers. As a result, these characters must be encoded in tags or in query strings where the strings can be re-sent by a browser in a request string.
fileName = HttpServerUtility.UrlEncode(fileName);
Upvotes: 5