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;
Instead of concatenating the destFilePath
, why can't you use like below.
destFilePath = Path.Combine(newDirectoryPath,fileName + ".zip");
which will give a correct path of the file you require.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.