Question

I know there are other topics about that, but nothing worked.

In my webpage, I allow to download some configuration files

I'm using this code:

public ActionResult DownloadConfigurationFiles()
{
    var stream = this.HttpContext.GetSessionObj<byte[]>((int)WebVariable.ConfigurationFilesStream);
    if (stream == null)
    {
        return HttpNotFound();
    }

    this.HttpContext.ClearSessionObj((int)WebVariable.ConfigurationFilesStream);
    return File(stream, "application/x-7z-compressed", "ConfigurationFiles.7z"); // octet-stream
}

It works perfectly the first time, when when I try again few second later, I download the 7z file, but when I want to open it, I have this error:

enter image description here

When I step into the code, it's always the same as the first try when it succeeded... so I don't know why my archive is corrupt..? Is there any way to validate that the archive we build is a valid 7z file?

Was it helpful?

Solution

http://msdn.microsoft.com/en-us/magazine/cc301755.aspx

Seems like arrays - reference type, you should copy bytes into stream for example, only then remove your session object.

public ActionResult DownloadConfigurationFiles()
{
    var bytes = this.HttpContext.GetSessionObj<byte[]>(idx_here);

    if (bytes != null) // check existance
    {
         var target = new MemoryStream(bytes); // <-- don't use USING!

         this.HttpContext.ClearSessionObj(idx_here);

         return File(target, mime, file_name);
    }

    return HttpNotFound();
}

think it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top