Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I want to open the pdf file in the browser which is stored in server side folder.
how to map that path in .net and how to do its coding in asp.net with c# provide me tutorial.


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;


public partial class open_pdf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_open_Click(object sender, EventArgs e)
    {
        string open_path = Server.MapPath("~/upload/IPM.pdf");
        WebClient client = new WebClient();
        Byte[] buffer = client.DownloadData(open_path);
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", buffer.Length.ToString());
        Response.BinaryWrite(buffer);
        Response.Flush();
        Response.End();
    }
}




XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="open_pdf.aspx.cs" Inherits="open_pdf" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Button ID="btn_open" runat="server" OnClick="btn_open_Click" Text="open pdf" />

    </div>
    </form>
</body>
</html>


That open the pdf but in exist tab not new tab or new window
Posted
Updated 6-Jan-14 22:54pm
v2
Comments
Kornfeld Eliyahu Peter 7-Jan-14 2:34am    
Have you done some research? Let us see!
Karthik_Mahalingam 7-Jan-14 3:15am    
post your code.
An@mik@ 7-Jan-14 4:16am    
give solustion
An@mik@ 7-Jan-14 4:55am    
I update the question and post my code

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900