Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open file from database listed in a Repeater 1

Status
Not open for further replies.

dstrange

Programmer
Nov 15, 2006
87
CA
Hello, I have a nested repeater that displays the title of saved documents from a database. How can I make the Linkbutton for each listed file title a hyperlink to open/save/cancel the file from the database?

Code:
        <asp:Repeater ID="repMenu1" runat="server">
            <HeaderTemplate>
            <asp:Label ID="Label1" runat="server" Text="Category: "></asp:Label>
            </HeaderTemplate>
            <ItemTemplate>               
                <%#DataBinder.Eval(Container.DataItem, "category")%>
                <asp:Repeater ID="repMenu2" runat="server">
                    <HeaderTemplate>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div style="margin-left:15px;">
                            <asp:Image ID="Image1" runat="server" ImageUrl='<%# GetImageURL(Eval("DocumentType")) %>'></asp:Image> 

                            <asp:LinkButton ID="LinkButton1" runat="server" Font-Size="Small" class="" CausesValidation="false" 
                                 Text='<%# Eval("DocumentTitle") %>' 
                                 OnClick="OpenFile" >
                            </asp:LinkButton>  
                            <br />
                        </div>
                    </ItemTemplate>
                    <FooterTemplate>
                    <br />
                    </FooterTemplate>
                    
                </asp:Repeater>
 
search the web for examples of opening an image from a database, the same concepts apply. I would use an IHttpHandler instead of a webform, you don't need the overheader.

in it's simplest form it will look like this
Code:
class DocumentHandler : IHttpHandler
{
   public bool IsResuable { get { return false;} }

   public void Process(HttpContext context)
   {
       object id = context.Request.Params["key"];
       byte[] bytes = GetBlobFromDataBaseWith(id);

       context.ContentType = "type of document";
       context.AppendHeader("Content-Disposition",string.Format("attachment;filename={0}", name of file));
       context.BinaryWrite(bytes);
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Thanks jmeckley. I figured out a similar response but your reply sums up what I wanted to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top