Our vBulletin migration is complete.
Welcome vBulletin users! All content and user information from the Micro Focus Forums (vBulletin) site has been migrated to this site. READ MORE.

How to save a file expressed in binary in the digest to the disk using WebParseDataBoundEx function.

How to save a file expressed in binary in the digest to the disk using WebParseDataBoundEx function.

Steps:

1) To save a file (like a excel file) expressed as binary format in the digest to the disk, you will need to customize your script to parse in the web response from the server (which is the binary data that represents the excel file) and save that data into a file and rename it with the correct file extension with a valid directory path.

2) To parse the web response and save it to a variable, you can use the function WebParseDataBoundEx (...) to save the output to a variable:

WebParseDataBoundEx(sResult,STRING_COMPLETE,NULL,0,NULL,WEB_FLAG_IGNORE_WHITE_SPACE,WEB_DOC_ALL,nResult);

This function should be placed before the web request that fetches the binary file.

3) As the data is in binary, this data will need to be represented in binary using the bin (...) operator. Like this: bin (sResult)

4) Using this knowledge, you can save the file to disk using disk functions: FOpen,FWrite and FClose. Here is an example where a excel file dummy.xls is saved to the temp folder using the binary format of the sResult :

FOpen (hFile,"C:\\temp\\dummy.xls",OPT_FILE_ACCESS_READWRITE, OPT_FILE_CREATE);
FWrite (hFile,bin(sResult));
FClose (hFile);

Take note that the bin operator that is covering the sResult string. Without this, the sResult string will be gibberish. It is imperative that you add this operator.

5) You are done! 

Here is a script sample that downloads a excel file from an URL and save it to disk:

// ----------------------------------------------------------------------
// Generated 2015/3/17 from 'DownloadExcelFile.spcap'
// by Silk Performer Recorder v16.0.0.6549
// ----------------------------------------------------------------------
// Rule set "ASP.NET ViewState"
// * Rule "Parse and Replace __VIEWSTATE"
// * Rule "Parse and Replace __EVENTVALIDATION"
// ----------------------------------------------------------------------

//@codepage(936)

benchmark SilkPerformerRecorder

use "WebAPI.bdh"

dcluser
user
VUser
transactions
TInit : begin;
TMain : 1;

var

dclrand

dcltrans
transaction TInit
begin
WebSetBrowser(WEB_BROWSER_MSIE11);
WebModifyHttpHeader("Accept-Language", "zh-CN");
//WebSetUserBehavior(WEB_USERBEHAVIOR_FIRST_TIME);
//WebSetDocumentCache(true, WEB_CACHE_CHECK_SESSION);
end TInit;

transaction TMain
var
nResult : number;
sResult : string;
hFile : number;

begin
WebParseDataBoundEx(sResult,STRING_COMPLETE,NULL,0,NULL,WEB_FLAG_IGNORE_WHITE_SPACE,WEB_DOC_ALL,nResult);
WebUrl("http://berkeleycollege.edu/browser_check/samples/excel.xls", 4.98);

writedata ("sResult : " + bin(sResult));
write ("nResult : " + nResult);

//WebSetBrowser(WEB_BROWSER_MSIE10);
//WebModifyHttpHeader("Accept-Language", NULL, WEB_MODIFY_OPT_Remove);

//save the binary as excel
FOpen (hFile,"C:\\temp\\dummy.xls",OPT_FILE_ACCESS_READWRITE, OPT_FILE_CREATE);
FWrite (hFile,bin(sResult));
FClose (hFile);

end TMain;

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2015-05-14 03:25
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.