Spaces in filenames causing 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's adding '#' in the place of space in file name which creating problems for me. Can anybody tell solution to
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);
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>");
}
精彩评论