//copy database files to target directory
string fileName = "test.txt";
string targetPath = StaticFormInstances.choose.txtbxTargetDir.Text;
string sourcePath = @"\\il93fil48\3GSM\release\testapplication_REL_01_00_09\database";
//Use Path Class to manipulate file and directory paths
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
//Create a new target folder if it doesn't exist
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
//calculate total number of files in source
int totalNumberOfFiles = files.Length;
//current file number
int fileNumber = 0;
//create object to store database string
OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();
foreach (string s in files)
{
//increase file number by 1
fileNumber++;
//copy file based on fileNumber
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, false);
//set up database
builder.Driver = "Microsoft Access Driver (*.mdb)";
builder.Dsn = fileName.Substring(0,fileName.Length - 4);
builder["Description"] = fileName.Substring(0, fileName.Length - 4);
builder["DBQ"] = destFile;
Console.WriteLine(builder.ConnectionString);
Console.WriteLine();
//clear current values and reset know keys to default
builder.Clear();
//calculate progess out of base of 100
int ProgressPercentage = (fileNumber / totalNumberOfFiles) * 100;
//update the progress bar
bckgrdSetUpDatabases.ReportProgress(ProgressPercentage);
}
}
lotrsimp12345 37 Posting Pro in Training
lotrsimp12345 37 Posting Pro in Training
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.