Uploading XML file in WebUI

Problem: you want to upload XML file in CRM WebIU.

Solution: follow below steps for the solution.

1. In your BSP page layout add BSP tag <thtmlb:fileUpload like so:

<thtmlb:fileUpload id         = "fileUpload"
                   onUpload   = "FileUpload"
                   uploadText = "Upload file" />
<thtmlb:fileUpload id         = "fileUpload"
                   onUpload   = "FileUpload"
                   uploadText = "Upload file" />

2. In the controller of your BSP page add event called FileUpload.

3. In the body of the newly created event add below code.

METHOD eh_onfileupload.
  DATA:
    lv_file_length TYPE i,
    lv_file_content TYPE string,
    lo_file_upload TYPE REF TO cl_thtmlb_fileupload,
    lo_converter TYPE REF TO cl_abap_conv_in_ce.
 
  lo_file_upload ?= htmlb_event_ex.
  lo_converter = cl_abap_conv_in_ce=>create( input = lo_file_upload->file_content ).
  lo_converter->read(
    IMPORTING
      data = lv_file_content
      len = lv_file_length
  ).
ENDMETHOD.
METHOD eh_onfileupload.
  DATA:
    lv_file_length TYPE i,
    lv_file_content TYPE string,
    lo_file_upload TYPE REF TO cl_thtmlb_fileupload,
    lo_converter TYPE REF TO cl_abap_conv_in_ce.

  lo_file_upload ?= htmlb_event_ex.
  lo_converter = cl_abap_conv_in_ce=>create( input = lo_file_upload->file_content ).
  lo_converter->read(
    IMPORTING
      data = lv_file_content
      len = lv_file_length
  ).
ENDMETHOD.

 The file’s contents will be uploaded to the lv_file_content variable.

Komentowanie jest zakończone.