Web Connection
Using wwDotnetBridge to call: HttpResponse.TransmitFile
Gravatar is a globally recognized avatar based on your email address. Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Greg Dohm
  All
  Jan 24, 2021 @ 11:36pm

Hi Rick,

I'm trying to use the .NET HttpResponse.TransmitFile method but am unable to instantiate the HttpResponse class.

LPARAMETERS lcFilename
LOCAL loBridge as wwDotNetBridge
loBridge = GetwwDotnetBridge()

loBridge.LoadAssembly("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.dll")
**the assembly seems to load correctly.

loNetResponse = loBridge.CreateInstance("System.Web.HttpResponse")
**Error:  loNetResponse = null
**"Constructor on type 'System.Web.HttpResponse' not found."

loNetResponse.HttpResponse.TransmitFile(lcFilename)
RETURN

Was wondering what I'm missing? Thanks

Greg


https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse.transmitfile?view=netframework-4.0
.NET definition
*!*	HttpResponse Class
*!*	Definition
*!*	Namespace:
*!*	System.Web
*!*	Assembly:
*!*	System.Web.dll
*!*	HttpResponse.TransmitFile MethodDefinition
Gravatar is a globally recognized avatar based on your email address. re: Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Rick Strahl
  Greg Dohm
  Jan 25, 2021 @ 11:29am

That won't work. HttpResponse is an ASP.NET intrinsic object, and it doesn't work without an HTTPContext and request that goes with it. It certainly won't magically connect to the running ASP.NET response and send output back to the client.

From the docs: This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

What are you doing exactly? And what are you trying to do? Is this inside of Web Connection or somewhere else?

In Web Connection you don't need this anyway as you can use Response.TransmitFile():

Which does pretty much exactly what I think you're trying to do?

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Greg Dohm
  Greg Dohm
  Jan 25, 2021 @ 12:16pm

I am trying to get over the 16 MB string limit with transmitting a file in webconnection.

It has to do with the spreadsheet control I'm using for spreadsheets larger than 16 MB. I realize this affects FUNCTION's URLDecode, GetURLEncodedKey, wwPageResponse.write and wwPageResponse.render which I was going to handle using a couple of other .net functions and wwFileStream whenever the size is > 16 MB.

So far everything everything seemed to be working right except that I am unable to get the webconnection transmitfile() function to work with files larger than 16MB in the wwPageResponse.render() using these other .net classes for handling larger strings.

I am hoping there's a way to use the System.Web.HttpResponse.transmitfile functionality directly?

Your comment seems to suggest it can't be done: "HttpResponse is an ASP.NET intrinsic object, and it doesn't work without an HTTPContext and request that goes with it. It certainly won't magically connect to the running ASP.NET response and send output back to the client."

I suppose an alternative may be to redirect the client to an ASP.net page for download...any suggestions are much appreciated? Thanks

Gravatar is a globally recognized avatar based on your email address. re: Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Rick Strahl
  Greg Dohm
  Jan 25, 2021 @ 01:09pm

Did you not read my response before you clicked Reply?

Just use Response.TransmitFile() - it can send files larger than 16mb. Please look at the docs for that function that I linked - it has all the info you need.

This Web Connection call internally calls HttpResponse.TransmitFile - in the proper request context.

If it's not working there's something else going like you have IIS request limits set that don't allow serving large files perhaps.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Greg Dohm
  Rick Strahl
  Jan 25, 2021 @ 09:50pm

Hi Rick,

Sorry about missing your link earlier to the TransmitFile documentation. I just thought it was some bolded text but good to know it can handle files larger than 16 MB.

I seem to be having some issues with the TransmitFile function. It works fine for .xls files although gives it the webpage name as the filename. For example, test.xls gets downloaded as mypage.xls

The problem for me is that I am using .xlsx files only. And when I set the content type for .xlsx files, and try to download test.xlsx the downloaded file is written out as mypage.wcsx?

Details as follows:

lcOutputFile = Config.cHtmlPagePath +  "temp\Test.xlsx"

**CASE 1:

Response.TransmitFile(lcOutputFile,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

**downloads and renames downloaded file as 'webpage.wcsx'? -->ultimately can't open due to incorrect file extension as should be .xlsx per original filename and the mime type.


**case 2 (as a side observation):

Response.TransmitFile(lcOutputFile,"application/vnd.ms-excel")	

**downloads and remames downloaded file as 'webpage.xls' -->ultimately can't open due to incorrect file extension as should be .xlsx per original filename. I understand this mime type specified is .xls so the behaviour is correct that way -- but the original file is an .xlsx file. (this works correctly if the original file has an .xls extension)

I looked at the transmitfile() function and it all seems to look okay to me in terms of values. You mentioned TransmitFile is handled by IIS...is there a setting I should have in IIS for this to work. I am currently using webconnection 6.21 for this project although have 7.14

I just thought a bit more about this...and tried zipping the .xlsx file and then downloading the .zip file and that works fine. Ultimately that solution works for me. I just have to try your zipfile utility now to do that in code.

Thanks,

Greg

Gravatar is a globally recognized avatar based on your email address. re: Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Mike McDonald
  Greg Dohm
  Jan 26, 2021 @ 07:39am

Greg -

It works fine for .xls files although gives it the webpage name as the filename. For example, test.xls gets downloaded as mypage.xls

Try using DownloadFile() and set the lcFileDisplayName parameter as the filename to save. This uses TransmitFile() but sets an additional header so the browser will prompt the user to save the downloaded content to a file.

Mike McDonald
Software Design of Kentucky

Gravatar is a globally recognized avatar based on your email address. re: Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Greg Dohm
  Mike McDonald
  Jan 26, 2021 @ 12:05pm

Thanks Mike, downloadfile does the trick, and works perfectly.

Gravatar is a globally recognized avatar based on your email address. re: Using wwDotnetBridge to call: HttpResponse.TransmitFile
  Rick Strahl
  Greg Dohm
  Jan 27, 2021 @ 03:00pm

Also added the filename parameter to TransmitFile() for the next version - Response.DownloadFile() seems to get missed by most people - this question has come up more than a few times. With that change TransmitFile can do the same thing as DownloadFile() if the display file name is provided. If not it'll load in the browser.

Response.TransmitFile()

Will be in the next update.

+++ Rick ---

© 1996-2024