我的数据列表中包含_File列,其中包含要下载的文件名
我想隐藏那些链接断开的记录(dos没有文件位于blabla位置)
我尝试使用此
public bool RemoteFileExists(string url)
{
try
{
//Creating the HttpWebRequest
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest;
//Setting the Request method HEAD, you can also use GET too.
request.Method = "HEAD";
//Getting the Web Response.
System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse;
//Returns TRUE if the Status code == 200
return (response.StatusCode == System.Net.HttpStatusCode.OK);
}
catch
{
//Any exception will returns false.
return false;
}
}
ASPX
<% if (RemoteFileExists("www.*****/" + Eval("_File").ToString() + ".pdf"))
{
%>
<tr>
<td style="background-color: white; border-bottom: 1px solid #dbdbdb" width="700">
<div style="font-size: 16px; width: 600px; margin-top: 2px; display: block; float: left; color: black;"><%# Eval("Title") %></div>
<div style="font-size: 11px; width: 600px; display: block; float: left; margin-top: -3px; color: gray;"><%# Eval("Department") %>, <%# Eval("Program") %>, <%# Eval("Semester") %></div>
<a style="float: right; font-size: 12px; padding-left: 18px; padding-right: 5px; margin-right: -4px; margin-top: 0px" target="_blank" class="downloadIcon" href='<%# "1913/" + Eval("_File") + ".pdf" %>'>Download</a></td>
</tr>
<%
}
%>
我收到此错误==数据绑定方法(如Eval(),XPath()和Bind()只能在数据绑定控件的上下文中使用
我得到的解决方案基本上url文字错误,也需要输入http://。
<div runat="server" visible=<%# RemoteFileExists("http://www.***/" + Eval("_File").ToString() + ".pdf") %>>
<tr>
<td style="background-color: white; border-bottom: 1px solid #dbdbdb" width="700">
<div style="font-size: 16px; width: 600px; margin-top: 2px; display: block; float: left; color: black;"><%# Eval("Title") %></div>
<div style="font-size: 11px; width: 600px; display: block; float: left; margin-top: -3px; color: gray;"><%# Eval("Department") %>, <%# Eval("Program") %>, <%# Eval("Semester") %></div>
<a style="float: right; font-size: 12px; padding-left: 18px; padding-right: 5px; margin-right: -4px; margin-top: 0px" target="_blank" class="downloadIcon" href='<%# "1913/" + Eval("_File") + ".pdf" %>'>Download</a></td>
</tr>
</div>