ZipArchiveEntry.FullName Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt het relatieve pad van de vermelding in het zip-archief opgeslagen.
public:
property System::String ^ FullName { System::String ^ get(); };
public string FullName { get; }
member this.FullName : string
Public ReadOnly Property FullName As String
Waarde van eigenschap
Het relatieve pad van de vermelding in het zip-archief.
Opmerkingen
De FullName eigenschap bevat het relatieve pad, inclusief de submaphiërarchie, van een vermelding in een zip-archief. (De eigenschap bevat daarentegen Name alleen de naam van de vermelding en bevat niet de submaphiërarchie.) Als u bijvoorbeeld twee vermeldingen in een zip-archief maakt met behulp van de CreateEntryFromFile methode en opgeeft NewEntry.txt als de naam voor het eerste item en AddedFolder\\NewEntry.txt voor het tweede item, hebben NewEntry.txt beide vermeldingen in de Name eigenschap. Het eerste item heeft ook NewEntry.txt in de FullName eigenschap, maar de tweede vermelding heeft AddedFolder\\NewEntry.txt de FullName eigenschap.
U kunt elke tekenreeks opgeven als het pad van een vermelding, inclusief tekenreeksen die ongeldige en absolute paden opgeven. Daarom kan de FullName eigenschap een waarde bevatten die niet juist is opgemaakt. Een ongeldig of absoluut pad kan resulteren in een uitzondering wanneer u de inhoud van het zip-archief extraheert.
Voorbeelden
In het volgende voorbeeld ziet u hoe u de inhoud van een .zip bestand kunt herhalen en bestanden kunt extraheren die de .txt-extensie bevatten.
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