Question

I had a piece of code that working without issue on Windows XP . Not our company has migrated to windows 7 and the software stopped working. De code itself opens an zip-file and extracts the content. Following it reads the content.

    Dim tempzip As String = "C:\ some very long path\bin\Debug\lib.zip"
    Dim tempdir As String = IO.Path.Combine(IO.Path.GetTempPath, Guid.NewGuid.ToString)
    Using zip1 As Ionic.Zip.ZipFile = Ionic.Zip.ZipFile.Read(tempzip)
        Dim e As Ionic.Zip.ZipEntry
        For Each e In zip1
            e.Extract(tempdir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
        Next
    End Using
    PropertiesAssembly = System.Reflection.Assembly.LoadFrom(IO.Path.Combine(tempdir, "some dll in zip-file"))

The error occurs at the e.Extract . He could apparently not find the zip-file. The exception thrown is your standard Could not find file or part of file...

The Zip-file does exist at the specified location and the needed assembly is present in the zip-file. The code has not been altered yet. This was merely a test to check the working.

Question: Is there a difference between windows 7 & windows xp in file-handling? if not, what might the cause of this strange behavior

Was it helpful?

Solution

I think its most likely the GetTempPath function returning different paths (the Temp folder does change). On XP, the path was short enough that adding the length of the Guid and the folders names in the zip file stayed within the limit of the max path name (I think 256 characters?), while on W7 GetTempPath returned a longer name which pushed the resulting paths over the limit.

This assuming that the zip file actually does exist where the program thinks it is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top