ZipArchiveEntry.FullName Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Zip arşivindeki girdinin göreli yolunu alır.
public:
property System::String ^ FullName { System::String ^ get(); };
public string FullName { get; }
member this.FullName : string
Public ReadOnly Property FullName As String
Özellik Değeri
Zip arşivindeki girdinin göreli yolu.
Açıklamalar
FullName özelliği, zip arşivindeki bir girdinin alt dizin hiyerarşisi de dahil olmak üzere göreli yolunu içerir. (Buna karşılık, Name özelliği yalnızca girdinin adını içerir ve alt dizin hiyerarşisini içermez.) Örneğin, yöntemini kullanarak CreateEntryFromFile bir zip arşivinde iki giriş oluşturur ve ilk girdinin ve ikinci girişin NewEntry.txt adını sağlarsanızAddedFolder\\NewEntry.txt, her iki girdi de özelliğinde NewEntry.txt olurName. İlk girdi özelliğinde NewEntry.txt de bulunurFullName, ancak ikinci girdi özelliğinde AddedFolder\\NewEntry.txt olurFullName.
Geçersiz ve mutlak yolları belirten dizeler de dahil olmak üzere herhangi bir dizeyi girdinin yolu olarak belirtebilirsiniz. Bu nedenle, FullName özelliği doğru biçimlendirilmemiş bir değer içerebilir. Zip arşivinin içeriğini ayıkladığınızda geçersiz veya mutlak bir yol özel durumla sonuçlanabilir.
Örnekler
Aşağıdaki örnekte, bir .zip dosyasının içeriğinde yineleme ve .txt uzantısını içeren dosyaları ayıklama gösterilmektedir.
using System;
using System.IO;
using System.IO.Compression;
class Program
{
static void Main(string[] args)
{
string zipPath = @".\result.zip";
Console.WriteLine("Provide path where to extract the zip file:");
string extractPath = Console.ReadLine();
// Normalizes the path.
extractPath = Path.GetFullPath(extractPath);
// Ensures that the last character on the extraction path
// is the directory separator char.
// Without this, a malicious zip file could try to traverse outside of the expected
// extraction path.
if (!extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
extractPath += Path.DirectorySeparatorChar;
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
{
// Gets the full path to ensure that relative segments are removed.
string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName));
// Ordinal match is safest, case-sensitive volumes can be mounted within volumes that
// are case-insensitive.
if (destinationPath.StartsWith(extractPath, StringComparison.Ordinal))
entry.ExtractToFile(destinationPath);
}
}
}
}
}
Imports System.IO
Imports System.IO.Compression
Module Module1
Sub Main()
Dim zipPath As String = ".\result.zip"
Console.WriteLine("Provide path where to extract the zip file:")
Dim extractPath As String = Console.ReadLine()
' Normalizes the path.
extractPath = Path.GetFullPath(extractPath)
' Ensures that the last character on the extraction path
' is the directory separator char.
' Without this, a malicious zip file could try to traverse outside of the expected
' extraction path.
If Not extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) Then
extractPath += Path.DirectorySeparatorChar
End If
Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
For Each entry As ZipArchiveEntry In archive.Entries
If entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) Then
' Gets the full path to ensure that relative segments are removed.
Dim destinationPath As String = Path.GetFullPath(Path.Combine(extractPath, entry.FullName))
' Ordinal match is safest, case-sensitive volumes can be mounted within volumes that
' are case-insensitive.
If destinationPath.StartsWith(extractPath, StringComparison.Ordinal) Then
entry.ExtractToFile(destinationPath)
End If
End If
Next
End Using
End Sub
End Module