Click here to Skip to main content
6,629,377 members and growing! (20,477 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Windows Forms License: The Code Project Open License (CPOL)

File Manager using C# and multithreading

By Er. Virendra

It helps to maintains files in directories with dynamically generated names using company's naming convention, versions and release
C# (C# 1.0, C# 2.0, C# 3.0)
Posted:24 Aug 2008
Views:12,213
Bookmarked:18 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 2.14 Rating: 2.38 out of 5
3 votes, 37.5%
1
2 votes, 25.0%
2
1 vote, 12.5%
3
1 vote, 12.5%
4
1 vote, 12.5%
5
FileManager

snap_2.jpg

snap_3.jpg

Introduction

This is a tool to manage your files related to uploads on server. When any one uploads updated files on server, generally he/she gets the backup of old files from server and and also creates a copy of new updated files in any directory. He/she gives the name to these directories according to company's naming convention, corresponding version and release. This tool gives an easy way to automate this process. In this application; there is a settings section where user can set the naming convention, prefix for backup folders and prefix for folders which contains the copy of new uploaded files. After making these settings user can use these settings for multiple times and user can also change settings in future. This application also allows user to drag and drop the files for fast working and all the saved directories are binded in a treeview using a seperate thread, so it also supports multiprocessing upto some level. This application uses a MS access file to maintain the track of version and release and uses quick sort to decide new version or release.

Using the code

Just download and run the application. You can also make its setup. This application contains following sections:
1. Form1 (which is the default form) 2. Settings (which is opened as a dialog box when user clicks on settings button on Form1)
3. MyMessage (this form is used to display messages)

In this application, I have given a way to set company's naming convention with few fields it can be added as per company's requirement using some modification in source code.

Following function is called from a seperate thread to start to bind treeview:




        
private void Get_nodes()
{
            string strPath = glbStrPath;
            strFiles = Directory.GetDirectories(strPath);
            Guid strguid;
            string strKey;
            string[] strName;
            char ch = Convert.ToChar("\\");
            //foreach (string strFile in strFiles)
            //{
            // int.TryParse(,intIndex);
            try
            {
                strName = strPath.Split(ch);
                strguid = System.Guid.NewGuid();
                strKey = strName[strName.GetUpperBound(0)] + Convert.ToString(strguid);
                if (InvokeRequired)
                {
                    BeginInvoke(new Onadd_Field(add_Field), new object[] { strKey, strName[strName.GetUpperBound(0)] });
                }
                if (HasSubDirectory(strPath))
                {
                    Get_nodes(strPath, treeFileExplorer.Nodes[strKey]);
                }
                BeginInvoke(new ThreadFinishedEvent(ThreadFinished));
            }
            catch
            {
            }

            //}
       }
        delegate void ThreadFinishedEvent();
        void ThreadFinished()
        {
            t.Abort();
            progressBar1.Visible = false;
            lblSearch.Visible = false;
            pnlProcess.Visible = false;

            timer1.Stop();
            progressBar1.Value = progressBar1.Minimum;
        }
       


 Following function is a reccursive function which initially called from called from Get_nodes() function:

       private void Get_nodes(string strPath, System.Windows.Forms.TreeNode CurrentNode)
        {


            strFiles = Directory.GetDirectories(strPath);
            Guid strguid;
            string strNodeKey;
            string[] strName;
            string[] childs;
            char ch = Convert.ToChar("\\");
            foreach (string strFile in strFiles)
            {
                // int.TryParse(,intIndex);
                try
                {
                    childs = Directory.GetDirectories(strPath + "\\");
                    strName = strFile.Split(ch);
                    strguid = System.Guid.NewGuid();
                    strNodeKey = strName[strName.GetUpperBound(0)] + Convert.ToString(strguid);
                    if (InvokeRequired)
                    {
                        BeginInvoke(new Onadd_Node(add_Node), new object[] { CurrentNode, strNodeKey, strName[strName.GetUpperBound(0)] });

                    }
                    //CurrentNode.Nodes.Add(strNodeKey,strName[strName.GetUpperBound(0)]);
                    if (HasSubDirectory(strFile))
                    {
                        Get_nodes(strFile, CurrentNode.Nodes[strNodeKey]);
                    }
                }
                catch
                {
                }

            }
        }


 
Following functions are called from above functions to add nodes in treeview:

 private delegate void Onadd_Field(string key, string item);

        private void add_Field(string key, string item)
        {
            treeFileExplorer.Nodes.Add(key, item);
        }

        private delegate void Onadd_Node(System.Windows.Forms.TreeNode CurrentNode, string key, string item);
        private void add_Node(System.Windows.Forms.TreeNode CurrentNode, string key, string item)
        {
            CurrentNode.Nodes.Add(key, item);
        }

        

Remember to set the Language of your code snippet using the Language dropdown.

Points of Interest

When I was developing this application, I experienced that if we wish to use any windows form control in a seperate thread, we have to use "Invoke" or "BeginInvoke" function. To call functions within "Invoke" or "BeginInvoke", we need to make delegate for the function which uses windows form control.

History

This is the first version of this application. Please give me feedback to make its next releases and versions. This is completely free and if any one goes through any other file manager of same type, obviously those are paid.


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Er. Virendra


Member
I passed my B.Tech. in 2007 from SRMCEM, Lucknow and currently I am working as a software developer in .Net technology.
Company: SRM Techsol Pvt. Ltd., Lucknow
Location: India India

Other popular Miscellaneous articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
GeneralIssue has been fixed! PinmemberEr. Virendra1:10 26 Aug '08  
GeneralNice application, but unable to understand Pinmemberadithyadugyala22:15 25 Aug '08  
GeneralRe: Nice application, but unable to understand PinmemberEr. Virendra1:59 26 Aug '08  
GeneralNot Able to run this application Pinmemberraju87819:16 25 Aug '08  
GeneralRe: Not Able to run this application PinmemberEr. Virendra2:00 26 Aug '08  
GeneralNice work, but can't compile... Pinmemberthompsons7:01 25 Aug '08  
GeneralRe: Nice work, but can't compile... Pinmemberadithyadugyala22:32 25 Aug '08  
GeneralRe: Nice work, but can't compile... PinmemberEr. Virendra2:01 26 Aug '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 Aug 2008
Editor: Smitha Vijayan
Copyright 2008 by Er. Virendra
Everything else Copyright © CodeProject, 1999-2009
Web09 | Advertise on the Code Project