Click here to Skip to main content
Rate this: bad
good
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????
Posted 28-Jan-13 1:15am
Deenuji3.8K
Edited 28-Jan-13 1:16am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Deenuji at 28-Jan-13 6:25am
   
Actually i have doubt on this?
Sushil Mate at 28-Jan-13 6:26am
   
what is that doubt?
Deenuji at 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 at 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 at 28-Jan-13 6:32am
   
s but how to select that particular link and redirect to open???
Sushil Mate at 28-Jan-13 6:36am
   
just follow the my solution & it will do the rest
Deenuji at 28-Jan-13 7:35am
   
so getting error only
Rate this: bad
good
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")
   {
       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
  Permalink  
v2
Comments
Deenuji at 28-Jan-13 6:34am
   
superb sir....but how to select that particular link and redirect to open??????
Deenuji at 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 at 28-Jan-13 6:41am
   
Pass it using CommandArgument property of LinkButton. Try my updated answer.. All the best.
Deenuji at 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 at 28-Jan-13 6:48am
   
You should use LinkButton not HyperLink.. Check my answer carefully.
Deenuji at 28-Jan-13 7:21am
   
Actually i can't find link button in that gridview....it have only hyperlink only....now what to do sir?
_Amy at 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 at 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:TemplateField>

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("Result") + Request.QueryString("type") %>'
Text="">

_Amy at 28-Jan-13 7:36am
   
Add the following in your GridView:
 
<asp:TemplateField>

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

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

  Print Answers RSS
0 OriginalGriff 359
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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