Solved

How to open pdf files in iframe

Posted on 2009-04-14
6
4,025 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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