Solved

How to open pdf files in iframe

Posted on 2009-04-14
6
3,941 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

18 Experts available now in Live!

Get 1:1 Help Now