Gen 8.6 OpenTextFile File_Dialog doesn't open file explorer in ASP.NET
search cancel

Gen 8.6 OpenTextFile File_Dialog doesn't open file explorer in ASP.NET

book

Article ID: 269288

calendar_today

Updated On:

Products

Gen Gen - Workstation Toolset

Issue/Introduction

Attempting to create a Gen 8.6 ASP.NET web-based client which presents a file explorer that shows only Excel files from the user's PC. Then, after the user selects a file, it inserts data into a database table for loading onto the browser window.

Attempted this using the Gen OpenTextFile function for Excel files. Attempted with OpenTextFile option File_Dialog and when testing the generated GUI Windows C application, the file explorer displayed. However, when testing an ASP.NET client the file explorer was not displayed.

Resolution

Tested code for OpenTextFile options File_Dialog and Filename for GUI/C and ASP.NET applications. For GUI/C both options were successful. However, under ASP.NET only the Filename option was successful. The File_Dialog option did not open any file explorer for file selection which matches the reported behavior.

When the OpenTextFile option File_Dialog is used under ASP.NET, the Gen runtime will attempt to call C# function OpenFileDialog. However, from web research, it appears that OpenFileDialog will only display the results on the server where IIS is running and not on the client machine where the browser is being used. For example, the problem is logged here:  Microsoft > Open file selection dialog from ASP.NET application on IIS

Also tried to create a C# External Action Block (EAB) using the same OpenFileDialog function and although tests were successful under Visual Studio, received an error at runtime "Object reference not set to an instance of an object". Working in Visual Studio and not working under ASP.NET using IIS is also what was reported above.

In summary,

  • Using OpenTextFile with File_Dialog will not be feasible under ASP.NET and the documentation for OpenTextFile Function has been improved to state that (i.e. "Note: For ASP.NET applications, OpenTextFile only works with the Filename option, not the File_Dialog option. This is because File_Dialog uses the C# class OpenFileDialog which only displays the file selection dialog box on the server where IIS is running and not on the client machine where the browser is being used.")

  • On the above Microsoft page, it is suggested to copy the file to the IIS server and then process it from there. Along these same lines, a workaround is use of the ASP.NET control FileUpload i.e. select a file using control FileUpload, save it to the IIS server and then use OpenTextFile to process the file on the server via its full path. See attached Test model and README file.

Additional Information

Currently when running Toolset Consistency Check (CC) usage of OpenTextFile in an action diagram statement will show messages:
WARNING : ICCOO03W Function cannot be executed in ASP.NET applications.
WARNING : ICCOO05W Function is not multi-thread safe in C# or Java.

Relevant documentation pages:
Consistency Check Messages - ICCOO03W
Consistency Check Messages - ICCOO05W

ICCOO05W is in line with the comments about OpenTextFile not being thread safe for .NET under the Unsupported ASP.NET Web Client Features page - see "Unsupported File-Related Functions
However, ICCOO03W should not include an OpenTextFile check and will be removed from the Toolset CC in the near future. The ICCOO03W documentation page has already been updated to remove the reference to OpenTextFile.

Attachments

1689822709128__FileUpload_with_OpenTextFile_README.docx get_app
1689822675152__opentnet.ief.zip get_app