Forum  Commercial Foru...  Commercial Foru...  FileDownloadGateway
Previous Previous
 
Next Next
New Post 5/10/2011 6:17 AM
Resolved
  olszik
50 posts
No Ranking


FileDownloadGateway  

Hi guys,

I got FileDownloadGateway class from (http://www.visualwebgui.com/Developers/Community/Projects/ApplicationVEM/Forums/tabid/179/forumid/29/threadid/22480/scope/posts/threadpage/2/Default.aspx) and tried to use it in my application (see code below). IIt works ok if I use xls file, but using xlsx file I got recovery error when I open the file.

Code:

            FileDownloadGateway myDownload = new FileDownloadGateway();

            myDownload.Filename = "ExportData.xlsx";

            myDownload.DownloadAsAttachment = true;

            myDownload.SetContentType(DownloadContentType.MicrosoftExcel2007);

 

            System.IO.FileStream fstream;

            fstream = System.IO.File.OpenRead("d:\\Template.xlsx");

            byte[] f = new byte[fstream.Length + 1];

            fstream.Read(f, 0, (int)fstream.Length);

            fstream.Close();

            System.IO.MemoryStream ms = new System.IO.MemoryStream(f);

            ms.Position = 0;

            myDownload.StartStreamDownload(this, ms);

 

where MicrosoftExcel2007 is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"


I'm doing something wrong?

Thanks and best regards,

Oliver

 
New Post 5/10/2011 3:06 PM
  palli
14416 posts
1st Level Poster




Re: FileDownloadGateway  

Hi Oliver,

Welcome to Visual WebGui

The problem seems to be in the code for loading the byte array, and the fact that you make it a "+ 1", so it will be 1 byte too long. This obviously doesn't affect Excel .xls documents, but Excel seems to be a little pickier with .xlsx.

You can download the application I used for testing here. In that application's FileDownloadGateway I also set the Content-Length for stream download which is not necessary, but was put there during testing according to this article here. I also prefer to use objResponse.Flush() instead of objResponse.End().

FYI, there is also a more simple version of this download control that you can find on the Gateway article here, in the Code Samples section. This other download control is built upon the other one and they both work approximately the same. Both of them have undesirable sideeffects as they both add the download control to a container, which in some cases is undesirable. There also is a Link.Download implemented into the framework directly, which you may want to look at too. More information here.

Hope this helps,

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 5/11/2011 5:54 AM
  olszik
50 posts
No Ranking


Re: FileDownloadGateway  

Hi Palli,

Thank you for the sample.

The “+1” was only for testing, to see if something is changing and I forgot it in sample

Your FileDownloadGateway solved my problems, is working fine. (The other solutions are not working for memorystream)

Best regards,

Oliver

 
New Post 5/11/2011 1:43 PM
  palli
14416 posts
1st Level Poster




Re: FileDownloadGateway  

Hi Oliver,

You are welcome. Glad it worked for you and thanks for confirming.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  FileDownloadGateway
.NET HTML5 Web, Cloud and Mobile application delivery | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2012 Visual WebGui®       Visual WebGui weblog on ASP.NET Gizmox Blog Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS