我有一个网格,显示文件夹中所有 pdf 文件的名称和链接。该链接在浏览器中打开文件。
这并不理想,因为浏览器会缓存文件,因此如果文档被移动或更改,旧的缓存版本仍然可以访问。
是否可以让链接在默认安装的 pdf 查看器中打开文件并完全避免缓存?
这是我的网格代码:
<form runat="server">
Search for a file: <asp:TextBox ID="txtFilter" runat="server"></asp:TextBox>
<asp:Button ID="btnShow"
runat="server" Text="Display" onclick="btnShow_Click" />
</form>
<asp:DataGrid runat="server" id="FileList" Font-Name="Verdana" CellPadding="5"
AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name" target="_blank"/>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time"
ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
</Columns>
</asp:DataGrid>
CS:
protected void btnShow_Click(object sender, EventArgs e)
{
ShowData();
}
public void ShowData()
{
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(""));
FileInfo[] info = dirInfo.GetFiles("*.pdf"); //Get FileInfo and Save it a FileInfo[] Array
List<Getfiles> _items = new List<Getfiles>(); // Define a List with Two coloums
foreach (FileInfo file in info) //Loop the FileInfo[] Array
_items.Add(new Getfiles { Name = file.Name, LastWriteTime = file.LastWriteTime.ToString("MM/dd/yyyy") }); // Save the Name and LastwriteTime to List
var tlistFiltered1 = _items.Where(item => item.Name.Contains(txtFilter.Text)); // Find the file that Contains Specific word in its File Name
FileList.DataSource = tlistFiltered1; //Assign the DataSource to DataGrid
FileList.DataBind();
}
public class Getfiles
{
public string Name { get; set; }
public string LastWriteTime { get; set; }
}