This is a migrated thread and some comments may be shown as answers.

Error: Windows cannot complete the extration. The destination file could not be create.

4 Answers 153 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
German
Top achievements
Rank 1
German asked on 18 Apr 2017, 01:36 PM

The dynamic Word documents was created in ASP.net  and stream it through System.IO.MemoryStream.

I read the stream data from System.IO.MemoryStream and put it in a Zip file using Telerik Zip Archive Entry,

But the error of "The destination file could not be create" keeps popping out...please see my code below and

let me know what I missed....Please help me....thanks.

oResponse.Clear()
oResponse.AddHeader("content-disposition", "attachment; filename=Gerrytest4.zip")
oResponse.ContentType = "application/octet-stream"
Using memoryStream As New System.IO.MemoryStream
       Using archive As New ZipArchive(memoryStream, ZipArchiveMode.Create, True, Nothing)
              Using entry As ZipArchiveEntry = archive.CreateEntry(sSSPFilename)
                     Dim writer As New BinaryWriter(entry.Open())
                     oDocTemplate.Save(memoryStream, oFormat)
                     Dim sr As BinaryReader = New BinaryReader(memoryStream, System.Text.Encoding.UTF8)
                     memoryStream.Position = 0
                     writer.Write(sr.ReadBytes(memoryStream.Length))
                     writer.Flush()
             End Using
       End Using
      oResponse.BinaryWrite(memoryStream.ToArray())

End Using

 

4 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 19 Apr 2017, 08:34 AM
Hi German,

It looks like this is a system error related to permissions or to limitations of the Windows Zip viewer. See this Microsoft Community thread or this StackOverflow thread (including this unaccepted answer) for example. 

In case playing with the permissions does not help, could you please send us more information - the exact exception and the stack trace, or simple application reproducing it. I am also still not sure whether you are getting the message during the code execution or during subsequent attempt to open the file using Windows.

Regards,
Boby
Telerik by Progress

0
German
Top achievements
Rank 1
answered on 19 Apr 2017, 02:23 PM

Hi Boby, thank you for immediate response to my issues....

I have checked the output and the file Word Document was corrupted....

This is what I am trying to do using Telerik Windows Zip ZipAchive Entry: 

The Word Document was created dynamically in Web Forms Asp.net in Vb, and was formatted

 and save it to System.IO.MemoryStream [ oDocTemplate.Save(memoryStream, oFormat)]

I created a Zip file using ZipArchiveEntry and open the file then try to Binary Read the data in System.IO.MemoryStream and

then Binary Write it to the open file.

I tried to put the file in a Zip folder [ oResponse.BinaryWrite(memoryStream.ToArray()) ]

and push the whole thing through http addheaders....so the user can open it in a browser temporary folder.

I am not sure about the code, where and what I missed. Do you think I am doing it right on my code using Telerik Windows Zip?

Please help...thanks.

0
German
Top achievements
Rank 1
answered on 19 Apr 2017, 05:37 PM

Hi Boby,

I am getting the error message when I try to open the file.

The word document file shows up exactly in the Browser's Temporary folder with the Zip folder and file I created.

Thanks.

 

0
Boby
Telerik team
answered on 24 Apr 2017, 12:21 PM
Hello German,

I think that the problem is that you are using the memoryStream for two things - writing the entry and exporting the docx. You should use two different streams, for example:
using (var memoryStream = new MemoryStream())
{
    using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true, null))
    using (var entry = archive.CreateEntry("test.docx"))
    {
        var stream = entry.Open();
 
        // This simulates your export - oDocTemplate.Save. The idea is that you can copy the docx stream directly in the entry's stream.
        using (FileStream fileStream = new FileStream(@"d:\temp\test.docx", FileMode.Open))
        {
            fileStream.CopyTo(stream);
        }
    }
 
    // This is just for debugging purposes - the zip file is already in the memoryStream.
    //using (FileStream output = new FileStream(@"d:\temp\zip.zip", FileMode.Create))
    //{
    //    memoryStream.Position = 0;
    //    memoryStream.CopyTo(output);
    //}
}


If this doesn't solve the problem, please send us sample application that reproduces the problem, so that we can dig deeper.

Regards,
Boby
Telerik by Progress

Tags
ZipLibrary
Asked by
German
Top achievements
Rank 1
Answers by
Boby
Telerik team
German
Top achievements
Rank 1
Share this question
or