Solved

How to open pdf files in iframe

Posted on 2009-04-14
6
3,928 Views
Last Modified: 2012-06-27
By Clicking Option in tree view content(pdf files) should open in i frame control.
0
Comment
Question by:mannevenu
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Nirmalan Nagenthiran
ID: 24136894
0
 
LVL 9

Expert Comment

by:tetorvik
ID: 24137007
See the snippets below. For more convenient user experience wrap treeview and iframe into UpdatePanel.
*.ASPX             

    <asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">

                    <Nodes>

                        <asp:TreeNode Text="root" Value="root">

                            <asp:TreeNode Text="Content1" Value="Somefile1.pdf" ></asp:TreeNode>

                            <asp:TreeNode Text="Content2" Value="Somefile2.pdf"></asp:TreeNode>

                            <asp:TreeNode Text="Content3" Value="Somefile3.pdf"></asp:TreeNode>

                        </asp:TreeNode>

                    </Nodes>

                </asp:TreeView>

                <iframe src="" id="iframe" runat="server"></iframe>
 
 

Code-behind:
 

        public void TreeView1_SelectedNodeChanged(object sender, EventArgs e)

        {

            iframe.Attributes["src"] = "somefile.pdf";

        }

Open in new window

0
 
LVL 9

Expert Comment

by:tetorvik
ID: 24137100
Correction to SelectedNodeChanged -event. It should be like

public void TreeView1_SelectedNodeChanged(object sender, EventArgs e)

{

    iframe.Attributes["src"] = TreeView1.SelectedValue;

}

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:mannevenu
ID: 24137296
this is my code..my target is to display pdffiles in iframe control
 
 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {              
   
        try
        {
            //Node(a,b);
            //string Record = "SPR";
            SelectMaster SelectMaster = new SelectMaster();
            string qry = "select Content_Id,Record_Type,Description from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "' ";
            DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);
            string cid = dt_Fill_TV.Rows[0][0].ToString();
            string recort_type = dt_Fill_TV.Rows[0][1].ToString();
            string desc = dt_Fill_TV.Rows[0][2].ToString();
            if (recort_type.ToString().Equals("OPT"))
            {
                txtdesc.Visible = true;
                txtdesc.Text = desc.ToString();

            }
            //if (dt_Fill_TV.Rows.Count>0)
            //{
            //string cid = dt_Fill_TV.Rows[0][0].ToString();
            else
            {
                txtdesc.Visible = false;
                txtdesc.Text = "";
                string qry1 = "select File_Path  from Admn_Content_Mast where Id='" + cid.ToString() + "'";
                DataTable dt_Fill_TV1 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry1);
                string path = dt_Fill_TV1.Rows[0][0].ToString();
               

                string strPath =Server.MapPath("..\\Head_Office_Content" + "\\" + path.ToString());
                //string strPath ="D:\\ISiTech\\Head_Office_Content\\qry.txt";

                txtfile.Text = strPath;

                //System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                //myProcess.EnableRaisingEvents = false;
                //myProcess.StartInfo.FileName = strPath;,
                //myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                //myProcess.Start();
                if (File.Exists(strPath))
                {
                    //System.IO.FileInfo fi = new System.IO.FileInfo(strPath);
                    //Response.ClearContent();
                    //Response.ClearHeaders();
                    //Response.Clear();
                    //Response.ContentType = "application/octet-stream";//Set your MIME Type or refer links provided
                    //Response.AddHeader("Content-Disposition", "attachment;filename=" + fi.Name);
                    //Response.WriteFile(strPath);
                    //// Response.Flush();    
                    ////Response.Close();
                    //Response.End();

                    //HtmlGenericControl iframe = new HtmlGenericControl("iframe");
                    //iframe.ID = "doc";
                    //iframe.Style.Add("FONT-SIZE", "11px");
                    //Controls.Add(iframe);
                    //iframe.Attributes.Add("str", strPath);
                    //iframe.DataBind();

                    //iframepdf.Visible = true;
                    //iframepdf.Attributes.Add("src", strPath);
                    //iframepdf.InnerText = strPath.ToString();
                    //iframepdf.DataBind();
                    //iframepdf.GetType();
                    //iframe.Visible = true;
                    //iframe.Attributes["src"] = strPath;
                    iframe.Attributes["src"] = strPath;


                    //System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                    //myProcess.EnableRaisingEvents = false;
                    //myProcess.StartInfo.FileName = strPath;
                    //myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                    //myProcess.Start();
                }
                else
                {
                    string strMsg = "No file to view.";

                    Label lbl = new Label();

                    lbl.Text = ("<script language=\'javascript\'>"

                    + (Environment.NewLine + ("window.alert(" + ("\'"
                    + (strMsg + ("\'" + ")</script>"))))));
                    Page.Controls.Add(lbl);

                }
            }
            //}
            //else
            //{
            //}

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
            TreeView1.Visible = false;
        }
}
0
 
LVL 9

Accepted Solution

by:
tetorvik earned 500 total points
ID: 24137489
Make sure your strPath is a virtual path (accessible via browser) to your pdf documents. Looks like you're now using physical path with Server.MapPath.
0
 

Author Comment

by:mannevenu
ID: 24183217
ok i will check it
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now