This is what I came up with:
void Import()
{
XmlDocument xDoc = new XmlDocument();
OpenFileDialog BrowseFile = new OpenFileDialog();
if (BrowseFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.ImportPath = BrowseFile.FileName;
Properties.Settings.Default.Save();
}
string fileName = "Contacts.xml";
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string sourcePath = Properties.Settings.Default.ImportPath;
string targetPath = path + "\\Phonebook\\";
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourcePath, destFile, true);
xDoc.Save(destFile);
MessageBox.Show("Contacts have successfully been imported. Please restart your application in order changes to take effect!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
It actually loads contacts after the app is restarted, but the problem is I am getting an error when I perform Import().
This is what the error is about:
IMAGE[
^]
So, after that I close the application, run it again and the contacts are imported.
Any ideas?