public virtual void AddFileFromTemplate(string source, string target)
{
if (String.IsNullOrEmpty(source))
{
throw new ArgumentNullException("source");
}
if (String.IsNullOrEmpty(target))
{
throw new ArgumentNullException("target");
}
try
{
string directory = Path.GetDirectoryName(target);
if (!String.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
FileInfo fiOrg = new FileInfo(source);
FileInfo fiNew = fiOrg.CopyTo(target, true);
fiNew.Attributes = FileAttributes.Normal; // remove any read only attributes.
}
catch (IOException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (UnauthorizedAccessException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (ArgumentException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
catch (NotSupportedException e)
{
Trace.WriteLine("Exception : " + e.Message);
}
}