locked
MS Access connected with asp.net; access on file attachements saved in accdb File RRS feed

  • Question

  • User-623365515 posted

    Hey folks,

    here another question:

    i inserted the MS Access Database with drag and drop and modified the sql-code. Following Code:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataSourceID="AccessDataSource1" 
                EmptyDataText="Es sind keine Datensätze zum Anzeigen vorhanden." Width="918px">
                <Columns>
                    <asp:BoundField DataField="Titel" HeaderText="Titel" SortExpression="Titel" />
                    <asp:BoundField DataField="Beschreibung" HeaderText="Beschreibung" 
                        SortExpression="Beschreibung" />
                    <asp:BoundField DataField="Fälligkeitsdatum" HeaderText="Fälligkeitsdatum" 
                        SortExpression="Fälligkeitsdatum" />
                    <asp:BoundField DataField="Anlagen" HeaderText="Anlagen" 
                        SortExpression="Anlagen" />">
                    <asp:BoundField DataField="ProgramName" HeaderText="ProgramName" 
                        SortExpression="ProgramName" />
                </Columns>
            </asp:GridView>
            <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                DataFile="App_Data\Aufgaben.accdb" 
                SelectCommand="SELECT [Titel], [Beschreibung], [Fälligkeitsdatum], [Anlagen], [ProgramName] FROM [Aufgaben] WHERE ([Öffentlich ALL] = ?)">
                <SelectParameters>
                    <asp:Parameter DefaultValue="true" Name="Öffentlich_ALL" Type="Boolean" />
                </SelectParameters>
            </asp:AccessDataSource>

    The field "Anlagen" is an attachement field in die *.accdb File, where I put in my pdf-Files...

    Question is now: Can i somehow manage to open the file by clicking on that name of the f.e. pdf-file on the webpage? Those files will just be pdf files... and of course should automatically be opened by the standard pdf program..

    Thx in advance ;)

    greetings 

    Benedikt

    Tuesday, January 31, 2012 11:55 AM

Answers

  • User3866881 posted

    My suggestion is that  you can:

    1)Create or add a TemplateField into the GridView,Something like this:

    <asp:TemplateField ……>

       <ItemTemplate>

             <a href='pdfhandler.ashx?id=<%#Eval("Id")%>'>PDF Download</a>

       </ItemTemplate>

    </asp:TemplateField>

    And your pdfhandler.ashx should read out the specific column from the existing db with the help of AccessDataBase,and then set——

    Response.Clear();
    Response.AddHeader(”Content-Disposition”,”attachment;filename=xxx.pdf”);
    Response.ContextType="application/pdf";
    Response.BinaryWrite(bytes of pdf read out from accessdb); 

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 1, 2012 9:01 PM