C # view Image Browsing in a specified folder

Source: Internet
Author: User

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using Microsoft. Web. UI. webcontrols;
Using system. IO;

Namespace treeviewtest
{
/// <Summary>
/// Summary of treeviewtest.
/// </Summary>
Public class treeviewtest: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. Image image1;
Protected Microsoft. Web. UI. webcontrols. Treeview treeview1;
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
If (! This. ispostback)
{
This. image1.imageurl = @ "D: \ photos \ huoying \ ecbbc2ded2bbbabd3e01.jpg ";
Showtreeview ();
}
}

Private void showtreeview ()
{
Try
{
String filepath = @ "D: \ photos ";
This. treeview1.nodes. Clear ();
Treenode TD = new treenode ();
TD. Text = filepath;
Treeview1.nodes. Add (TD );
Getallfiles (filepath, TD );
Getdir (TD, filepath );
}
Catch (exception ERR)
{
String strerro = err. message;
// Response. Write (ERR. Message );
// Response. Write (ERR. source );
// Response. Write (ERR. stacktrace );
}
}

// Get the file name
Private void getallfiles (string path, treenode currentnode)
{
Directoryinfo maindir = new directoryinfo (PATH );
Try
{
Foreach (fileinfo files in maindir. getfiles ())
{
Treenode TD = new treenode ();
TD. Text = files. Name;
TD. ID = files. fullname;
// Response. Write (files. fullname );
Currentnode. nodes. Add (TD );
}
}
Catch (exception ERR)
{
String strerro = err. message;
// Response. Write (ERR. Message );
// Response. Write (ERR. source );
// Response. Write (ERR. stacktrace );
}
}

// Obtain the folder path
Private void getdir (treenode currentnode, string path)
{
Try
{
Directoryinfo maindir = new directoryinfo (PATH );
Foreach (directoryinfo D in maindir. getdirectories ())
{
Treenode TD = new treenode ();
TD. Text = D. Name;
// TD. ID = D. fullname;
// Response. Write (D. fullname );
Currentnode. nodes. Add (TD );
Getallfiles (path + @ "\" + D. Name, TD );
Getdir (TD, path + @ "\" + D. Name );
}
}
Catch (exception ERR)
{
String strerro = err. message;
// Response. Write (ERR. Message );
// Response. Write (ERR. source );
// Response. Write (ERR. stacktrace );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.