Our QA reported following error during the production:
Access to the path "C: \ ProgramData \ avi \ Logs \ IMPMDesktopClient HTML Debug - Copy - Copy - Copy - Copy - Copy - Copy (2) - Copy.zip" was denied.
At System.IO.__ Error.WinIOError (Int32 errorCode, String maybeFullPath)
In System.IO.FileStream.Init(String path, FileMode mode, FileAccessAccess, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptionsOptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
At System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
At Ionic.Zip.ZipEntry._WriteFileData(Stream s)
At Ionic.Zip.ZipEntry.Write(Stream s)
At Ionic.Zip.ZipFile.Save()
At Ionic.Zip.ZipFile.Save(String fileName)
At IMPMDesktopClient.LogUploader.ZipupLogsForPosting(String strFileTag)
At IMPMDesktopClient.LogUploader.UploadLogs(TimeSpan timeout, String strTag)
I tried replicating the case, but couldn't do it. It has been running successfully in my machine.
There are folders : Logs and Temp inside a directory : C:\ProgramData\avi. The program copies and zips up the Log folder and places inside Temp. If the zipped folder size is greater than 4 mb (lets say 500 mb), it divides the zip file into multiple chunks of smaller zip files more or less than 4 mb.
Here is my code : Please let me know where could I possibly go wrong.
Note: I am using Ionic zip library.
private static string ZipupLogsForPosting(string strFileTag)
{
string strDstPath = Updater.UpdateFolder;
string strZipFileName = string.Format("{0}_{1}_{2}_Logs.zip",
Environment.MachineName,
Environment.UserName,
strFileTag.Substring(0, Math.Min(strFileTag.Length, 20)));
var sb = new StringBuilder(strZipFileName);
sb.RemoveTheseChars(Path.GetInvalidFileNameChars());
strZipFileName = sb.ToString();
string strZipPath = Path.Combine(strDstPath, strZipFileName);
if (File.Exists(strZipPath))
{
if ((File.GetAttributes(strZipPath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
File.SetAttributes(strZipPath, FileAttributes.Normal);
}
File.Delete(strZipPath);
}
Log.Trace("Zipping up logs for posting, Tag='{0}'", strFileTag);
Log.FlushAllLogs();
using (var zip = new ZipFile())
{
zip.AddDirectory(Log.LogsPath);
zip.Save(strZipPath);
}
return (strZipPath);
}
Note : Please, don't worry about the splitting of zip folders. The issue arises when trying to zip the folder at the beginning before splitting.