Reputation: 783
I have a file upload control. I restrict users to upload only zip files. the namespace i use is Ionic.Zip; I also want check if that zip file has a folder inside. I have to restrict the users not upload a zipfile with a folder inside. I could check how many files inside zip file like
using (ZipFile zip = ZipFile.Read(file_path))
{
if (zip.Count < 5)
{
}
I do not know how to check for a folder inside
Anyone can help me please. thanks in advance
Upvotes: 0
Views: 568
Reputation: 148624
void Main()
{
var isGood=false;
using (ZipFile zip = new ZipFile(@"c:\\1.zip"))
{
for (var i=0;i<zip.Count;i++)
if (zip[i].Attributes==FileAttributes.Directory)
{
isGood=false;
break;
}
}
if (isGood) Console.WriteLine ("ok");
else
Console.WriteLine ("error");
}
// Define other methods and classes here
there's seems to be a problem with the way you created this zip file.
I extracted the files from the file you sent me and created new zip : (named 3.zip):
and as you can see - the code works :
so I guess the dll is not powerful enough to recognize edge format
Upvotes: 2
Reputation: 3255
You can iterate on your zip object's ZipEntries - ZipEntry
object contains IsDirectory
property.
foreach(var entry in zip)
{
if(entry.IsDirectory)
{
//your stuff
}
}
Upvotes: 2