Download File From Internet In PowerBuilder
Create Objects n_inetresult.sru
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
$PBExportHeader$n_inetresult.sru Forward Global Type n_inetresult From internetresult End Type End Forward Global Type n_inetresult From internetresult End Type Global n_inetresult n_inetresult Type Prototypes Function Long CreateFile ( & String lpFileName, & ULong dwDesiredAccess, & ULong dwShareMode, & Long lpSecurityAttributes, & ULong dwCreationDisposition, & ULong dwFlagsAndAttributes, & Long hTemplateFile & ) Library "kernel32.dll" Alias For "CreateFileW" Function Boolean CloseHandle ( & Long hObject & ) Library "kernel32.dll" Function Boolean WriteFile ( & Long hFile, & Blob lpBuffer, & ULong nNumberOfBytesToWrite, & Ref ULong lpNumberOfBytesWritten, & ULong lpOverlapped & ) Library "kernel32.dll" Function ULong GetTempPath ( & ULong nBufferLength, & Ref String lpBuffer & ) Library "kernel32.dll" Alias For "GetTempPathW" End Prototypes Type Variables Blob iblob_data // constants for CreateFile API function Constant ULong INVALID_HANDLE_VALUE = -1 Constant ULong GENERIC_READ = 2147483648 Constant ULong GENERIC_WRITE = 1073741824 Constant ULong FILE_ATTRIBUTE_NORMAL = 128 Constant ULong FILE_SHARE_READ = 1 Constant ULong FILE_SHARE_WRITE = 2 Constant ULong CREATE_NEW = 1 Constant ULong CREATE_ALWAYS = 2 Constant ULong OPEN_EXISTING = 3 Constant ULong OPEN_ALWAYS = 4 Constant ULong TRUNCATE_EXISTING = 5 End Variables Forward Prototypes Public Function Integer InternetData (Blob Data) Public Function Integer of_writefile (String as_filename, Blob ablob_data) Public Function String of_gettemppath () End Prototypes Public Function Integer InternetData (Blob Data); // save the data to an instance variable // // Return - 1=Success, -1=Failure // iblob_data = Data Return 1 End Function Public Function Integer of_writefile (String as_filename, Blob ablob_data); ULong lul_file, lul_written Boolean lb_rtn // open file for write lul_file = CreateFile(as_filename, GENERIC_WRITE, & FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0) If lul_file = INVALID_HANDLE_VALUE Then Return -1 End If // write file to disk lb_rtn = WriteFile(lul_file, ablob_data, & Len(ablob_data), lul_written, 0) // close the file CloseHandle(lul_file) Return 1 End Function Public Function String of_gettemppath (); String ls_path Integer li_buflen li_buflen = 260 ls_path = Space(li_buflen) GetTempPath(li_buflen, ls_path) Return ls_path End Function On n_inetresult.Create Call Super::Create TriggerEvent( This, "constructor" ) End On On n_inetresult.Destroy TriggerEvent( This, "destructor" ) Call Super::Destroy End On |
Add Event Dowload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Inet iinet_base n_inetresult ln_irdata Integer li_rc String ls_filename // instantiate internet service objects Parent . GetContextService ( "Internet" , iinet_base ) ln_irdata = Create n_inetresult SetPointer ( HourGlass!) li_rc = iinet_base . GetURL ( "https://pblib.com/wp-content/uploads/2020/11/PMIT.pdf" , ln_irdata ) If li_rc = 1 Then ls_filename = "C:\temp\PMIT.pdf" ln_irdata.of_WriteFile ( ls_filename , ln_irdata . iblob_data ) Else MessageBox ( "Warning" , "GetURL Failed" ) End If |
Find Projects On Github click here
Attachments Objects Inetresult:
Good Luck!
Thanks for sharing. Really appreciate your contribution to spread the magic of Powerbuilder. Keep posting and sharing. Greetings from Indonesia.