?
Solved

How to open pdf files in iframe

Posted on 2009-04-14
6
Medium Priority
?
4,083 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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