0

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.

Avishekh Bharati
  • 1,858
  • 4
  • 27
  • 44
  • "C: \ ProgramData \ Presensoft \ Logs \ IMPMDesktopClient HTML Debug - Copy - Copy - Copy - Copy - Copy - Copy (2) - Copy.zip". Is the path so much long ? – Vandita Apr 24 '17 at 09:17
  • QA copied the files multiple times just to increase the size of the folder. – Avishekh Bharati Apr 24 '17 at 09:20
  • May be this is useful. http://www.winhelponline.com/blog/fix-zipped-folder-access-denied-unable-complete-operation/ – Vandita Apr 24 '17 at 09:40
  • And error is not related to Ionic.zip. creating same folder structure I found that zipped folder if opened, a temporary zipped folder will be created like "C:\Users\userxyz\AppData\Local\Temp\Temp1_IMPMDesktopClient_HTML_Debug-Copy-Copy-Copy-Copy-Copy-Copy(2)-Copy.zip\IXM-SW-PC_userxyz__Logs.zip" but trying to open the path "C:\ProgramData\Presensoft\Logs\IMPMDesktopClient_HTML_Debug-Copy-Copy-Copy-Copy-Copy-Copy(2)-Copy.zip\IXM-SW-PC_userxyz__Logs.zip" will give error ! – Vandita Apr 24 '17 at 09:50
  • Hmm... looks like the similar scenario. But I dont know why, I tried but I could see no temporary zipped folder. And again, QA says for the same scenario when she request the log for the machine with admin previlage, log is zipped and uploaded. But user with local account, it failed. And further zip is not created inside the Temp file of machine ... but the Temp file is actually created by me at different location. Could you please give a thought ? I need to get it done today . :( – Avishekh Bharati Apr 24 '17 at 10:03

0 Answers0