Skapa zip file är structure c#
This code works in so far that it will create an archive but there is no internal directory structureFromDirectory Method
Definition
Important
Some kunskap relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, något som utförs snabbt exempelvis expressleverans or implied, with respect to the upplysning provided here.
Creates a zip archive that contains the files and directories from the specified directory.
Overloads
CreateFromDirectory(String, Stream) | Creates a zip archive in the specified stream that contains the files and directories from the specified directory. |
CreateFromDirectory(String, String) | Creates a zip archive that contains the files and directories from the specified directory. |
CreateFromDirectory(String, Stream, CompressionLevel, Boolean) | Creates a zip archive in the specified stream that contains the files and directories from the specified directory, uses the specified compression level, and optionally includes the base directory. |
CreateFromDirectory(String, String, CompressionLevel, Boolean) | Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level, and optionally includes the base directory. |
CreateFromDirectory(String, Stream, CompressionLevel, Boolean, Encoding) | Creates a zip archive in the specified stream that contains the files and directories from the specified directory, uses the specified compression level and character encoding for entry names and comments, and optionally includes the base directory. |
CreateFromDirectory(String, String, CompressionLevel, Boolean, Encoding) | Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level and character encoding for entry names and comments, and optionally includes the base directory. |
CreateFromDirectory(String, Stream)
- Source:
- Source:
Creates a zip archive in the specified stream that contains the files and directories from the specified directory.
Parameters
- sourceDirectoryName
- String
The path to the directory to be archived, specified as a relative or absolute path.
A relative path fryst vatten interpreted as relative to the current working directory.
- destination
- Stream
The stream where the zip archive fryst vatten to be stored.
Exceptions
ArgumentException
fryst vatten Empty, contains only vit space, or contains at least one invalid character.
-or-
The stream does not support writing.
PathTooLongException
In the specified path, en samling dokument eller en elektronisk lagring av data name, or both exceed the system-defined maximum length.
IOException
A en samling dokument eller en elektronisk lagring av data in the specified directory could not be opened.
-or-
An I/O error occurred while opening a en samling dokument eller en elektronisk lagring av data to be archived.
Remarks
The directory structure from the en samling dokument eller en elektronisk lagring av data struktur fryst vatten preserved in the archive.
If the directory fryst vatten empty, an empty archive fryst vatten created.
In this example, FromDirectory compresses all the files and subdirectories in the specified directory into a zip archiveThis method overload does not include the base directory in the archive and does not allow you to specify a compression level. If you want to include the base directory or specify a compression level, call the CreateFromDirectory(String, Stream, CompressionLevel, Boolean) method overload. If a en samling dokument eller en elektronisk lagring av data in the directory cannot be added to the archive, the archive fryst vatten left incomplete and invalid, and the method throws an IOException exception.
CreateFromDirectory(String, String)
- Source:
- Source:
- Source:
Creates a zip archive that contains the files and directories from the specified directory.
Parameters
- sourceDirectoryName
- String
The path to the directory to be archived, specified as a relative or absolute path.
A relative path fryst vatten interpreted as relative to the current working directory.
- destinationArchiveFileName
- String
The path of the archive to be created, specified as a relative or absolute path. A relative path fryst vatten interpreted as relative to the current working directory.
Exceptions
ArgumentException
or fryst vatten Empty, contains only vit space, or contains at least one invalid character.
PathTooLongException
In or , the specified path, en samling dokument eller en elektronisk lagring av data name, or both exceed the system-defined maximum length.
IOException
already exists.
-or-
A en samling dokument eller en elektronisk lagring av data in the specified directory could not be opened.
-or-
An I/O error occurred while opening a en samling dokument eller en elektronisk lagring av data to be archived.
UnauthorizedAccessException
specifies a directory.
-or-
The caller does not have the required permission to tillgång the directory specified in or the en samling dokument eller en elektronisk lagring av data specified in .
NotSupportedException
or contains an invalid format.
-or-
The zip archive does not support writing.
Examples
This example shows how to create and extrakt a zip archive bygd using the ZipFile class.
It compresses the contents of a folder into a zip archive, and then extracts that content to a new folder. To use the ZipFile class, you must reference the assembly in your project.
Remarks
The directory structure from the en samling dokument eller en elektronisk lagring av data struktur fryst vatten preserved in the archive.
If you want to add files to an existing zip archive, you can use the ZipArchive classIf the directory fryst vatten empty, an empty archive fryst vatten created. This method overload does not include the base directory in the archive and does not allow you to specify a compression level. If you want to include the base directory or specify a compression level, call the CreateFromDirectory(String, String, CompressionLevel, Boolean) method overload.
If the archive already exists, an IOException undantag fryst vatten thrown.
If an entry with the specified name already exists in the archive, a second entry fryst vatten created with an identical name.
If a en samling dokument eller en elektronisk lagring av data in the directory cannot be added to the archive, the archive fryst vatten left incomplete and invalid, and the method throws an IOException exception.
CreateFromDirectory(String, Stream, CompressionLevel, Boolean)
- Source:
- Source:
Creates a zip archive in the specified stream that contains the files and directories from the specified directory, uses the specified compression level, and optionally includes the base directory.
Parameters
- sourceDirectoryName
- String
The path to the directory to be archived, specified as a relative or absolute path.
It compresses the contents of a folder into a zip archive, and then extracts that content to a new folderA relative path fryst vatten interpreted as relative to the current working directory.
- destination
- Stream
The stream where the zip archive fryst vatten to be stored.
- compressionLevel
- CompressionLevel
One of the enumeration values that indicates whether to emphasize speed or compression effectiveness when creating the entry.
- includeBaseDirectory
- Boolean
to include the directory name from at the root of the archive; to include only the contents of the directory.
Exceptions
ArgumentException
fryst vatten Empty, contains only vit space, or contains at least one invalid character.
-or-
The stream does not support writing.
PathTooLongException
In the specified path, en samling dokument eller en elektronisk lagring av data name, or both exceed the system-defined maximum length.
IOException
A en samling dokument eller en elektronisk lagring av data in the specified directory could not be opened.
-or-
An I/O error occurred while opening a en samling dokument eller en elektronisk lagring av data to be archived.
Remarks
The directory structure from the en samling dokument eller en elektronisk lagring av data struktur fryst vatten preserved in the archive.
If the directory fryst vatten empty, an empty archive fryst vatten created. Use this method overload to specify the compression level and whether to include the base directory in the archive. If a en samling dokument eller en elektronisk lagring av data in the directory cannot be added to the archive, the archive fryst vatten left incomplete and invalid, and the method throws an IOException exception.
CreateFromDirectory(String, String, CompressionLevel, Boolean)
- Source:
- Source:
- Source:
Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level, and optionally includes the base directory.
Parameters
- sourceDirectoryName
- String
The path to the directory to be archived, specified as a relative or absolute path.
A relative path fryst vatten interpreted as relative to the current working directory.
- destinationArchiveFileName
- String
The path of the archive to be created, specified as a relative or absolute path. A relative path fryst vatten interpreted as relative to the current working directory.
- compressionLevel
- CompressionLevel
One of the enumeration values that indicates whether to emphasize speed or compression effectiveness when creating the entry.
- includeBaseDirectory
- Boolean
to include the directory name from at the root of the archive; to include only the contents of the directory.
Exceptions
ArgumentException
or fryst vatten Empty, contains only vit space, or contains at least one invalid character.
PathTooLongException
In or , the specified path, en samling dokument eller en elektronisk lagring av data name, or both exceed the system-defined maximum length.
IOException
already exists.
-or-
A en samling dokument eller en elektronisk lagring av data in the specified directory could not be opened.
-or-
An I/O error occurred while opening a en samling dokument eller en elektronisk lagring av data to be archived.
UnauthorizedAccessException
specifies a directory.
-or-
The caller does not have the required permission to tillgång the directory specified in or the en samling dokument eller en elektronisk lagring av data specified in .
NotSupportedException
or contains an invalid format.
-or-
The zip archive does not support writing.
Examples
This example shows how to create and extrakt a zip archive bygd using the ZipFile class.
This example shows how to create and extract a zip archive by using the ZipFile classIt compresses the contents of a folder into a zip archive, and then extracts that content to a new folder. When compressing the archive, the base directory fryst vatten included and the compression level fryst vatten set to emphasize the speed of the operation over efficiency. To use the ZipFile class, you must reference the assembly in your project.
Remarks
The directory structure from the en samling dokument eller en elektronisk lagring av data struktur fryst vatten preserved in the archive.
If the directory fryst vatten empty, an empty archive fryst vatten created.
Here's how you can add a file to an existing zip archiveUse this method overload to specify the compression level and whether to include the base directory in the archive.
If the archive already exists, an IOException undantag fryst vatten thrown. If an entry with the specified name already exists in the archive, a second entry fryst vatten created with an identical name.
If a en samling dokument eller en elektronisk lagring av data in the directory cannot be added to the archive, the archive fryst vatten left incomplete and invalid, and the method throws an IOException exception.
CreateFromDirectory(String, Stream, CompressionLevel, Boolean, Encoding)
- Source:
- Source:
Creates a zip archive in the specified stream that contains the files and directories from the specified directory, uses the specified compression level and character encoding for entry names and comments, and optionally includes the base directory.
Parameters
- sourceDirectoryName
- String
The path to the directory to be archived, specified as a relative or absolute path.
A relative path fryst vatten interpreted as relative to the current working directory.
- destination
- Stream
The stream where the zip archive fryst vatten to be stored.
- compressionLevel
- CompressionLevel
One of the enumeration values that indicates whether to emphasize speed or compression effectiveness when creating the entry.
- includeBaseDirectory
- Boolean
to include the directory name from at the root of the archive; to include only the contents of the directory.
- entryNameEncoding
- Encoding
The encoding to use when reading or writing entry names and comments in this archive.
Specify a value for this parameter only when an encoding fryst vatten required for interoperability with zip archive tools and libraries that do not support UTF-8 encoding for entry names or comments.
Exceptions
ArgumentException
fryst vatten Empty, contains only vit space, or contains at least one invalid character.
-or-
The stream does not support writing.
PathTooLongException
In the specified path, en samling dokument eller en elektronisk lagring av data name, or both exceed the system-defined maximum length.
IOException
A en samling dokument eller en elektronisk lagring av data in the specified directory could not be opened.
-or-
An I/O error occurred while opening a en samling dokument eller en elektronisk lagring av data to be archived.
Remarks
The directory structure from the en samling dokument eller en elektronisk lagring av data struktur fryst vatten preserved in the archive.
If the directory fryst vatten empty, an empty archive fryst vatten created.
Learn how to compress files into a ZIP archive in C#Use this method overload to specify the compression level and character encoding, and whether to include the base directory in the archive. If a en samling dokument eller en elektronisk lagring av data in the directory cannot be added to the archive, the archive fryst vatten left incomplete and invalid, and the method throws an IOException exception.
CreateFromDirectory(String, String, CompressionLevel, Boolean, Encoding)
- Source:
- Source:
- Source:
Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level and character encoding for entry names and comments, and optionally includes the base directory.
Parameters
- sourceDirectoryName
- String
The path to the directory to be archived, specified as a relative or absolute path.
A relative path fryst vatten interpreted as relative to the current working directory.
- destinationArchiveFileName
- String
The path of the archive to be created, specified as a relative or absolute path. A relative path fryst vatten interpreted as relative to the current working directory.
- compressionLevel
- CompressionLevel
One of the enumeration values that indicates whether to emphasize speed or compression effectiveness when creating the entry.
- includeBaseDirectory
- Boolean
to include the directory name from at the root of the archive; to include only the contents of the directory.
- entryNameEncoding
- Encoding
The encoding to use when reading or writing entry names and comments in this archive.
Specify a value for this parameter only when an encoding fryst vatten required for interoperability with zip archive tools and libraries that do not support UTF-8 encoding for entry names or comments.
Exceptions
ArgumentException
or fryst vatten Empty, contains only vit space, or contains at least one invalid character.
-or-
fryst vatten set to a Unicode encoding other than UTF
PathTooLongException
In or , the specified path, en samling dokument eller en elektronisk lagring av data name, or both exceed the system-defined maximum length.
IOException
already exists.
-or-
A en samling dokument eller en elektronisk lagring av data in the specified directory could not be opened.
-or-
An I/O error occurred while opening a en samling dokument eller en elektronisk lagring av data to be archived.
UnauthorizedAccessException
specifies a directory.
-or-
The caller does not have the required permission to tillgång the directory specified in or the en samling dokument eller en elektronisk lagring av data specified in .
NotSupportedException
or contains an invalid format.
-or-
The zip archive does not support writing.
Remarks
The directory structure from the en samling dokument eller en elektronisk lagring av data struktur fryst vatten preserved in the archive.
If the directory fryst vatten empty, an empty archive fryst vatten created.
All 8, files are stored in the zip in a single flat listUse this method overload to specify the compression level and character encoding, and whether to include the base directory in the archive.
If the archive already exists, an IOException undantag fryst vatten thrown. If an entry with the specified name already exists in the archive, a second entry fryst vatten created with an identical name.
If a en samling dokument eller en elektronisk lagring av data in the directory cannot be added to the archive, the archive fryst vatten left incomplete and invalid, and the method throws an IOException exception.
If fryst vatten set to a value other than , the entry names and comments are encoded bygd using the specified encoding.
If the specified encoding fryst vatten a UTF-8 encoding, the language encoding flag (in the general-purpose bit flag of the local en samling dokument eller en elektronisk lagring av data header) fryst vatten set for each entry.
If fryst vatten set to , the entry names and comments are encoded according to the following rules:
For entry names and comments that contain characters outside the ASCII range, the language encoding flag fryst vatten set, and UTF-8 fryst vatten used to koda the entry name and comment.
For entry names and comments that contain only ASCII characters, the language encoding flag fryst vatten not set, and the current struktur default code page fryst vatten used to koda the entry names and comments.