Click here to Skip to main content
14,383,148 members
Rate this:
Please Sign up or sign in to vote.
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????
Updated 28-Jan-13 1:16am
Rate this:
Please Sign up or sign in to vote.

Solution 1

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???
Sushil Mate 28-Jan-13 6:36am
just follow the my solution & it will do the rest
Deenuji 28-Jan-13 7:35am
so getting error only
Rate this:
Please Sign up or sign in to vote.

Solution 2

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:
<!--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")%>'/>

protected void Gridview_RowCommand(Object sender, GridViewCommandEventArgs e)
   if(e.CommandName == "View")

public void DownloadFile(string FilePath)
    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";

Hope it helps!
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 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.
Deenuji 28-Jan-13 7:21am
Actually i can't find link button in that have only hyperlink what to do sir?
_Amy 28-Jan-13 7:25am
You need to change it to LinkButton. Try replacing your asp:HyperLink to asp:LinkButton. If you are still unable to do that then paste your HTML code here. I'll check that.
Deenuji 28-Jan-13 7:32am
now i'm trying with this coding

<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:HyperLinkField DataTextField="Result" DataNavigateUrlFields="Result" DataNavigateUrlFormatString="Show.aspx?Result={0}" Text="Result"
HeaderText="Link" />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("Result") + Request.QueryString("type") %>'

_Amy 28-Jan-13 7:36am
Add the following in your GridView:

<asp:LinkButton ID="lnkView" runat="server" Text="View Document" CommandName="View" CommandArgument='<%#EVal("Result")%>'/>
Deenuji 28-Jan-13 7:42am
After that what i do to select that particular link and view that file????
Deenuji 28-Jan-13 7:48am
Error is The name 'EVal' does not exist in the current what we declare the value for Eval???? thn whr v ve to declare this???
_Amy 28-Jan-13 8:30am
It's not EVal its Eval. Sorry I mistyped that word.
Deenuji 28-Jan-13 8:42am
sir again doubt????
_Amy 28-Jan-13 22:33pm
Check the link below for similar post:
Open PDF file on button click or hyperlink from[^]

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100