Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i am exporting data from gridview to excel for some data.

In that, one of the cell which contains hyperlink in the excel sheet cell.

when i click the hyperlink in the excel, then i received popup like "Microsoft Excel Security Notice" followed by "cannot download the information you requested".

How to solve this problem.

SQL Query to map with gridview

IF @Spd_Type='Exportdata' 

Create Table #Pkids(ID Int) 
Insert into #Pkids 
SELECT R.i.query('Pkid').value('.', 'VARCHAR(20)') 
FROM @Spd_XML.nodes('/DocumentElement/Test') R(i) 

Case When EmpNo ='' Then '' Else 'http://sas02.sanet.sam.intranet/D2/servlet/Download?auth=basic&event_name=d2_view&_docbase=uatprjarea&id=09139&version=CURRENT' End PDFEmpNo, 
From tbl_Student 
Where A.Pkid in(Select * from #Pkids)


<asp:GridView ID="grdEmp" AutoGenerateColumns="false" HeaderStyle-BackColor="Yellow"
ShowHeader="false" runat="server">

<%# DataBinder.Eval(Container.DataItem, "EmpName")%>
<asp:Label ID="lblPOPDF" runat="server" Text='<%# Eval("EmpNo") %>' Visible="false" />
<asp:HyperLink ID="lnkbtnDownload" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "POFEmpNo")%>'
Text='<%# Eval("EmpNo") %>' runat="server"></asp:HyperLink>
<%# DataBinder.Eval(Container.DataItem, "Dept")%>

ASP.NET.vb Code
Dim XML As String
XML = Session("XML").ToString

If XML = "<DocumentElement />" Then
Session("XML") = "NULL"
End If

Conn.sqlCmd.Parameters.AddWithValue("@Spd_Type", "ExportData")
Conn.sqlCmd.Parameters.AddWithValue("@Spd_XML", Session("XML").ToString)
ds = Conn.XcuteResult(str, CommandType.StoredProcedure, "SPD_StudentInfo")

grdEmp.DataSource = ds

Finally when i click the hyperlink i getting following error message.

Error : "cannot download the information you requested".

what is the solution for this..
Updated 14-Sep-16 9:41am
njammy 14-Sep-16 5:24am    
What happens when you access the url from your browser directly?
gani7787 16-Sep-16 0:58am    
getting Error : "cannot download the information you requested".
njammy 16-Sep-16 2:33am    
Then there is something wrong with the server not your code
Richard Deeming 14-Sep-16 9:00am    
You're not exporting an Excel file. You're exporting an HTML fragment, but sending a header to make the browser pretend that it's an Excel file. Excel then tries to import that HTML fragment into a new worksheet, but you'll have very little control over how that import works.

You'll probably have better luck if you export a real Excel file instead. There are several libraries which let you do that - for example, EPPlus[^], ClosedXML[^], and The OpenXML SDK[^].

NB: Don't try to use Office Interop to generate the file, as it's not supported in ASP.NET applications[^].
gani7787 14-Sep-16 9:29am    
Thanks for your great help.
your suggestions is great. can you pls. give one example to open http link using hyperlink in excel file. (http://sas02.sanet.sam.intranet/D2/servlet/Download?auth=basic&event_name=d2_view&_docbase=uatprjarea&id=09139&version=CURRENT) --> URL as empno like "1001"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900