The following code snippet takes the specified file (sourceFilePath) and creates Zip file.
using System.IO;
using System.IO.Compression;
public class FilesProcess
{
public bool ConvertFileToZip(string sourceFilePath, string destinationZipFilePath)
{
bool isFileZipped = false;
using (ZipArchive archive = ZipFile.Open(destinationZipFilePath, ZipArchiveMode.Create))
{
archive.CreateEntryFromFile(sourceFilePath, Path.GetFileName(sourceFilePath));
}
if (File.Exists(destinationZipFilePath))
{
isFileZipped = true;
}
return isFileZipped;
}
}
using System.IO;
using System.IO.Compression;
public class FilesProcess
{
public bool ConvertFileToZip(string sourceFilePath, string destinationZipFilePath)
{
bool isFileZipped = false;
using (ZipArchive archive = ZipFile.Open(destinationZipFilePath, ZipArchiveMode.Create))
{
archive.CreateEntryFromFile(sourceFilePath, Path.GetFileName(sourceFilePath));
}
if (File.Exists(destinationZipFilePath))
{
isFileZipped = true;
}
return isFileZipped;
}
}
No comments:
Post a Comment