Error Showing while try to zip file under Azure Local Storage.
I am trying to zip .ps1
file to <filename>.ps1.zip
and i am getting an error
The directory name is invalid.
code:
string scriptPath = Path.Combine(fileDirectoryPath, fileName);
string destFilePath = string.Empty;
List<string> zipFolderDetails = new List<string>();
if (!File.Exists(scriptPath))
{
throw new Exception(string.Format("ZipFile : No file exists in the source path {0}", fileName));
}
string newDirectoryPath = Path.Combine(Utilities.GetLocalDirectoryScriptPath(), Guid.NewGuid().ToString());
zipFolderDetails.Add(newDirectoryPath);
Directory.CreateDirectory(newDirectoryPath);
destFilePath = newDirectoryPath + @"\" + fileName + ".zip";
zipFolderDetails.Add(destFilePath);
//// Zipping the script file
System.IO.Compression.ZipFile.CreateFromDirectory(scriptPath, destFilePath, CompressionLevel.Fastest, false); // <--- Exception here
return zipFolderDetails;
we sorted out the issue. We were passing the file path
as first parameter, but it should be the directory path
where file needed to zip exists.
we changed the code like this and it works now
System.IO.Compression.ZipFile.CreateFromDirectory(sourceDirectory, destFilePath, CompressionLevel.Fastest, false); // <--- Exception here