Hi,

I'm creating a program were logs files in a certain directory are presented in a table format.

My issue here is, I created a filter option in which the user can filter data available in a particular year and month.

I currently retrieved all the file dates and its in format (2014-08-01).
now I would like to store the values in the format in the below example and then populate the year and month in the dropdown:

2014
   - May
   - Jun

2015
    - Apr
    - May    

Thus, mainitaining the year and month relation intact.

I request your help in letting me know which data structure would help me achieve it.

Thanks in advance.
Karthikprs

Recommended Answers

All 3 Replies

Looks your in need for something like this.

As for storing your data a 2D dictionary would work:

Dictionary<string,Dictionary<string,FileInfo[]>> fileTree;

The outer dictionary would have the year as the key. Each year then would contain a dictionary with the month as the key. Each month would then have an array of FileInfo objects referring to the files for that year and month.

To access the specific array simply index by the year and the month:

fileTree["2014"]["Mar"];

At this point populating a combobox is a simple matter of assigning the array as the data source to the combobox

Are you looking for some database solution.

Yes you can make four fields in Database Year, Month, Filename, Filepath. You can increase the field to five if you want to increase the filtering option based upon date.

//You can pass your custom date instead of Current Day.
String sDate = DateTime.Now.ToString();
DateTime datevalue = (Convert.ToDateTime(sDate.ToString()));

String dy = datevalue.Day.ToString();
String mn = datevalue.Month.ToString();
String yy = datevalue.Year.ToString();

Afterwards you can bind these Data in a treeview control using this method from the Database:

https://www.aspsnippets.com/Articles/Display-Directory-Folder-structure-using-ASPNet-TreeView-control-in-C-and-VBNet.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.