Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
SQL
Select   Result.No                  URL 

Select     2   C:\Users\FABS\Documents\Xml Search\upload\count.xml
Select     3   C:\Users\FABS\Documents\Xml Search\upload\Doc.xml



My Gridview Showing like this ......then in URL column bind as link button in gridview
....Now problem is how to open or how to show that document when i click this URL link in gridview table....Pls help me????
Posted
Updated 28-Jan-13 0:16am
v3

 
Share this answer
 
Comments
Deenuji 28-Jan-13 6:25am    
Actually i have doubt on this?
Sushil Mate 28-Jan-13 6:26am    
what is that doubt?
Deenuji 28-Jan-13 6:28am    
i have url on this link but when i click this link i want to open or view that clicked xml document?
Sushil Mate 28-Jan-13 6:30am    
you will, you don't have to worry about it. windows has the association between .xml to internet explorer so whenever user clicks on that link it will open that XML document in IE.
Deenuji 28-Jan-13 6:32am    
s but how to select that particular link and redirect to open???
If you want to open the file normally then you can use Response.Redirect(YourFilePath). And if you want to download the file then you can use the function below. Call the function in your RowCommand Event of GridView and pass the path of corresponding file. Try this:
ASP.NET
<!--This should be there in your aspx file inside gridview itemtemplate-->
<asp:LinkButton ID="lnkView" runat="server" Text="View Document" CommandName="View" CommandArgument='<%#EVal("URL")%>'/>

C#
protected void Gridview_RowCommand(Object sender, GridViewCommandEventArgs e)
{
   if(e.CommandName == "View")
   {
       DownloadFile(e.CommandArgument.ToString());
   }
}

public void DownloadFile(string FilePath)
{
    Response.Clear();
    Response.ContentType = @"application\octet-stream";
    System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(FilePath));
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(file.FullName);
    Response.Flush();
}



Hope it helps!
--Amit
 
Share this answer
 
v2
Comments
Deenuji 28-Jan-13 6:34am    
superb sir....but how to select that particular link and redirect to open??????
Deenuji 28-Jan-13 6:37am    
for example i have link like C:\Users\FABS\Documents\Xml Search\upload\count.xml in gridview.....how can i pass this selected link to open through redirect??????
_Amy 28-Jan-13 6:41am    
Pass it using CommandArgument property of LinkButton. Try my updated answer.. All the best.
Deenuji 28-Jan-13 6:46am    
Error Creating Control -'System.Web.UI.WebControls.HyperLinkField' does not have a public property named 'CommandName' ....
I'm getting this error sir...
_Amy 28-Jan-13 6:48am    
You should use LinkButton not HyperLink.. Check my answer carefully.

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