Thursday, September 18, 2008

VBScript/ASP URLEncode function with charset (urlencode to utf-8 or other character encoding)

VBScript/ASP URLEncode function with charset (urlencode to utf-8 or other character encoding)


Function URLEncode(ByVal Data, CharSet)
'Create a ByteArray object
Dim ByteArray: Set ByteArray = CreateObject("ScriptUtils.ByteArray")
If Len(CharSet)>0 Then ByteArray.CharSet = CharSet

ByteArray.String = Data

If ByteArray.Length > 0 Then
Dim I, C, Out

For I = 1 To ByteArray.Length
'For each byte of the encoded data
C = ByteArray(I)
If C = 32 Then 'convert space to +
Out = Out + "+"
ElseIf (C <>126) Or (c>56 And c<=64) Then Out = Out + "%" + Hex(C) Else Out = Out + Chr(c) End If Next URLEncode = Out End If End Function


Hi have this code that produces error ActiveX Component cannot create object ScriptUtils.ByteArray

Set ByteArray = CreateObject("ScriptUtils.ByteArray")

when I run vb script I get the above error. Anyone knows why?

Have you registered ScptUtl.DLL ?

In a console window type regsvr32 /?

Have a look here:
http://www.motobit.com/help/scptutl/pa75.htm
and here:
http://www.motobit.com/help/scptutl/pa33.htm

======================================================

ScriptUtilities and HugeASP file upload installation

First installation, upgrade, full version over evaluation, installation without setup.
First installation of ScriptUtilities and HugeASP file upload
1. Download evaluation or full version from your download location.
2. Run scptutl.exe on the computer you want to install the software
3. Go to Start -> Programs -> PSTRUH Software -> samples
copy the .asp samples to web folder with execute rights and try to run the samples.
Installation of full version over evaluation or Installation of newer versions
1. Download evaluation or full version from your download location.
2. Stop W3SVC rervice on computer you want to install ScriptUtilities
Note: W3SVC processes (dllhost.exe) usually locks aspform.dll and scptutl.dll libraries
3. Run scptutl.exe on the computer you want to install the software
The installation is completed in seconds
4. Start W3SVC service
Advanced: Custom installation without setup or without w3svc restart, redistribution.
Redistribution, installation without setup
ScriptUtilities and Huge-ASP upload package (scptutl.exe) contains samples, help and two main DLLs - ASPForm.DLL containing Huge-ASP file upload (ASPForm, FormFields, FormField and FormParser classes) and ScptUtl.DLL containing ScriptUtilities (Kernel, ByteArray, Process, Thread, Advapi, INIFile, ZLib and LogFile classes).
You will only need ASPForm.DLL to work with upload classes and ScptUtl.DLL for other classes.
You can copy the DLLs to server-side to a folder with read and execute right for IUSR_... and other web user accounts and then register them by regsvr32.

You can get these files from setup package by 'ScptUtl.exe /T:c:\temp /C' command.
Problem with locked ASPForm.DLL / ScptUtl.DLL
W3SVC processes (dllhost.exe) usually locks aspform.dll and scptutl.dll libraries. Sometimes you need to install newer versions of this DLL without restarting of your web or with minimal server stop-time.
I such case you can
- rename old aspform.dll and scptutl.dll dlls (for example to *.bak)
- copy new version of the DLL and register the new versions using regsvr32:
regsvr32 ASPForm.DLL
regsvr32 ScptUtl.DLL
- quick restart websites using the DLLs or better restart required dllhosts.exe (which uses the DLLs) in COM+ management console.

http://www.motobit.com/help/scptutl/pa75.htm

No comments: