Excel File Corrupted When Uploading to Server from Stream

0 votes
asked Mar 25, 2015 by November06 (190 points)

I am building an excel file and saving it to a MemoryStream with ClosedXML.

From the MemoryStream, the file is either sent as an attachment through email or uploaded to the server using Rebex PutFile.

I am not using Rebex for the email and there's no problem with it. The file is sent well. The problem lies with the file saved in the server. Yes, it is being uploaded but once I try to open it, there is the error... "…file format or extension not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

I tried uploading an excel file that is saved from my local PC. There's no problem with it after FTP. Only those excel files from MemoryStream have this problem. When I tried using the same code to FTP a CSV file from MemoryStream, the file works well.

I only have this problem with Excel files from MemoryStream.

What can I do to prevent the file from being corrupted?

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Mar 25, 2015 by November06 (190 points)
selected Mar 25, 2015 by Tomas Knopp
Best answer

No need to answer this, guys, I got the answer now.

I failed to add this line...

client.Seek(0, SeekOrigin.Begin);

This solved the problem.

commented Mar 25, 2015 by Tomas Knopp (58,890 points)
Thanks for letting us know that you solved the problem in your program and that you are able to upload the files correctly now.
commented Apr 19, 2018 by MotionS (100 points)
Thanks a lot! works for me.