Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET DiskFolder.Delete throws an exception

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #20403 |


    I use Xceed.Zip and try to compress a folder to zip-file as follows:

            private void CompressTo(string fileName)
                var temp = new DiskFolder(TempFolder);
                var zip = new ZipArchive(new DiskFile(fileName));

                    temp.CopyFilesTo(zip, true, true);

     When i try temp.Delete(), i have Xceed.FileSystem.ItemIsReadOnlyException:

    Cannot perform the requested operation on an item that has the read-only attribute.

    Type: Xceed.FileSystem.DiskFile

    FullName: [User]\\AppData\\Local\\Temp\\81b57d21-0b25-44ce-a93c-ed34884e8eda\\media\\78566878-c4a1-480c-a8a0-f83f2fd2e7a2\\0720ae6c-ef79-4d77-8462-6b6d1c7e4ab1\\video.avi

       at Xceed.FileSystem.DiskFile.DoDelete(FileSystemEventsSession session)
       at Xceed.FileSystem.FileSystemItem.ListDeleteCore(FileSystemEventsSession session, ItemPair currentItemPair)
       at Xceed.FileSystem.FileSystemItem.ListDelete(FileSystemEventsSession session)
       at Xceed.FileSystem.FileSystemItem.Delete(FileSystemEvents events, Object userData)
       at Xceed.FileSystem.FileSystemItem.Delete()
       at iBwave.Mobile.Common.ZipSerializer.CompressTo(String fileName) in D:\Source\IBLIB\trunk\Internal\InternalProjects\iBwave.Mobile.Common\ZipSerializer.cs:line 160
       at iBwave.Mobile.Common.ZipSerializer.Export(Project project, String fileName, Exception& ex) in D:\Source\IBLIB\trunk\Internal\InternalProjects\iBwave.Mobile.Common\ZipSerializer.cs:line 135

    Also, if i don’t call DiskFolder.Delete() but instead try to delete my temp folder, i have pretty the same exception.

    It is a bit surprising since i thought  that CopyFilesTo method is synchronous, but looks like it isn’t.

    Is there any way to wait for compress operation is completed, or delete the folder in some other way?




    Imported from legacy forums. Posted by Dmitry (had 1515 views)

    Xceed Support
    Post count: 5658

    Hi Dmitry,

    I know that we resolved this issue yesterday, but I will post this answer in case another developer is looking for the solution

    If the folder and its child items are ReadOnly, you must change its
    Attributes to Normal so that you may Delete them. To do so, you must run
    your Delete on the DiskFolder. Then, you must trap the error in a
    Try/Catch and in the Catch, you must change the attributes for the
    folder and its children.

    I would suggest creating your own Delete() so that it does not make your code messy. For example:

    Public Sub DeleteMyFolderAndItsChildren()
        Catch ex As Exception
            ‘Set the Attributes to the DiskFolder
            temp.Attributes = IO.FileAttributes.Normal

            ‘Apply the Attributes to the DiskFolder

            ‘Change the attributes for the Children

            ‘You must call the Delete() again without error
        End Try
    End Sub

    You must then call the function that will change the Attributes for all child items so that they are not ReadOnly. For example:

    Public Sub ChangeAttributes(ByVal folder As DiskFolder)
        For Each childItem As FileSystemItem In folder.GetItems(True)
            childItem.Attributes = IO.FileAttributes.Normal
        Next childItem
    End Sub

    Imported from legacy forums. Posted by Marc [Xceed] (had 1121 views)

    User (Old forums)
    Post count: 23064

    But If i want to delete a zip file wrong zipped that it is being used yet because that zipping process was not finiched, how can i do?

    Imported from legacy forums. Posted by Francisco (had 143 views)

    Fawzi [Xceed]
    Post count: 722

    Hi Francisco,


    I am not sure if I understood what you mean properly. You could ask your question in French if you feel more comfortable expressing the issue. 

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 484 views)

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