At the moment I am using to store the zip files with the file name like this…
backup-20111010092345.Zip
but i want to change the file name to this ..backup-2011-10-10_09:23:45.Zip
i have got this code …
string zipName = Path.Combine(filepath, string.Format("backup-{0}.zip", DateTime.Now.ToString("yyyyMMddhhmmss")));
string backupFilePath = Path.Combine(filepath, backupName);
using (ZipFile zip = new ZipFile())
{
zip.AddFile(backupFilePath, "");
zip.Save(zipName);
}
string backupName = "backup.sql";
string filepath = @"C:\Folder\Back\";
would any one pls help on this…
many thanks In advance…
Modified Code:
string zipName = Path.Combine(filepath, string.Format("backup-{0:yyyy-MM-dd_HH:mm:ss}.zip", DateTime.Now));
string backupFilePath = Path.Combine(filepath, backupName);
using (ZipFile zip = new ZipFile())
{
zip.AddFile(backupFilePath, "");
zip.Save(zipName);
}
Error :Notsupported Exception was unhandled
this is stack trace .
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at Ionic.Zip.ZipFile.Save()
at Ionic.Zip.ZipFile.Save(String fileName)
error: The given path’s format is not supported.
Sounds like you’ve nearly got it (in terms of building the name that you specified) – you just need to change the format string
You could specify that as:
It’s up to you which you find more readable.
Note that this will use the time separator for the current culture. If you always want it to be “colon” then you should quote it. On the other hand, is colon even a valid character in Windows filenames? Consider using dash again, or something similar. For example: