Solved

How to open pdf files in iframe

Posted on 2009-04-14
6
4,042 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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