Welcome to Dream.In.Code
Become a C# Expert!

Join 150,399 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 959 people online right now. Registration is fast and FREE... Join Now!




Displaying Image from a Tree

 
Reply to this topicStart new topic

Displaying Image from a Tree

kkgaming
6 Mar, 2008 - 07:42 AM
Post #1

D.I.C Head
**

Joined: 7 Feb, 2007
Posts: 75


My Contributions
I am having trouble displaying an image from a tree I have made. I have an upload control, and can upload image files that will display in the tree. Once I click the filename of the image in the tree, I want the picture to show. I understand I need an if statement, but do not exactly know hot to write it. I got pseudocode displaying what I want to do:

CODE
if (treeview list is an image)


    Display image

else

    Do not display anything if not an image


Here is my full C# code:

CODE
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO;

public partial class ul4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            updatefilelist();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = DropDownList1.SelectedItem.Value;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        //Dim fname As String
        //Dim folder As String
        //Dim filepath As String

        //filepath = "~/Uploads/"
        //fname = FileUpload1.FileName
        //folder = DropDownList1.SelectedItem.Text
        //filepath = filepath & folder & "/"

        //filepath = filepath & fname
        //filepath = MapPath(filepath)
        //FileUpload1.SaveAs(filepath)

        //Label1.Text = filepath

        //updatefilelist()
        //End Sub
        string fname, filepath, folder;
        filepath = "~/Uploads/";
        fname = FileUpload1.FileName;
        folder = DropDownList1.SelectedItem.Text;
        filepath = filepath + folder + "/" + fname;
        filepath = MapPath(filepath);
        FileUpload1.SaveAs(filepath);
        Label1.Text = filepath;
        updatefilelist();

    }

    private void updatefilelist()
    {
        string upfolder;
        upfolder = MapPath("~/Uploads");
        DirectoryInfo dir = new DirectoryInfo(upfolder);

        //ListBox1.DataSource = dir.GetFiles();
        //ListBox1.DataBind();

        DropDownList1.DataSource = dir.GetDirectories();
        DropDownList1.DataBind();
        ///////////////////////////
        ListBox1.Items.Clear();
        foreach (DirectoryInfo tdir in dir.GetDirectories())
        {
            ListBox1.Items.Add(tdir.Name);
            foreach (FileInfo fin in tdir.GetFiles())
            {
                ListBox1.Items.Add('-' + fin.Name);
            }
        }
        updatetreelist();
    }

    private void updatetreelist()
    {
        string upfolder;
        upfolder = MapPath("~/Uploads");
        DirectoryInfo dir = new DirectoryInfo(upfolder);
        ///////////////////////////
        tv1.Nodes.Clear();

        TreeNode root = new TreeNode("Uploads");
        tv1.Nodes.Add(root);





        foreach (DirectoryInfo tdir in dir.GetDirectories())
        {
            //ListBox1.Items.Add(tdir.Name);
            TreeNode d = new TreeNode(tdir.Name);
            root.ChildNodes.Add(d);

            foreach (FileInfo fin in tdir.GetFiles())
            {
                //ListBox1.Items.Add('-'+fin.Name);
                TreeNode f = new TreeNode(fin.Name);
                d.ChildNodes.Add(f);
            }
        }

    }

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string filepath;
        filepath = "~/Uploads/";
        if (TextBox1.Text != "")
        {
            filepath = filepath + TextBox1.Text;
            filepath = MapPath(filepath);
            Directory.CreateDirectory(filepath);
            updatefilelist();
        }

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {

        if (tv1 = Image1)
        
            Image1.ImageUrl = Uploads/Dots/red.jpg;

        
        
        
    }

}

User is offlineProfile CardPM
+Quote Post

kkgaming
RE: Displaying Image From A Tree
6 Mar, 2008 - 10:51 PM
Post #2

D.I.C Head
**

Joined: 7 Feb, 2007
Posts: 75


My Contributions
I am having trouble displaying an image from a tree I have made. I have an upload control, and can upload image files that will display in the tree. Once I click the filename of the image in the tree, I want the picture to show. I understand I need an if statement, but do not exactly know hot to write it. I got pseudocode displaying what I want to do:

CODE
if (treeview list is an image)


    Display image

else

    Do not display anything if not an image


Here is my full C# code:

CODE
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO;

public partial class ul4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            updatefilelist();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = DropDownList1.SelectedItem.Value;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        //Dim fname As String
        //Dim folder As String
        //Dim filepath As String

        //filepath = "~/Uploads/"
        //fname = FileUpload1.FileName
        //folder = DropDownList1.SelectedItem.Text
        //filepath = filepath & folder & "/"

        //filepath = filepath & fname
        //filepath = MapPath(filepath)
        //FileUpload1.SaveAs(filepath)

        //Label1.Text = filepath

        //updatefilelist()
        //End Sub
        string fname, filepath, folder;
        filepath = "~/Uploads/";
        fname = FileUpload1.FileName;
        folder = DropDownList1.SelectedItem.Text;
        filepath = filepath + folder + "/" + fname;
        filepath = MapPath(filepath);
        FileUpload1.SaveAs(filepath);
        Label1.Text = filepath;
        updatefilelist();

    }

    private void updatefilelist()
    {
        string upfolder;
        upfolder = MapPath("~/Uploads");
        DirectoryInfo dir = new DirectoryInfo(upfolder);

        //ListBox1.DataSource = dir.GetFiles();
        //ListBox1.DataBind();

        DropDownList1.DataSource = dir.GetDirectories();
        DropDownList1.DataBind();
        ///////////////////////////
        ListBox1.Items.Clear();
        foreach (DirectoryInfo tdir in dir.GetDirectories())
        {
            ListBox1.Items.Add(tdir.Name);
            foreach (FileInfo fin in tdir.GetFiles())
            {
                ListBox1.Items.Add('-' + fin.Name);
            }
        }
        updatetreelist();
    }

    private void updatetreelist()
    {
        string upfolder;
        upfolder = MapPath("~/Uploads");
        DirectoryInfo dir = new DirectoryInfo(upfolder);
        ///////////////////////////
        tv1.Nodes.Clear();

        TreeNode root = new TreeNode("Uploads");
        tv1.Nodes.Add(root);





        foreach (DirectoryInfo tdir in dir.GetDirectories())
        {
            //ListBox1.Items.Add(tdir.Name);
            TreeNode d = new TreeNode(tdir.Name);
            root.ChildNodes.Add(d);

            foreach (FileInfo fin in tdir.GetFiles())
            {
                //ListBox1.Items.Add('-'+fin.Name);
                TreeNode f = new TreeNode(fin.Name);
                d.ChildNodes.Add(f);
            }
        }

    }

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string filepath;
        filepath = "~/Uploads/";
        if (TextBox1.Text != "")
        {
            filepath = filepath + TextBox1.Text;
            filepath = MapPath(filepath);
            Directory.CreateDirectory(filepath);
            updatefilelist();
        }

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {

        if (tv1 = Image1)
        
            Image1.ImageUrl = Uploads/Dots/red.jpg;

        
        
        
    }

}

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Displaying Image From A Tree
6 Mar, 2008 - 10:59 PM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
kkgaming, this is your 2nd thread regarding this same exact question. Double posting is against the forum rules, and is strictly enforced. You need patience, we are not at your beckon call. It will take time to get help sometimes as we all have full lives with jobs, school, families and such. So you just need to be patient, opening a new thread with the same question isnt going to get you the attention you're looking for. Topics merged
User is offlineProfile CardPM
+Quote Post

kkgaming
RE: Displaying Image From A Tree
7 Mar, 2008 - 07:43 PM
Post #4

D.I.C Head
**

Joined: 7 Feb, 2007
Posts: 75


My Contributions
I posted twice because I was unsure which topic to put this in...ASP.net or C#, that's all, I didn't think it would get me help faster. I am not sure why there is a double post in this topic though? Can a mod delete one of them?

This post has been edited by kkgaming: 7 Mar, 2008 - 11:33 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Displaying Image From A Tree
8 Mar, 2008 - 08:38 AM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
There is a double post in this topic because anytime someone creates a duplicate topic we either delete them or merge them with the original topic. The latter is the case here, it was merged into one topic.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:00PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month