Click here to Skip to main content
15,888,224 members
Home / Discussions / C#
   

C#

 
GeneralRe: Query error: no such column Pin
DPaul19946-Apr-15 5:40
DPaul19946-Apr-15 5:40 
GeneralRe: Query error: no such column Pin
Dave Kreskowiak6-Apr-15 6:26
mveDave Kreskowiak6-Apr-15 6:26 
GeneralRe: Query error: no such column Pin
DPaul19946-Apr-15 6:41
DPaul19946-Apr-15 6:41 
GeneralRe: Query error: no such column Pin
Dave Kreskowiak6-Apr-15 7:35
mveDave Kreskowiak6-Apr-15 7:35 
GeneralRe: Query error: no such column Pin
DPaul19946-Apr-15 8:07
DPaul19946-Apr-15 8:07 
GeneralRe: Query error: no such column Pin
Dave Kreskowiak6-Apr-15 8:22
mveDave Kreskowiak6-Apr-15 8:22 
GeneralRe: Query error: no such column Pin
DPaul19946-Apr-15 8:26
DPaul19946-Apr-15 8:26 
QuestionHow to pass folder hierarchy when creating zip file from memory stream using DotNetZip library Pin
Tridip Bhattacharjee6-Apr-15 1:09
professionalTridip Bhattacharjee6-Apr-15 1:09 
Requirement: 1) creating split zips file in multiple segments(say size - 1 GB/500 MB), so that they can be downloaded through browser. The total zip volume of all the segments could exceed 10 GB 2) the zip content could be multiple files or a folder containing sub folders and files 3) the content of the file are read from Cloud in the form of stream. The meta information for the files(like folder hierarchy) are locally available

I am using DotNetZip library to achieve the task. The code is as following:

long length = default(long);
Stream fileReadStream;
long Space = default(long);
string tempZipFile = string.Empty;
FileZipStatus oldStatue = new FileZipStatus();
byte[] Buffer = new byte[1024 * 1024];

if (zipFileName != null && !zipFileName.ToUpper().EndsWith(".ZIP")) zipFileName += ".zip";
string strTempFolder = "";
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
{
    try
    {
        strTempFolderPath = tempZipOutPutFilePath + "\\";
        string strTempFolderName = DateTime.Now.Ticks.ToString();
        strTempFolder = strTempFolderPath + strTempFolderName;
        if (userFileList.Count > 0)
        {
            if (Directory.Exists(strTempFolder))
            {
                Directory.Delete(strTempFolder);
            }
            Directory.CreateDirectory(strTempFolder);
        }
        foreach (UserFile userFile in userFileList)
        {
            WebResponse response = null;
            try
            {
                WebRequest request = null;
                IDictionary<string, object> _dictionary = new Dictionary<string, object>();
                /// First
                FileSystemEnum fileSysEnum = FileSystemBase.GetFileSystemEnumByStorageId(userFile.StorageId);
                IFileSystemLib ifileSystemLocal = FileSystemFactory.GetSpecificInstance(fileSysEnum);

                fileReadStream = ifileSystemLocal.GetFile(userFile.FilePath, userFile.GuidName, ref request, ref response, _dictionary);
                long filesize = default(long);

                long.TryParse(ifileSystemLocal.GetFileContentLength(userFile.FilePath, userFile.GuidName).ToString(), out filesize);
                Space = (Space > default(long)) ? (Space + filesize) : filesize;
                //Now we have to store the data, so that we must access the file

                int dataToRead;
                FileStream writeStream = new FileStream(strTempFolder + "\\" + userFile.FileName, FileMode.Create, FileAccess.Write);
                while ((dataToRead = fileReadStream.Read(Buffer, 0, Buffer.Length)) > 0)
                {
                    writeStream.Write(Buffer, 0, dataToRead);
                }
                writeStream.Close();

                zip.AddFile(strTempFolder + "\\" + userFile.FileName, userFile.RelativePath);
                fileReadStream.Close();
            }
            catch (Exception ex)
            {
                LogManager.Trace(ex, "ZIpping Block - ZIPFileName", zipFileName + "File to zip" + userFile.GuidName);
            }
            finally
            {
                if (response != null) response.Close();
            }
        }
    }
    catch (Exception ex)
    {
        _currentStatus = FileZipStatus.NotAvailable;
        oldStatue = UpdateZipStatus(ObjectZipID, Space, FileZipStatus.Failed);
        throw ex;
    }
    finally
    {
    }
    try
    {
        zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
        zip.MaxOutputSegmentSize = 200 * 1024 * 1024;   // 200 mb
        zip.Save(strTempFolderPath + "\\" + zipFileName);
        oldStatue = UpdateZipStatus(ObjectZipID, Space, FileZipStatus.Available);
        length = new FileInfo(strTempFolderPath + "\\" + zipFileName).Length;
        _currentStatus = FileZipStatus.Available;
        // deleting temp folder
        Directory.Delete(strTempFolder, true);
    }
    catch (Exception ex)
    {
        _currentStatus = FileZipStatus.NotAvailable;
        oldStatue = UpdateZipStatus(ObjectZipID, Space, FileZipStatus.Failed);
        length = default(long);
        throw ex;
    }
}

There are a limitation of the DotNetZip libray used in the above code. It either needs a) files saved on disk as input. In that case folder hierarchy information could be passed for each file. or 2) if stream is passed as input, folder hierarchy information could NOT be passed for file.

I need to pass in the folder hierarchy information for each file as well as read the input from stream. As the zip content could be huge(could exceed 10 GB), do not want to save the files on temporary storage in web server. Can Anyone help like how to pass folder hierarchy when creating zip file? thanks
tbhattacharjee

AnswerRe: How to pass folder hierarchy when creating zip file from memory stream using DotNetZip library Pin
Eddy Vluggen6-Apr-15 2:42
professionalEddy Vluggen6-Apr-15 2:42 
AnswerRe: How to pass folder hierarchy when creating zip file from memory stream using DotNetZip library Pin
Dr Gadgit6-Apr-15 4:03
Dr Gadgit6-Apr-15 4:03 
AnswerRe: How to pass folder hierarchy when creating zip file from memory stream using DotNetZip library Pin
Dave Kreskowiak6-Apr-15 4:43
mveDave Kreskowiak6-Apr-15 4:43 
GeneralRe: How to pass folder hierarchy when creating zip file from memory stream using DotNetZip library Pin
Tridip Bhattacharjee6-Apr-15 21:27
professionalTridip Bhattacharjee6-Apr-15 21:27 
SuggestionRe: How to pass folder hierarchy when creating zip file from memory stream using DotNetZip library Pin
Richard Deeming7-Apr-15 2:07
mveRichard Deeming7-Apr-15 2:07 
Questionsplit string Pin
Member 103707115-Apr-15 12:53
professionalMember 103707115-Apr-15 12:53 
AnswerRe: split string Pin
Richard Andrew x645-Apr-15 13:07
professionalRichard Andrew x645-Apr-15 13:07 
GeneralصهفاRe: split string Pin
Member 103707115-Apr-15 13:20
professionalMember 103707115-Apr-15 13:20 
GeneralRe: split string Pin
PIEBALDconsult5-Apr-15 13:23
mvePIEBALDconsult5-Apr-15 13:23 
GeneralRe: split string Pin
Member 103707115-Apr-15 13:27
professionalMember 103707115-Apr-15 13:27 
GeneralRe: split string Pin
Dr Gadgit6-Apr-15 3:39
Dr Gadgit6-Apr-15 3:39 
SuggestionRe: split string Pin
Richard Deeming7-Apr-15 2:10
mveRichard Deeming7-Apr-15 2:10 
GeneralRe: split string Pin
Dr Gadgit11-Apr-15 7:36
Dr Gadgit11-Apr-15 7:36 
QuestionHow to Install Windows OS On selected IP's In a Network Pin
Member 105963985-Apr-15 0:20
Member 105963985-Apr-15 0:20 
AnswerRe: How to Install Windows OS On selected IP's In a Network Pin
OriginalGriff5-Apr-15 1:21
mveOriginalGriff5-Apr-15 1:21 
GeneralRe: How to Install Windows OS On selected IP's In a Network Pin
Member 105963985-Apr-15 1:55
Member 105963985-Apr-15 1:55 
GeneralRe: How to Install Windows OS On selected IP's In a Network Pin
OriginalGriff5-Apr-15 2:13
mveOriginalGriff5-Apr-15 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.