Working with big files in classic ASP

一世执手 提交于 2020-01-04 06:34:57

问题


I was wondering what's the best practise for serving a generated big file in classic asp.

We have an application with "export to excel" function that produces 10MB files. The excels are created by just calling a .asp page that has the Response.ContentType set to excel and has an HTML table for the data.

This gives as problem that it takes 4 minutes before the user sees the "Save as..." dialog.

My current solution is to call an .asp page that creates the excel on the server with AJAX and lets the page return the URL of the generated document. Then I can use javascript to display the on the original page.

Is this easy to do with classic asp (creating files on server with some kind of stream) while keeping security in mind? (URL should make people be able to guess the location of other files)

How would I go about handling deleted the generated files overtime? They have to be deleted periodicly as the data changes in realtime.

Thanks.

edit: I realized now that creating the file on the server will probably also take 4 minutes...


回答1:


I think you are selecting a complex route, when the solution is simple enough (Though I may be missing some requirements)

If you to generate an excel, just call an asp page that do the following:

Response.clear
Response.AddHeader "content-disposition", "attachment; filename=myexcel.xls"
Response.ContentType = "application/excel"

'//write the content of the file
Response.write "...."

Response.end

This will a start a download process in the browser without needing to generate a extra call, javascript or anything

See this question for more info on the format you will choose to generate the excel.

Edit

Since Thomas update the question and the real problem is that the file take 4 minutes to generate, the solution could be:

  1. Offer the user the send the file by email (if this is a workable solution in you server or hosting).

  2. Generate the file async, and let the user know when the file generation is done (with an ajax call, like SO does when other user have added an answer)

To generate the file on the server

'//You should change for a random name or something that makes sense
FileName = "C:\temp\myexcel.xls" 
FileNumber = FreeFile
Open FileName For Append As #FileNumber

'//generate the content
TheRow = "...."
Print #FileNumber, TheRow




Close #FileNumber

To delete the temp files generated
I use Empty Temp Folders a freeware app that I run daily on the server to take care of temp files generated. (Again, it depends on you server or hosting)

About security
Generate the files using random numbers or GUIds for a light protection. If the data is sensitive, you will need to download the file from a ASP page, but I think that you will be in the same problem again...(waiting 4 minutes to download)




回答2:


How do you plan to generate the Excel? I hope you don't plan to call Excel to do that, as it is unsupported, and generally won't work well.

You should check to see if there are COM components to generate Excel that you can call from Classic ASP. Alternatively, add one ASP.NET page for the purpose. I know for a fact that there are compoonents that can be called from ASP.NET pages to do this. Worse come to worst, there's an Excel exporter component from Infragistics that works with their UltraWebGrid control to export. The grid need not be visible in order to accomplish this, but styles in the grid translate to styles in the spreadsheet. They also allow you to manipulate the spreadsheet programmatically.




回答3:


  1. Read file using FSO.
  2. Set headers for Excel file-type, name according to file read and for download (attachment)
  3. Flush response after headers are set. The client should display "save as" dialogue.
  4. Output FSO to response. Client will download file and see progress bar.


来源:https://stackoverflow.com/questions/925784/working-with-big-files-in-classic-asp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!