Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
How to Retrive the Selected Entries from the Zip.
posted

HI 

   I am creating the Zip file based on the Hierarchy.. So i am recrusively  go throught the enteries and get the selected path and add the FIle under the Folder. my issue is  how to retrive the selected path from the selectedEntries.

ZipEntry en = zip.SelectEntries(FileName).FirstOrDefault();

if the filename having space it is throwing argument null exception,

 pls see the attached sample project. like that  employee structureneed to create the folder,

can u update my project and send me.. 

thanks and regards

Kannan

  • 6759
    Offline posted

    Hi,

    I couldn't quite catch what exactly you are trying to achieve from the provided sample.  Here a few notes that might be of help:

    1. SelectEntry is not what you want: "This Method is intended for use with a ZipFile that has been Read from storage. When creating a new ZipFile, this Method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results. " - check out its help page
    2. ArgumentNullException is kind of expected because the string SelectCriteria has a specific format and in your case it is invalid - for more info click here
    3. So instead of
      ZipEntry en = zip.SelectEntries(FileName).FirstOrDefault();
      I suggest to use something like this:
      ZipEntry en = zip.Entries.FirstOrDefault(e => e.FileName == FileName);

     

    Regards

    • 125
      posted in reply to Konstantin Koynov

      HI 

      Thanks  for  reply. I need to  get the path  from the SelectedEntries. because of that i  am passing the string Value in  the  method. i got the help from the previously mentioned link.. i could nt able to achive.

      eg)

      i am creating the File .. 

       ZipEntry entry=  ZipEntry.CreateFile(item.ExportTitle + ".jpg", FullParentPath, image.ToStream());

       zip.Entries.Add(entry);

      then i need to add the Folder below file.so i am  using 

      ZipEntry en = zip.SelectEntries(FullParentPath).FirstOrDefault();

      here  not return the particular path.. can u provide one simple  project to get the paricular file in any levell .. this one how to form the String. 

      thanks 

      kan

       

      • 125
        posted in reply to Kannan

        HI 

         i didnt get the solution.. if the Folder name Having Spaces i didntable to retrive the Path.. 

        pls provide some samples .. very urgent.

        Thanks

        kan

        • 125
          posted in reply to Konstantin Koynov

          HI 

          Thanks for Ur help.

           i was tried what u mentioned but still not working. While Creating Directory 

            ZipEntry entrys = ZipEntry.CreateDirectory(emps.FullName);

          now i checked it is ends  with this "\\ "

          for file "/" i am not not able to retrieve the Path.. 

           i tried lot not able to retive the path if have any space in the FileName. some of my FolderName having Space me pasding the string as Path.. it returns null . 

          Pls can u provide one simple Example to  recursively retrieve the path and Created Folder or file inside. 

          Thanks 

          kan

          • 6759
            Offline posted in reply to Kannan

            Hi Kan,

            as far as I understood you you just need to extract the directory path from entry's FilePath. Basically your CreateZipFile method should look somthing like this:

            public void CreateZipFile(ZipFile zip, EmploYeeHierarchy emps,string FileName)
            {
            foreach (var item in emps.empHierarchy)
            {
            ZipEntry en = zip.Entries.FirstOrDefault(e => e.FileName == FileName);

            //Extract the path to the holding directory
            int lastIndex = en.FileName.LastIndexOf('/');
            string path = en.FileName.Substring(0, lastIndex);

            ZipEntry entry = ZipEntry.CreateFile(emps.ID + ".txt", path, "n77tr65r65");
            zip.Entries.Add(entry);
            var childFullPath = FileName + item.FullName.Trim();
            CreateZipFile(zip,item,"'" + childFullPath + "'");
            }
            }


            Hope this helps.
            • 125
              posted in reply to Kannan

              HI 

               I am creating the Folder inside only creating  File. because of that only need to retive the Folder  not a file.. if the Folder name having space not taking properly...