1. Tracy Lamb
  2. PowerBuilder
  3. Saturday, 3 July 2021 18:42 PM UTC

Hi all,

I'm having trouble viewing documents in my browser if the document name has any spaces.  I'm trying to replace spaces with %20 for the browser... but when I run my code, it replaces space with %2520 ... here's an example:


Here's the code:

// If the file exists, view it in a browser window
//First replace spaces with %20
long start_pos=1
string old_str, new_str

old_str = ' '
new_str = '%20'

// Find the first occurrence of old_str.
start_pos = Pos(ls_filename, old_str, start_pos)

// Only enter the loop if you find old_str.
DO WHILE start_pos > 0
// Replace old_str with new_str.
ls_filename = Replace(ls_filename, start_pos, &
Len(old_str), new_str)
// Find the next occurrence of old_str.
start_pos = Pos(ls_filename, old_str, &

if lb_FileExists then
GetContextService("Internet", iinet_base)
MessageBox("View Document","Could not locate file: ~r~n" + ls_filename)
end if

Any suggestions on how to fix this is greatly appreciated.




Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Saturday, 3 July 2021 23:50 PM UTC
  2. PowerBuilder
  3. # Permalink


The extra 25 you are getting is because somehow the %20 that you used to replace the spaces. The hyperlinkToUrl function replaces the % with a value of 25, which is the hexadecimal value for the % in an ascii table.

You could consider the CoderObject to call the "UrlEncode" function, but .... that one encodes also all of the "/", so that won't work either.

I've done some testing and this would work:
1. Don't replace the spaces and ...
2. Enclose the url in "double quotes".

In other words have single quotes as the outer quotes and enclose the inner string value with double quotes.

Something like this: 
ls_url = '"file:///C:/temp2/folder with spaces/New Text Document.txt"'

string ls_url
inet linet_base

ls_url = '"file:///C:/temp2/folder with spaces/New Text Document.txt"'

GetContextService("Internet", linet_base)



  1. Tracy Lamb
  2. Sunday, 4 July 2021 03:43 AM UTC
no worries there... I create the ii_net_base object at the top of the code, and destroy it at the end. But I will rename variable to li_net_base so it's not confused with an instance variable. Thanks again!

  1. Helpful
  1. Miguel Leeuwe
  2. Sunday, 4 July 2021 08:26 AM UTC
(Just a formality, but if you call it "li_net_base", other programmers might think it's an integer because of the "li_".

I'd call it something like "linet_base".)

  1. Helpful
  1. Chris Pollach @Appeon
  2. Sunday, 4 July 2021 12:50 PM UTC
FWIW: In my framework's naming standard, I would use "lo_inet". The "o" being for "object" class. Food for thought.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 5 July 2021 20:55 PM UTC
  2. PowerBuilder
  3. # 1

Hi Tracy;

  FYI: In the future, you can try my "fn_html_symbolic_replace" global function from my framework to make sure that things like spaces, special characters, etc are properly escaped. This function is designed to clean up any ANSI characters > decimal(127) and replace them with their HTML symbolic names.

  For example:

quotation mark         "  --> "           "      --> "
ampersand               &  --> &          &       --> &
less-than sign           &#60;  --> <          &lt;           --> <
greater-than sign      &#62;  --> >          &gt;          --> >

  The framework is free and you can just extract this one GF from the STD_FC_Base.pbl for your own use as the framework is open source. http://chrispollach.blogspot.com/2021/01/2020r2.html

Download: http://sourceforge.net/projects/stdfndclass/files/FrameWork/Integrated

Regards ... Chris


  1. Miguel Leeuwe
  2. Tuesday, 6 July 2021 06:35 AM UTC
Hi Chris,

While your function can be useful, it won't solve the problem Tracy was having with HyperLinkToUrl().

  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 6 July 2021 17:28 PM UTC
That could be. She would have to try it. I have many other HTML & URL replacement and URL encoding routines. These are from the DPB era but still relevant today. Just an FYI.
  1. Helpful
There are no comments made yet.
Tracy Lamb Accepted Answer Pending Moderation
  1. Sunday, 4 July 2021 03:38 AM UTC
  2. PowerBuilder
  3. # 2

Thank you for taking time to research, test and reply! I changed my code a little... took out the code to replace the space with %20 and added this:

ls_filename = '"' + ls_filename + '"'

In front of:
GetContextService("Internet", iinet_base)

That's Quote-DoubleQuote-Quote + ls_filename + Quote-DoubleQuote-Quote.  

Works like a charm!


  1. Miguel Leeuwe
  2. Sunday, 4 July 2021 08:23 AM UTC
  1. Helpful
There are no comments made yet.
  • Page :
  • 1

There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.