Elixir Elixir - 2 months ago 9
C# Question

How to create backup of ms access in folder?

I want to create backup of ms access database with

extension with c# code And the backup should automatically save in Day Wise folder like If I click on
today, then it should automatically create back in
Folder. How to do this?


Backup of MS Access database is a file copy.

Starting from a baseDirectory, with Path.Combine you can build a fullDirectory name containing the baseDirectory and the day. After that you can copy the file (File.Copy) to that directory (eventually using Path.Combine to build a fullPath of the file). Don't forget to Dispose the connection before copying the file and be sure the no one is using the file when you make the copy.


using System;
using System.IO;

public class Program
    public static void Main()

        string baseDirectory = "C:\\Insert\\Your\\Base\\Directory";
        string mdbSourceFilePath = "C:\\Directory\\Of\\mdb\\MyAccessDb.accdb";
        string mdbTargetFileName = "MyAccessDb.bk";

        string fullDirectory = Path.Combine(baseDirectory, DateTime.Today.ToString("dddd"));
        if (!Directory.Exists(baseDirectory))
        if (!Directory.Exists(fullDirectory))

        string mdbTargetFilePath = Path.Combine(fullDirectory, mdbTargetFileName);

        File.Copy(mdbSourceFilePath, mdbTargetFilePath);