Share via


ZipArchive.CreateEntryFromFile Method (String, String, CompressionLevel)

Adds a file from the file system to the archive under the specified entry name.

The new entry in the archive will contain the contents of the file.

The last write time of the archive entry is set to the last write time of the file on the file system.

If an entry with the specified name already occurs in the archive, a second entry will be created that has the same name.

If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.

Namespace:  Microsoft.TeamFoundation.Framework.Server
Assembly:  Microsoft.TeamFoundation.Framework.Server (in Microsoft.TeamFoundation.Framework.Server.dll)

Syntax

'Declaration
Public Function CreateEntryFromFile ( _
    sourceFileName As String, _
    entryName As String, _
    compressionLevel As CompressionLevel _
) As ZipArchiveEntry
public ZipArchiveEntry CreateEntryFromFile(
    string sourceFileName,
    string entryName,
    CompressionLevel compressionLevel
)
public:
ZipArchiveEntry^ CreateEntryFromFile(
    String^ sourceFileName, 
    String^ entryName, 
    CompressionLevel compressionLevel
)
member CreateEntryFromFile : 
        sourceFileName:string * 
        entryName:string * 
        compressionLevel:CompressionLevel -> ZipArchiveEntry
public function CreateEntryFromFile(
    sourceFileName : String, 
    entryName : String, 
    compressionLevel : CompressionLevel
) : ZipArchiveEntry

Parameters

  • sourceFileName
    Type: System.String

    The path of the file on the file system to be copied from. The path is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.

  • entryName
    Type: System.String

    The name of the entry to be created.

Return Value

Type: Microsoft.TeamFoundation.Framework.Server.ZipArchiveEntry
A wrapper for the newly created entry.

Exceptions

Exception Condition
ArgumentException

sourceFileName is a zero-length string, or it contains only white space, or it contains one or more invalid characters as defined by InvalidPathChars, or entryName is a zero-length string.

ArgumentNullException

sourceFileName or entryName is null.

PathTooLongException

In sourceFileName, the specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

DirectoryNotFoundException

The specified sourceFileName is invalid; for example, if it is on an unmapped drive.

IOException

An I/O error occurred while you are opening the file specified by sourceFileName.

UnauthorizedAccessException

sourceFileName specified a directory, or the caller does not have the required permission.

FileNotFoundException

The file specified in sourceFileName was not found.

NotSupportedException

sourceFileName is in an invalid format, or the ZipArchive does not support writing.

ObjectDisposedException

The ZipArchive has already been closed.

.NET Framework Security

See Also

Reference

ZipArchive Class

CreateEntryFromFile Overload

Microsoft.TeamFoundation.Framework.Server Namespace