Wednesday, 23 September 2015

Create a log file when using File Selection Manager

This is a great feature of File Selection Manager which is really easy to carry out.

All you need to do is edit your app.config file and add the following:

<configuration>
    <configSections>
        <section name="FSMLog" 
                 type="FileSelectionManager.FSMLogSection, 
                 FileSelectionManager,
                 Version=1.0.0.0, 
                 Culture=neutral, 
                 PublicKeyToken=null" 
                 allowDefinition="Everywhere" 
                 allowExeDefinition="MachineToApplication" 
                 restartOnExternalChanges="true"/>
    </configSections>
    <FSMLog name="MyLog">
        <logging fullPath="c:\FSMLog"
             fileName="FSManager.log"
             listAffectedFiles="true"
             active="true"/>
    </FSMLog>
</configuration>

As you can see, the parameters of the logging tag are:

fullPath: Folder where the log file will be written.
fileName: Filename of the log file.
listAffectedFiles: Show the affected files in the log file.
activate: Enable or disable logging.

Tuesday, 15 September 2015

Using the FileSelectionManager library in Visual Basic

In previous posts, we presented samples of File Selection Manager using C#.

Here you can see the same projects, using Visual Basic instead of C#.

Download the projects here:

How to make an incremental backup
How to create an advanced file searcher
Sort a FileInfo Collection

Test the projects and give us your opinion.

Friday, 28 August 2015

Sort a FileInfo collection in C# like a database using FileSelectionManager

Adding the FileSelectionManager library to a project means you can select and sort files using pseudo-SQL sentences, like a database. In this article we focus on the sort feature.

First of all you have to download the FileSelectionManager library, then create a console application and add the library to your project as a new reference.

Next, write the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using FileSelectionManager;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            if(args.Count()!=2 || !Directory.Exists(args[0]))
                throw new ArgumentException("Invalid Parameters");
            else
            {
                //Selecting Files
                FSM fManager = new FSM();
                fManager.Dir(args[0], true, args[1]);

                //Show results
                Console.WriteLine("Files Affected: " + fManager.AffectedFiles);
                Console.WriteLine("Files Involved: " + fManager.InvolvedFiles);

                foreach (System.IO.FileInfo file in fManager.SelectedFiles)
                {
                    Console.WriteLine("Found: {0} - {1} - {2} - {3} ",
                    file.DirectoryName,
                    file.Name,
                    file.CreationTime,
                    file.Length);
                }
            }
        }
    }
}


Imagine you have the following directory and file structure:



Compile your application and execute it, giving it the directory, the select criteria and the sort clause.
Here are three examples:




Thursday, 20 August 2015

How to create an advanced file searcher in C# using the FileSelectionManager library

This is how to use the pseudo-SQL features contained in the FileSelectionManager library for selecting and sorting files.
In order to do this, your application needs to receive a directory where it will search the files and pseudo-SQL sentence with the search criteria.

First of all you have to download the FileSelectionManager library, then create a console application and add the library to your project as a new reference

Next, write the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using FileSelectionManager;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            if(args.Count()!=2 || !Directory.Exists(args[0]))
                throw new ArgumentException("Invalid Parameters");
            else
            {
                //Selecting Files
                FSM fManager = new FSM();
                fManager.Dir(args[0], true, args[1]);

                //Show results
                Console.WriteLine("Files Affected: " + fManager.AffectedFiles);
                Console.WriteLine("Files Involved: " + fManager.InvolvedFiles);

                foreach (System.IO.FileInfo file in fManager.SelectedFiles)
                {
                    Console.WriteLine("Found: {0} - {1} - {2} - {3} ",
                    file.DirectoryName,
                    file.Name,
                    file.CreationTime,
                    file.Length);
                }
            }
        }
    }
}

Imagine you have the following directory and files structure:

Friday, 14 August 2015

How to make an incremental backup in C#. It is really easy using FileSelectionManager.


  • Download the free DLL from www.fileselectionmanager.com
  • Create a console project using visual studio and call it Backup_using_FSM. Add the DDL you just downloaded as a reference in the project.
  • Imagine you want to make a backup of the following directories and files:


  • Write the following code in the project: 

using System;
using System.Collections.Generic;
using System.Text;
using FileSelectionManager;

namespace backup_using_FSM
{
    class Program
    {
        static void Main(string[] args)
        {
            //Validate Date of last backup
            try { DateTime.Parse(args[0]); }
            catch { throw new ArgumentException("The date of the last backup is invalid"); }

            FSM fManager = new FSM();
            // Make a where clause like this "ModificationDate > 01/01/20015" 
            StringBuilder wclause = new StringBuilder();
            wclause.Append("ModificationDate > ");
            wclause.Append(args[0]);
            
            //Backuping
           fManager.CopyFilesAndStructure(@"c:\files_need_backing_up",true,Convert.ToString(wclause),
@"c:\Backup_using_FSM", true);

            //Show results
            Console.WriteLine("Files Affected: " + fManager.AffectedFiles);
            Console.WriteLine("Files Involved: " + fManager.InvolvedFiles);

            foreach (System.IO.FileInfo file in fManager.SelectedFiles)
            {
                    Console.WriteLine("File Copied: {0} - {1} - {2} ",
                    file.DirectoryName, file.Name,
                    file.LastWriteTime);
            }

        }
    }
}
  • Compile the code and execute it, giving it the date of the most recent backup that was carried out. If this is the first backup you have done, put in an old date to make sure that all the files are copied. You can see this in the image below:




  • Done. This will generate a new subdirectory called Backup_using_FSM in the root directory, with the files and structure of the subdirectory files_need_backing_up. Next time you execute your code, it will just copy the files that have been modified since the date that you put in as a parameter and which shows the date of the last backup carried out. 



Wednesday, 12 August 2015

Welcome

Welcome to our new blog, where we will be posting articles, reviews and tutorials on how to use the products developed by LeapCoders.