Question

Solution Found.

Thanks to everyone helping me, I found out what the root problem was. The .trl file had nothing to do with it. It was the path being created wrong. I was doing "TRLR" + Path, when it should have been "TRLR" + fileName. This was a stupid error on my part, and I apologize for wasting your time, but I appreciate the help!


I have a zip file given to us by a 3rd party. In this zip files are custom files. These are just text files with a different extension, which I assume is just to frustrate me.

I'm trying to open this files in my C# application, but it keeps throwing the error that the format is not supported.

Since these are just text files, I feel there must be some way for this to happen.

If anyone has any ideas, please let me know.

Code:

using (ZipArchive archive = ZipFile.OpenRead(_trailerName))
{
     ZipArchiveEntry entry = archive.GetEntry(tableChanged + ".trl");
     Stream ms = entry.Open(); //Here is what's causing the issue.
     StreamReader reader = new StreamReader(ms);
     string allLinesRead = reader.ReadToEnd();
     string[] everyCell = allLinesRead.Split('|');
     int numRecords = Convert.ToInt32(everyCell[1]);
     int numChanged = getRecordNum(tableChanged);
     Console.Write(numRecords + "/" + numChanged + " - " + tableChanged);
     if (numChanged != numRecords)
     {
          _errorMessage += "Records updated do not match trailer. (" + numRecords + "/" + numChanged + ") Please check database. Table affected: " + tableChanged + Environment.NewLine;
     }
}

Error:

The given path's format is not supported.

I know this is specific, but I need advice on what steps I can take to resolve this.

Thanks.

Was it helpful?

Solution

The native zip functionality of .NET is frequently lacking in terms of the ability to handle and modify zip files created by applications other than the windows zip tool. While the "zip" file is standardized, you still see a decent amount of variation on file headers and attributes.

I would suggest you look into DotNetZip (Ionic), which is a third party library that has very robust capabilities in terms of creating and opening zip files. I've found it to be much more forgiving and capable than the basic functionality that .NET gives you, and the code to open a zip is extremely similar to what you have.

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