Format to allow ASP Classic <% %> tags inside of a FileSystem object Writeline command - asp-classic

I have a script I am building that creates ASP Classic pages from form input.
I am using the file object to create the asp file. It is working as intended, however I am slightly perplexed how to embed ASP CLASSIC code into the string. The open tag works like this:
fname.WriteLine"<% DIM GENERIC_VAR"
This displays in the file properly, however the use of the close tag doesn't seem to want to work. Even my IDE is indicating a formatting issue. Usually in the instances I need to replace a " (double quote) a ' (single quote) will work, but in this case I get compile errors (Unterminated string constant) or the file doesn't create the line as expected. I know about doubling up "" but so far haven't had any luck. Thanks.
Side note as an example, I just need to be able to print this into the line of the file:
fname.WriteLine"%>"

openasp = "<"
openasp = openasp & "% "
closeasp = " %"
closeasp = closeasp & ">"
Set up the ASP tags like above.
Then Wrap them in line as needed for example:
fname.WriteLine openasp & "DIM VAR_NAME" & closeasp

Related

Image control is not displaying image using mappath property vb.net

I am trying to set an image dynamically. Image control is not displaying the image but it is displaying the alternate text. I'm using VS 2008 with vb.net. I used information from this post to construct the code. During debug the file path is correct.
vb Code:
Dim strImgURL As String = "C:\fldr1\fldr2\Projfldr3\images\emps\" 'local dev path where visual studio solution is located
Dim filename As String = System.IO.Path.Combine(strImgURL, Session("EmpID").ToString() & ".jpg")
If (File.Exists(filename)) Then
imgEmp.ImageUrl = filename
Else
filename = System.IO.Path.Combine(strImgURL, "99999.jpg")
imgEmp.ImageUrl = filename
End If
aspx:
<asp:image id="imgEmp" Runat="server" Height="100px" Width="77px"
AlternateText="Employee's picture" />
Is it wrong to use "IO.Path.combine" when passing to ImageUrl?
UPDATE: Still working on this with lessons learned from this thread and this thread using MapPath property to set the path to images. The mappath should theoretically detect file path to the images folder in whatever environment I'm testing.
The only way I can get an image to show is if I hard-code filename value like below (removing any mappath code and system.io.path.combine() code entirely). btw I am taking a Int session variable, Session("EmpID") converting to string to create the filename property (e.g. 12345) - none of the conversion methods I'm using are effective:
1. Session("EmpID").ToString() (or Convert.ToString(Session("EmpID"))
2. strEmpID =Session("EmpID").ToString() + ".jpg"
strImgURL = "http://server/images/" + strEmpID + ".jpg"
Based on the link you provided, System.IO.Path.Combine automatically adds forward slashes to the strings. Then try to remove the excess forward slash at the end of strImgURL:
Dim strImgURL As String = "C:\fldr1\fldr2\Projfldr3\images\emps"
Hope this will help. :)

How to find start and end of IF THEN ELSE block in asp classic

I have been tasked to edit some classic asp pages(though I develop in C#). These were created 10 years back but are still in use. One of the file is very big spanning 5159 lines. It has got many nested if then conditions which I am unable to figure out .. which is this if , where it is starting or where next if is like that.
I have tried vs2010 but it also dosen't highlight start/end of if/else, I tried notepad++ also with the same story.
My question to asp developers is that which IDE they use or how they figure out the start of many nested ifs thens?
I like to use UltraEdit Professional Text/HEX Editor which can fold unfold blocks: http://www.ultraedit.com/
Also this could help: http://www.aspindent.com/?indent
Never used it but heared good things about it: http://www.aspdebugger.com/
A code folding feature is very helpful on such problems, but only if code is quite good formatted. But code folding is of no help if the nesting takes place within a line.
All IDE and most text editors have a Match Brace command or something similar. That command is usually best to find the matching brace of a condition in a not well formatted block with nested conditions.
UltraEdit and maybe also other text editors support even customizable strings which are applied to the Match Brace feature. Perhaps this is a help for you on the not well structured ASP code.
UltraEdit has several brace matching features. But for your problem the most helpful would be the commands Go to Matching Brace and Select to Matching Brace which are both in menu Search (traditional menus) respectively Go to brace and Select to brace on Codding tab/menu (ribbon mode/contemporary menus). With caret blinking at beginning of an If the first command moves caret to the matching End If and the second command additionally selects everything from If to End If. The commands can be used also in reverse direction from End If to matching If.
But before the brace matching commands can be used on your ASP files on If and End If, it is necessary to define the string If as opening brace and the string End If as closing brace in the syntax highlighting wordfile for ASP.
To do this open in UltraEdit from ribbon/menu Advanced the Configuration by clicking on Configuration (traditional menus) or Settings (ribbon mode/contemporary menus). Open in configuration tree Editor Display and click on Syntax Highlighting. Select the language respectively wordfile VBScript ASP and click on button Open. Exit the configuration dialog with button Cancel.
In the opened wordfile vbscript.uew search at top for the lines
/Open Brace Strings = "{" "(" "[" "<"
/Close Brace Strings = "}" ")" "]" ">"
and append on first line "If" and on second line "End If".
/Open Brace Strings = "{" "(" "[" "<" "If"
/Close Brace Strings = "}" ")" "]" ">" "End If"
Save the modified wordfile and close it. The modification is immediately active and you can use now the commands Go to Matching Brace and Select to Matching Brace in your ASP files.

formatting numbers as text in excel

Building an excel spreadsheet is a classic asp application. The problem now is that one of the columns is being automatically formatted by excel as a number when it should really be text and so it is removing leading zeros which the boss wants to keep. I have done some web search and you should be able to pre-append an apostrophe to the string forcing excel to display it as text:
If isNumeric(val) Then
response.write "'" & val
Else
response.write val
End If
Great, but excel is now displaying those columns with a leading apostrophe! From the reading that I have done the leading apostrophe should be hidden and only used by excel as formatting, what am I doing wrong?
Thanks.
After a little poking around I found this to work:
Response.Write "=""" & Trim(val) & """"
Displayed correctly and the formatting characters were not displayed, unless of course you click on the cell then the contents is displayed in the header.
If you are creating the Excel by using Microsoft Libraries, instead of creating csv file that Excel reads. Then you can basically specify the column as a Text. By doing so you don't have to add string characters into the cell.
Add a white space character in HTML before the value you want to insert in the Excel cell:
If isNumeric(val) Then
response.write " " & val
Else
response.write val
End If

Restrict user input to characters in IBM System i 00280 code page

We need to restrict user input in a classic ASP web site to the characters allowed by the 00280 code page of IBM System i.
Is there a way to do it in a sane way besides having a (JavaScript|VBScript) function checking every character of an input string against a string of allowed characters?
A basic classic ASP function I thought of:
Function CheckInput(text, replacement)
Dim output : output = ""
Dim haystack : haystack = "abcd.. " ' Insert here the allowed characters.
Dim i : i = 0
For i = 1 To Len(text)
Dim needle : needle = Mid(text, i, 1)
If InStr(haystack, needle) = 0 Then
needle = replacement
End If
output = output & needle
Next
CheckInput = output
End Function
Would - in my function - a RegExp be an overkill?
The short answer to your first question is: No. To your second question: RegEx might not help you here because not all RegEx implementation in browsers will support the characters you need to test and neither does VBScript version of RegEx.
Even using the code approach you are proposing would need some very careful thought. In order to be able to place the set of characters you want to support in as string literal the codepage that you save the ASP file would need to be one that covers all the characters needed or alternatively you would need to use AscW to help you build a string containing those characters.
One slightly simpler approach would be to use Javascript and have the page charset and codepage set to UTF-8. This would allow you to create a string literal containing anyset of characters.
Since it is generally not considered secure to rely on browser validation, you should consider changing your IBM i (formerly OS/400) application interface to accept UCS-2 data, and perform any necessary validation and conversion at the server side.

Why the asp code fail?

HeaderStr = HeaderStr & "<link href="""&HB_ManageFolder&"/Include/ASBox/ASBox.css"" rel=""stylesheet"" type=""text/css"">"&vbcrlf
But if I change &HB_ManageFolder& to & HB_ManageFolder & it will work.
Why?
&H starts a hexadecimal number
I don't really know VBScript (which you are probably using with ASP) but as far as I know, it's quite similar to VBA.
And I know this issue from VBA: if you build strings with "&" and you don't leave blanks in between, VBA won't compile until you put the blanks in.
Probably it's the same issue here.
So, you just always have to use " & " instead of "&" and it will work.

Resources