Extracting a full file

Hello everybody,

I am trying to download the files after an asynchronous extraction.

From the web interface, the file is downloaded properly and can be opened with 7zip.

With the code, I do something like this with each f in CompletedExtraction.Files :

    var streamResponse = extractionsContext.ExtractedFileOperations.GetReadStream(f);
string strFileName = f.ExtractedFileName;
string contents = string.Empty;
using (var reader = new StreamReader(streamResponse.Stream))
{
contents = reader.ReadToEnd();
}
using (System.IO.StreamWriter outputfile = new StreamWriter(@C:\dev\target\ + strFileName))
{
outputfile.Write(contents);
}

and it appears that 7zip cannot open the file, as it is not an archive. It is not readable by a human either, that being said. There is no problem with the notes file, that is quite readable after being imported that way, only the full file, of type gz, cannot be opened.

Anything I missed ?

Best Answer

  • Christiaan Meihsl
    Answer ✓

    @Hubert CANEVET, can you try this:

    var streamResponse = extractionsContext.ExtractedFileOperations.GetReadStream(f);
    string strFileName = f.ExtractedFileName;
    {
    using (FileStream fileStream = File.Create(@C:\dev\target\ + strFileName))
    streamResponse.Stream.CopyToAsync(fileStream).Wait();
    }

    Caveat: I tested this code in a different context, but I believe it should work.

Answers