Link to home
Start Free TrialLog in
Avatar of mannevenu
mannevenu

asked on

Tree view Problem

hi sir,


                I have one tree view.In that i click on any links in that tree view,pdf files and word files are open.But these files are open in local system.When I placed These files in internet.pdf files are not open.I send my code aspx and cs files below
cs file:
public partial class CampusCenter_Creating_Users : System.Web.UI.Page
{
    InsertMaster Insert;
    UpdateMaster Update;
    DeleteMaster Delete;
    ExpDetails exDetails;
 
    string ClientIPAdd;
    string xmlPath;
    string scriptText;
    string parent1,batch,course;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["ConStr"] = ConfigurationSettings.AppSettings["ConStr"].ToString();
        string HostName = System.Net.Dns.GetHostName();
        ClientIPAdd = System.Net.Dns.GetHostAddresses(HostName).GetValue(0).ToString();
        xmlPath = Server.MapPath("~") + "\\Exception_XML_File\\ExceptionalDetails.xml";
        //Session["Branch_ID"] = "121";
        if (Page.IsPostBack == false)
        {
            if (Request.Browser.Browser == "Firefox")
            {
                Form.Attributes.Add("autocomplete", "off");
            }
 
            BindBatch();
           // BindTerm();
            //AddNodesTreeview();
           //Populateroot();            
        }
 
    }
    public void BindBatch()
    {
        SelectMaster SelectMaster = new SelectMaster();
        //string qry = "select abm.Batch_Name,abcsm.Batch_Id from Admn_Batch_Mast abm,Admn_Batch_Course_Sem_Mast abcsm where abcsm.Batch_Id=abm.Batch_Id group by abcsm.Batch_Id,abm.Batch_Name ";
        string batch = "SELECT Admn_Batch_Branch.Batch_Id, Admn_Batch_Mast.Batch_Name";
        batch += " FROM Admn_Batch_Branch INNER JOIN";
        batch += " Admn_Batch_Mast ON Admn_Batch_Branch.Batch_Id = Admn_Batch_Mast.Batch_Id";
        batch += " WHERE(Admn_Batch_Branch.Branch_Id =  '" + Session["Branch_ID"].ToString() + "' )";
        DataTable dt_Fill1 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), batch);
        ddlBatch.DataSource = dt_Fill1;
        ddlBatch.DataTextField = dt_Fill1.Columns["Batch_Name"].ColumnName.ToString();
        ddlBatch.DataValueField = dt_Fill1.Columns["Batch_Id"].ColumnName.ToString();
        ddlBatch.DataBind();
        ddlBatch.Items.Add("-Select-");
        ddlCourse.Items.Add("-Select-");
        ddlBatch.SelectedIndex = ddlBatch.Items.Count - 1;
    }
    //public void BindTerm()
    //{
    //    SelectMaster SelectMaster = new SelectMaster();
    //    string qry = "select abcsm.Schedule_Id,acsm.Name from Admn_Course_Schedule_Mast acsm,Admn_Batch_Course_Sem_Mast abcsm where abcsm.Schedule_Id=acsm.Id group by abcsm.Schedule_Id,acsm.Name  ";
    //    DataTable dt_Fill2 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);
    //    ddlTerm.DataSource = dt_Fill2;
    //    ddlTerm.DataTextField = dt_Fill2.Columns["Name"].ColumnName.ToString();
    //    ddlTerm.DataValueField = dt_Fill2.Columns["Schedule_Id"].ColumnName.ToString();
    //    ddlTerm.DataBind();
    //    ddlTerm.Items.Add("-Select-");
    //    ddlCourse.Items.Add("-Select-");
    //    ddlTerm.SelectedIndex = ddlTerm.Items.Count - 1;
    //}
    public void BindCourse()
    {
        SelectMaster SelectMaster = new SelectMaster();
        //string qry = "select aicm.Name,abcsm.Course_Id from Admn_Internal_Course_Mast aicm,Admn_Batch_Course_Sem_Mast abcsm where abcsm.Course_Id=aicm.Course_Id group by aicm.Name,abcsm.Course_Id";
        string course = "SELECT Admn_Batch_Course.Course_Id, Admn_Internal_Course_Mast.Name";
        course += " FROM Admn_Batch_Course INNER JOIN";
        course += " Admn_Internal_Course_Mast ON Admn_Batch_Course.Course_Id = Admn_Internal_Course_Mast.Course_Id INNER JOIN";
        course += " Admn_Batch_Mast ON Admn_Batch_Course.Batch_Id = Admn_Batch_Mast.Batch_Id and Admn_Batch_Course.Batch_Id='" + ddlBatch.SelectedValue + "' ";
 
        DataTable dt_Fill3 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), course);
        ddlCourse.DataSource = dt_Fill3;
        ddlCourse.DataTextField = dt_Fill3.Columns["Name"].ColumnName.ToString();
        ddlCourse.DataValueField = dt_Fill3.Columns["Course_Id"].ColumnName.ToString();
        ddlCourse.DataBind();
        ddlCourse.Items.Add("-Select-");
        ddlCourse.SelectedIndex = ddlCourse.Items.Count - 1;
 
 
    }
 
    //protected void ddlTerm_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlTerm.SelectedItem.Text == "-Select-")
    //    {
    //        ddlCourse.Items.Clear();
    //        ddlCourse.Items.Add("-Select-");
    //    }
    //    else
    //    {
    //        BindCourse();
    //    }
    //}
   
    public void Populateroot()
    {
        SelectMaster SelectMaster = new SelectMaster();
        string qry = "select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount FROM Admn_Course_Organization sc where parent_Id IS NULL and Schedule_Id='1' and Course_Id='" + ddlCourse.SelectedValue + "'  ";
        DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);
 
        //SqlConnection con = new SqlConnection(con1);       
        //SqlCommand cmd = new SqlCommand("select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount FROM Admn_Course_Organization sc where parent_Id IS NULL", con);
        //SqlDataAdapter da = new SqlDataAdapter(cmd);
        //DataTable dts = new DataTable();
        //da.Fill(dts);
        PopulateNodes(dt_Fill_TV, TreeView1.Nodes);
 
 
    }
 
 
    private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)
    {
        foreach (DataRow dr in dt.Rows)
        {
            TreeNode tn = new TreeNode();
            tn.Text = dr["Name"].ToString();
            tn.Value = dr["Id"].ToString();
            nodes.Add(tn);
 
            //If node has child nodes, then enable on-demand populating
            tn.PopulateOnDemand = ((int)dr["childnodecount"] > 0);
        }
    }
 
 
    private void PopulateSubLevel(int parentid, TreeNode parentNode)
    {
        //SelectMaster SelectMaster = new SelectMaster();
        //string qry1 = "select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount FROM Admn_Course_Organization sc where Parent_Id=@Parent_Id";
        //DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry1);
 
 
 
        SqlConnection con = new SqlConnection(Session["ConStr"].ToString());
        string Record = "SPR";
        SqlCommand cmd = new SqlCommand("select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount FROM Admn_Course_Organization sc where Parent_Id=@Parent_Id and Record_Type<>'" + Record + "'", con);
        cmd.Parameters.Add("@Parent_Id", SqlDbType.Int).Value = parentid;
 
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        PopulateNodes(dt, parentNode.ChildNodes);
    }
 
 
    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        //int a = Convert.ToInt32(e.Node.Value);
        //PopulateSubLevel(a, e.Node);
        PopulateSubLevel(Int32.Parse(e.Node.Value), e.Node);   
    }
 
    protected void btnshow_Click(object sender, EventArgs e)
    {
       // AddNodesTreeview();
        //if (Page.IsPostBack == false)
        //{
        if (ddlBatch.SelectedItem.Text == "-Select-")
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('select batch'); }", true);
        }
        else if (ddlCourse.SelectedItem.Text == "-Select-")
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('select course'); }", true);
        }
        else
        {
            TreeView1.Nodes.Clear();
            Populateroot();
        }
        //}
 
    }
    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();
                    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;
        }
 
      
    }
    
 
 
 
    protected void TreeView1_TreeNodeExpanded1(object sender, TreeNodeEventArgs e)
    {
 
    }
    protected void ddlBatch_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlBatch.SelectedItem.Text == "-Select-")
        {
            ddlCourse.Items.Clear();
            ddlCourse.Items.Add("-Select-");
        }
        else
        {
            BindCourse();
        }
    
    }
}
 
 
Aspx Page:
 
<table border="0" cellpadding="0" cellspacing="0" class="border_table" height="350"
        width="100%">
        <tr>
            <td colspan="8" rowspan="1" style="height: 47px; width: 100%;" valign="top">
                <table style="height: 28px" width="100%">
                    <tbody align="center">
                        <tr>
                            <td align="left" class="Heading_Style_Header">
                                Course Structure</td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="6" rowspan="2" style="width: 5%; height: 360px;" valign="top">
            </td>
            <td align="center" colspan="1" rowspan="2" style="width: 90%; height: 360px;" valign="top">
                <asp:ScriptManager id="ScriptManager1" runat="server">
                </asp:ScriptManager><asp:updatepanel id="updatepanel1" runat="server">
                    <contenttemplate>
<TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 10%"></TD><TD style="WIDTH: 80%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 100%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="TEXT-ALIGN: right">Batch:</TD><TD style="TEXT-ALIGN: left"><asp:DropDownList id="ddlBatch" runat="server" OnSelectedIndexChanged="ddlBatch_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList></TD><TD style="TEXT-ALIGN: right">Course:</TD><TD style="TEXT-ALIGN: left"><asp:DropDownList id="ddlCourse" runat="server"></asp:DropDownList></TD><TD style="TEXT-ALIGN: left"><asp:Button style="BACKGROUND-IMAGE: url(But_back.png); BACKGROUND-COLOR: transparent" id="btnshow" onclick="btnshow_Click" runat="server" CausesValidation="False" Width="86px" Text="Show"></asp:Button></TD></TR><TR><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: left"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: left"></TD><TD style="TEXT-ALIGN: left"><asp:TextBox style="POSITION: relative" id="txtfile" runat="server" __designer:wfdid="w8"></asp:TextBox></TD></TR></TBODY></TABLE></TD></TR><TR><TD style="WIDTH: 100%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="VERTICAL-ALIGN: top; WIDTH: 30%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="VERTICAL-ALIGN: top; WIDTH: 100%"><asp:UpdatePanel id="UpdatePanel2" runat="server" __designer:wfdid="w6" ChildrenAsTriggers="False" UpdateMode="Conditional"><ContentTemplate>
<TABLE style="WIDTH: 100%"><TBODY><TR><TD style="VERTICAL-ALIGN: top; WIDTH: 100%"><asp:TreeView style="VERTICAL-ALIGN: top; TEXT-ALIGN: left" id="TreeView1" runat="server" Width="100%" __designer:wfdid="w7" ExpandDepth="0" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" ShowLines="true" OnTreeNodePopulate="TreeView1_TreeNodePopulate" ShowExpandCollapse="true" PopulateNodesFromClient="true">
                                                                </asp:TreeView></TD></TR></TBODY></TABLE>
</ContentTemplate>
<triggers>
<asp:AsyncPostBackTrigger ControlID="TreeView1" EventName="TreeNodeCollapsed"></asp:AsyncPostBackTrigger>
</triggers>
</asp:UpdatePanel></TD></TR></TBODY></TABLE></TD><TD style="VERTICAL-ALIGN: top; WIDTH: 70%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 100%"><asp:TextBox style="VERTICAL-ALIGN: top; TEXT-ALIGN: left" id="txtdesc" runat="server" Width="100%" Visible="False" Height="150px" ReadOnly="True" TextMode="MultiLine"></asp:TextBox></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR><TR><TD style="WIDTH: 100px"></TD></TR></TBODY></TABLE></TD><TD style="WIDTH: 10%"></TD></TR></TBODY></TABLE>
</contenttemplate>
<%--<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnshow"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="ddlBatch"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="ddlTerm"></asp:AsyncPostBackTrigger>
<asp:PostBackTrigger ControlID="TreeView1"></asp:PostBackTrigger>
</Triggers>--%>
 
 
           </asp:updatepanel>
               </td>
            <td colspan="1" rowspan="2" style="width: 5%; height: 360px;" valign="top">
            </td>
        </tr>
        <tr>
        </tr>
    </table>

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

The reason is that the code you are using is opening the file on the server. Use the code you have commented out.
 
                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();
                   
                }
     

Open in new window

Avatar of mannevenu
mannevenu

ASKER

here i am getting the open/save dialog, i should not get that option, my requirement is the file should be opened directly in the browser
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why was it a B grade solution?