.NET में ZIP से SHP Files Extract करें

Aspose.ZIP for .NET से ZIP archive में stored Shapefile dataset के components restore करें। .shp file geometry रखती है, लेकिन usable dataset के लिए समान base name वाली .shx और .dbf files तथा उपलब्ध होने पर .prj और .cpg भी आवश्यक होते हैं।

Selective extraction GIS imports, map services, spatial ETL और dataset exchange के लिए उपयोगी है। Application unrelated files छोड़ सकती है, names और sizes validate कर सकती है तथा पूरा package unpack किए बिना approved items अगले business component तक भेज सकती है।

C# से ZIP Archive में SHP Files कैसे Extract करें

Aspose.ZIP for .NET package install करें और Aspose.Zip namespace reference करें। Extraction से पहले entry metadata उपलब्ध होती है, इसलिए application file लिखने से पहले ArchiveEntry.Name, ArchiveEntry.IsDirectory और ArchiveEntry.UncompressedSize जांच सकती है।


Package Manager Console Command

PM> Install-Package Aspose.Zip

ZIP को Archive से खोलें, Archive.Entries enumerate करें और एक ही dataset की .shp, .shx, .dbf, .prj तथा .cpg entries चुनें। हर component को validated destination में लिखें और archived path को target folder से बाहर न जाने दें।

C# में SHP Files Extract करने के चरण

  • Source ZIP path define करें और isolated output directory बनाएं।
  • Input को Archive class से खोलें।
  • पूरा package तुरंत extract करने के बजाय Archive.Entries enumerate करें।
  • SHP geometry और समान base name वाली companion files चुनें।
  • ऐसा destination path बनाएं जो approved root के भीतर रहे।
  • Configured extracted-size limit से बड़ी entries reject करें।
  • हर approved entry को ArchiveEntry.Extract से save करें।

सिस्टम आवश्यकताएं

Example चलाने से पहले सुनिश्चित करें कि environment में यह उपलब्ध हो:

  • Windows, Linux या macOS पर supported .NET runtime।
  • Visual Studio, JetBrains Rider, Visual Studio Code या अन्य C# environment।
  • NuGet से installed या assembly के रूप में referenced Aspose.ZIP for .NET।
  • Source ZIP पर read access और destination directory पर write access।
  • Size, execution time और temporary storage की स्पष्ट limits।

C# उदाहरण: ZIP से चुनी हुई SHP Files Extract करें

Code ZIP package खोलता है, directory entries छोड़ता है, format से मेल खाने वाली entries filter करता है और approved files को controlled destination में लिखता है। Production में duplicate filenames के लिए deterministic rule और total extracted-size limit भी जोड़ें।

ZIP से SHP Files Extract करें - C#

using Aspose.Zip;
using System;
using System.IO;

string archivePath = Path.GetFullPath("geodata.zip");
string outputDirectory = Path.GetFullPath("extracted-shapefile");
string[] requiredExtensions = { ".shp", ".shx", ".dbf", ".prj", ".cpg" };
const ulong MaxEntrySize = 100UL * 1024 * 1024;

Directory.CreateDirectory(outputDirectory);

using (var archive = new Archive(archivePath))
{
    foreach (ArchiveEntry entry in archive.Entries)
    {
        if (entry.IsDirectory) continue;

        string fileName = Path.GetFileName(entry.Name);
        if (string.IsNullOrWhiteSpace(fileName)) continue;

        string extension = Path.GetExtension(fileName);
        if (!Array.Exists(
            requiredExtensions,
            value => string.Equals(value, extension, StringComparison.OrdinalIgnoreCase)))
        {
            continue;
        }

        if (entry.UncompressedSize > MaxEntrySize)
        {
            throw new InvalidDataException(
                $"Entry '{fileName}' exceeds the 100 MB extraction limit.");
        }

        string destinationPath = Path.Combine(outputDirectory, fileName);
        entry.Extract(destinationPath);
    }
}

Production में SHP Files के लिए नोट्स

Shapefile एक multi-file dataset है। समान base name वाले .shp, .shx और .dbf files को साथ रखें तथा उपलब्ध होने पर .prj और .cpg भी extract करें।

Extension filtering केवल candidate file पहचानती है; यह internal structure या integrity validate नहीं करती। Import, preview या conversion से पहले file को GIS component से जांचें। Duplicate names के लिए स्पष्ट policy रखें और कुल extracted size भी सीमित करें।

सुरक्षा और गोपनीयता

Uploaded ZIP, entry names और content को untrusted input मानें। ArchiveEntry.Name को सीधे output directory से combine न करें; entry में absolute path या parent-directory segments हो सकते हैं। Folders preserve करने हों तो final path resolve करके जांचें कि वह approved root के भीतर ही है।

Compressed size, extracted size, entry count, execution time और concurrency सीमित करें। Restricted temporary storage उपयोग करें, failure के बाद output साफ करें और passwords, private filenames या extracted content logs में न लिखें।

SHP files निकालने से जुड़े सामान्य प्रश्न

C# में ZIP archive से केवल SHP files कैसे extract करें?

ZIP को Archive से खोलें, Archive.Entries enumerate करें, non-directory entries को .shp, .shx, .dbf, .prj और .cpg के अनुसार filter करें और हर validated output path के लिए Extract call करें।

क्या Aspose.ZIP SHP file का content parse करता है?

नहीं। Aspose.ZIP archive में stored file restore करता है। उसके content को पढ़ना, validate करना या convert करना उस format के specialized component की जिम्मेदारी है।

क्या यही workflow 7Z, RAR या TAR archives के साथ काम करता है?

Concept समान है, लेकिन हर container को संबंधित Aspose.ZIP class से खोलना होगा। Entry APIs और supported operations format के अनुसार बदल सकते हैं।

Duplicate SHP filenames कैसे handle करें?

Extraction से पहले policy तय करें: duplicate reject करें, unique name generate करें या validated relative directory structure बनाए रखें।