Gridview mit herunterladen und anzeigen von pdf-Dateien in asp.net & c#

Alles funktioniert gut, bis die pdf-Datei sollte in der Lage sein werden, auf die geklickt n viewd auf den browser.Obwohl der download-link funktioniert perfekt.

Mein raster...

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText = "No files uploaded">
<Columns>
    <asp:BoundField DataField="FileDate" HeaderText="Dated" />
    <asp:BoundField DataField="FileName" HeaderText="File Name" />
    <asp:TemplateField>
        <ItemTemplate>
            <asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%#   Eval("FilePath") %>' runat="server" OnClick = "DownloadFile" ></asp:LinkButton>
             <asp:LinkButton ID="btnOpen" Text="View" Font-Bold="true" runat="server" onclick="btnpdf_Click" /></asp:LinkButton>
        </ItemTemplate>
    </asp:TemplateField>
        </Columns>
    </asp:GridView>

Meiner Klasse

public class Thing
{

    public string FilePath { get; set; }
    public string FileName { get; set; }
    public string FileDate { get; set; }
}

Meine PageLoad

 string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
        List<Thing> lst = new List<Thing>();
        foreach (string filePath in filePaths)
        {
            lst.Add(new Thing() 
            { 

                //FileDate = File.GetCreationTime(filePath).ToShortDateString(),
                FileDate = Path.GetFileName(filePath.Substring(0,35)),
                FileName = Path.GetFileName(filePath.Substring(36)), 
                FilePath = filePath 
            });
        }
        GridView1.DataSource = lst;
        GridView1.DataBind();

Meine download-button

string filePath = (sender as LinkButton).CommandArgument;
    Response.ContentType = ContentType;
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath.Substring(36)));
    Response.WriteFile(filePath);
    Response.End();

Meine pdfview

string filePath = (sender as LinkButton).CommandArgument;
    Response.ContentType = "Application/pdf";
    //Get the physical path to the file.
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath.Substring(36)));
    //Write the file directly to the HTTP content output stream.
    Response.WriteFile(filePath);
    Response.End();

Immer noch kann ich nicht die pdf-Datei anzeigen, die auf einem browser...pls help

InformationsquelleAutor shaiToro | 2014-11-14
Schreibe einen Kommentar