0

I am making an application which shares files to the user in asp.net c#... I have a grid with column username and filename with a link

Now I want that when I click on filename(can be text, images, doc, PDF) the file should open on different page

My code for aspx page is as below

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"
        CssClass="grid" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" 
        BorderWidth="1px" onrowcommand="GridView1_RowCommand">
        <RowStyle ForeColor="black" />
        <Columns>
            <asp:TemplateField HeaderText="File Name">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("FileName") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Who shared">
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle Width="200px" />
            </asp:TemplateField>

            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%#((GridViewRow)Container).RowIndex%>'
                        Text='<%# Bind("FileName") %>' CommandName="ViewImages" ></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="black" Font-Bold="True" ForeColor="White" />
    </asp:GridView>

How to open the file in other page so that user can see the content of files online????

Pritesh
  • 63
  • 1
  • 3
  • 11
  • I think you can get your answer here http://stackoverflow.com/questions/9255427/c-sharp-target-blank-in-a-linkbutton – Zleepy Feb 19 '13 at 06:19

1 Answers1

0

You can use handler for opening or downloading any format file. & for new page give target="_blank" to your link. Please find the handler code as here: http://pastie.org/6221636

& call it like '../MyHandler.ashx?ID=filename.txt'

If you have only issue with opening the new tab have look to How to open a page in a new tab in the rowcommand event of gridview?

Community
  • 1
  • 1
Neha
  • 2,933
  • 3
  • 19
  • 23
  • I can open the .txt files online with the code in http://pastie.org/6221636 but not able to open .doc file online. The save as window will open in case of.doc files – Pritesh Feb 19 '13 at 07:19
  • i have commented if (forceDownload) { context.Response.AppendHeader("content-disposition", "attachment; filename=\"" + name + "\""); } if (type != "") context.Response.ContentType = type; – Pritesh Feb 19 '13 at 07:22
  • try to use Response.TransmitFile(file.FullName); – Neha Feb 19 '13 at 07:23
  • if you comment these lines it will not work as you need to mention the header & response type – Neha Feb 19 '13 at 07:24
  • if i will not comment then i have to download the files... but i want to display the file's content without downloading it – Pritesh Feb 19 '13 at 07:35
  • where i have to write Response.TransmitFile(file.FullName); – Pritesh Feb 19 '13 at 07:35
  • replace it context.Response.WriteFile(path); with context.Response.TransmitFile(path); – Neha Feb 19 '13 at 07:39
  • i want like http://blog.maartenballiauw.be/post/2008/01/11/Preview-Word-files-%28docx%29-in-HTML-using-ASPNET-OpenXML-and-LINQ-to-XML.aspx – Pritesh Feb 19 '13 at 08:38
  • the difference is here: context.Response.AppendHeader("content-disposition", "inline; filename=\"" + name + "\"");, it uses inline. anyways this much I can do. Thanks. – Neha Feb 19 '13 at 10:06
  • ya i know... but the output is same – Pritesh Feb 19 '13 at 10:29
  • i have also gone through the below link but i can see save as window. i want to display the file content in the web page only http://stackoverflow.com/questions/1549929/display-word-pdf-excell-etc-files-in-browser-asp-net-c-net-2008?answertab=active#tab-top – Pritesh Feb 19 '13 at 12:01