Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Getting error "Cannot perform the requested operation on an item that exists."


Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Nand
    Post count: 1
    #43925 |

    I have written the below method to create archive, but I found that it throws below error sometimes and sometimes it works well:
    “Cannot perform the requested operation on an item that exists.
    Type: Xceed.Zip.ZippedFile
    Full Name: \Secured.html”

    Stack Trace : at Xceed.FileSystem.AbstractFolder.CopyFilesTo(FileSystemEvents events, Object userData, AbstractFolder destinationFolder, Boolean recursive, Boolean replaceExistingFiles, Object[] filters)
    at IdSecureLib.cXceedZip.CreateArchive(String sArchiveFileName, String sSourceFileName, CompressionLevel DefaultCompressionLevel, String sEncryptionPassword) in H:\NandKishore\A\core\IdSecureLib\IdSecureLib\cXceedZip.cs:line 244

    I am using the these dll in my application:
    1. Xceed.Compression (version 3.0.6173.0)
    2. Xceed.Compression.Formats (version 3.0.6173.0)
    3. Xceed.FileSystem (version 3.0.6173.0)
    4. Xceed.Zip (version 3.0.6173.0)

    Operating system : Windows 10.
    Framework – dot net framework 2.0.

    Parameters values in methods are:
    sArchiveFileName = “C:\Users\nandkishore.sharma\AppData\Local\S\A\Secured.zip”
    sSourceFileName = “C:\Users\nandkishore.sharma\AppData\Local\S\A\Secured”
    DefaultCompressionLevel = Xceed.Compression.CompressionLevel.Normal
    sEncryptionPassword = “”

    public bool CreateArchive(string sArchiveFileName, string sSourceFileName, CompressionLevel DefaultCompressionLevel, string sEncryptionPassword)
    bool bRet = false;
    DiskFile oArchiveFile = new DiskFile(sArchiveFileName);
    ZipArchive oZip = new ZipArchive(oArchiveFile);
    ZipEvents oEvents = new ZipEvents();
    oEvents.DiskRequired += new DiskRequiredEventHandler(oEvents_DiskRequired);
    oEvents.ItemProgression += new ItemProgressionEventHandler(oEvents_ItemProgression);
    oEvents.ByteProgression += new ByteProgressionEventHandler(oEvents_ByteProgression);
    oZip.AllowSpanning = false;
    oZip.DefaultCompressionLevel = DefaultCompressionLevel;
    oZip.DefaultEncryptionPassword = sEncryptionPassword;
    string sFolder = string.Empty;
    string sFileName = string.Empty;
    bool bRecursive = false;
    if (File.Exists(sSourceFileName))
    sFileName = Path.GetFileName(sSourceFileName);
    sFolder = Path.GetDirectoryName(sSourceFileName);
    sFileName = “*.*”;
    sFolder = sSourceFileName;
    bRecursive = true;
    DiskFolder oFileParentFolder = new DiskFolder(sFolder);
    oFileParentFolder.CopyFilesTo(oEvents, “Zipping”, oZip, bRecursive, false, sFileName);
    if (oFileParentFolder != null)
    oFileParentFolder = null;
    if (oArchiveFile != null)
    oArchiveFile = null;
    if (oZip != null)
    oZip = null;
    if (oEvents != null)
    oEvents = null;
    bRet = true;
    catch (Exception oEx)
    oLogger.WriteLog(“CreateArchive()”, oEx.Message);
    return bRet;

    Please help me why I am getting error only sometimes.

    Thanks in Advance.

    Fawzi [Xceed]
    Post count: 722


    Your line

    oFileParentFolder.CopyFilesTo(oEvents, “Zipping”, oZip, bRecursive, false, sFileName);

    shows that for the ‘replaceExistingFiles’ parameter, you use the value ‘false’

    That means that if the item you’re zipping already exists in the archive, it will not be overwritten and you will get the ‘ItemAlreadyExistsException’ you’re getting.

    If you want to replace existing items in the archive when you’re zipping, set the ‘replaceExistingFiles’ parameter to true:

    oFileParentFolder.CopyFilesTo(oEvents, “Zipping”, oZip, bRecursive, true, sFileName);

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.