I have a gridview having field:
<asp:TemplateField HeaderText="View File">
<ItemTemplate >
<asp:HyperLink ID="LinkView" runat="server" Target="_blank"></asp:HyperLink>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
In code behind, (Gridview's RowBound)
Dim lnk As HyperLink = DirectCast(e.Row.FindControl("LinkView"), HyperLink)
lnk.Attributes.Add("onclick", "OpenPdf('" + "file://" + fileName + "')")
Ex. fileName: E:\\MyFolder\\F1\\File_01_15_2013_000100.pdf
And javascript function:
function OpenPdf(path1) {
window.open(path1);
}
But it's not working. In IE, I'm getting an error: Access denied
and in Firefox: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMJSWindow.open]
You are given the physical path of the file instead you have to give the virtual path of the file, like
fileName = "http://yourdomain.com/files/a.pdf"
You need to put the file in website directory structure for path accessible through your domain. Suppose your current page is at root and pdf file in files folder. If do not want to put the images in the virtual directory of your website then you can create a new virtual directory having your files.
Make a virtual directory inside your website and give path of folder that is outside your website folder and has images. Now this folder will act as it is part of your website and you will not get error. How to create Virtual Directory, MSDN
Suppose you have website folder d:\\Yoursites\\Testsite and you want to access files within d:\\file\\a.pdf, make a virtual directory in side TestWebsite pointing to d:\\files and access files within it through virual directory.
The URL for pdf would be something like
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.