We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

MemoryStream Problem

Hi all,
 
i have some problems with the memorystream.
 
1) the program opens a Iworkbook
2) i fill this workbook/sheets
3) i send this workbook to the browser
 
workbook.SaveAs(sfile, Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2007);

this works fine...
 
But:
Save the workbook to the memory stream

    MemoryStream ms = new MemoryStream();
    workbook.SaveAs(ms);
and for testing back to file:
 
    FileStream file = new FileStream(@"c:\test.xlsx", FileMode.Create, System.IO.FileAccess.Write);
    byte[] bytes = new byte[ms.Length];
    ms.Read(bytes, 0, (int)ms.Length);
    file.Write(bytes, 0, bytes.Length);
    file.Close();
    ms.Close();

doesnt work. The filesize is exactly like the org file. But i cant open it.
 
But:
if i use this function:

    workbook.SaveAs(@"C:\FromSaveAs.xlsx");
 
it works.
 
 
The point is - i want to save the file into a blob column of my database. My method of saving files/byte into my database works perfect on other projects/files. I think there is problem with the memorystream!?

Can someone help me?

Thanks
Markus

 
 
 
 
 
 
 
 
 
 
    

3 Replies

MM Manikandan M Syncfusion Team July 22, 2013 04:21 AM UTC

Hi Markus,

 

Thanks for using Syncfusion products.

 

We are able to reproduce the reported issue “XlsIO Saved file does not open in MS Excel” from our side. We suspect that this could be an issue and send to the development team for further analysis. We request you to create a new incident to further follow up on this issue.

 

Direct-Trac Link: Login

 

Please let us know if you need any clarifications.

 

Thanks,

Manikandan M.

 



CT Christos Tatitzikidis February 25, 2015 02:21 PM UTC

Any luck with this?

Having the exact same problem!


DB Dilli Babu Nandha Gopal Syncfusion Team February 26, 2015 08:33 AM UTC

Hi Christos,

Thank you for Syncfusion products.

The memory issue reported earlier was an usage issue. This issue can be resolved by resetting the memory stream position to zero before copying the memory stream to file stream. Please follow the below code snippet  to resolve the issue.

Code Snippets:

            MemoryStream ms = new MemoryStream();

            workbook.SaveAs(ms);

            //Resetting Memory stream position.

            ms.Position = 0;

            FileStream file = new FileStream(Server.MapPath("App_data/Output.xlsx"),  FileMode.Create, System.IO.FileAccess.Write);

            byte[] bytes = new byte[ms.Length];

            ms.Read(bytes, 0, (int)ms.Length);

            file.Write(bytes, 0, bytes.Length);

            file.Close();

            ms.Close();

If you are unable to resolve the issue, please share us your entire scenario and the code snippet which will be helpful for us to give you a prompt solution.

Please let us know if you have any concerns.

Regards,

Dilli babu.



Loader.
Live Chat Icon For mobile
Up arrow icon