c# - Files and Directories inside Access Database -
i'm working on program contains directory ( major directories , each directory contains sub directories , each sub directory contain sub2 directories , on ... till final directory contains .doc files objects.) example:
how can design data base accept tree hierarchy can each directories , open .doc in c# program.
i'm beginner in using tree-view , database.
thanks
edit:
i have 7 main folders , each folder has number of sub-folders , may sub-folders1 have sub-folders2 contain files, other sub-folders1 have files too. ( files 10000 almost).
question:
how populate structure database can list them in treeview or listbox ?
thanks
you can go unlimited level infinite structure 1 table. using ms sql here. same logic apply ms access well.
id unique identifier of row. parentid reference id row appear under. in other words, parent of current row. name field containing directory or file name. isfile (can omitted) determine if file or directory. can apply logic in code check if row has children. if there children of row, can mark directory.
then can populate table data
if using ms sql server 2005 , onwards, create cte (common table expression) make whole tree automatically. access not support common table expressions.
as tagged c# in question, should use c# create recursive function call if item has children.
populatemenu(); private void populatemenu() { var parentitems = getmenuitemswhereparentidisnull(); foreach(var item in parentitems) { console.writeline(item["name"]); populatechildrenbyitem(item); } } private void populatechildrenbyitem(object item) { var childitems = getmenuitemsbyparentid(item["id"]); foreach(var item in childitems) { console.writeline("child item: " + item["name"]); //recursively check children of child item populatechildrenbyitem(item["id"]); } } function object getmenuitemswhereparentidisnull() { //code getting parent items access via ado.net //query should "select * menu parentid null" } function object getmenuitemsbyparentid(int id) { //code getting child items given parentid access via ado.net //query should "select * menu parentid = <id>" }
note populatechildrenbyitem calling check child items of iterated item.
i hope guide right direction
cheers
Comments
Post a Comment