********************************************************************** Tip of the Day! by Ian Vink Normally you would create an XML data island with the tags. However, you can use the script tag to create an XML island as well: ********************************************************************** Tip of the Day! by Ian Vink When your XSL sorts your XML, by default it sorts it alphabetically. If you prefer, you can have it sort by date or number format by setting the dt:dt element of the node accordingly in your schema. ********************************************************************** Tip of the Day! by Ian Vink To have the XML document parser wait until the entire XML document is loaded, set the async property of the XML DOM to false. XMLDoc .async = false ********************************************************************** Tip of the Day! by Ian Vink One of the quickest ways to create an XML document is to use the Microsoft added method "LOAD" in the XML DOM. var XMLDoc = Server.CreateObject("MSXML2.DOMDocument") XMLDoc .async = false XMLDoc .load("http://ASPToday/xmlfile.xml") ********************************************************************** Tip of the Day! by Ian Vink When an XML data island reads in an XML file, you can check the ParseError.Reason property of the XML DOC to see if there was a parsing error. Dim xmlDoc Set xmlDoc = MyDataIsle.XMLDocument xmlDoc.resolveExternals=false xmlDoc.async=false If xmlDoc.parseError.Reason <> "" then Msgbox "parseError.Reason = " & xmlDoc.parseError.Reason End If ********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP.NET it is possible to access the HTML Control Attributes or expando properties programmatically. The following ASP.NET code demonstrates the above concept by taking the example of text control and accessing its attribute programmatically on the server side. expando.aspx ------------
********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP.NET we can find the virtual root mapping of the current application by employing the 'ApplicationPath' Property of the Request Object. The follwing ASP.NET snippet demonstrate the above concept: virtpath.aspx ------------- ********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP.NET if a control is made a server control then its value can be accessed and manipulated on the server side. In order to make a control a server side you specify its RUNAT attribute to "server". The following example demonstrates the server control concept by taking a text box server control and by accessing its value when you load the page. serverctl.aspx --------------
********************************************************************** Tip of the Day! by Sandra Gopikrishna The following ASP.NET snippet demonstrates a method of dynamically finding a textbox at runtime and retrieving its value. The text box can be found out at run time by employing the FindControl method of page object. findcntl.aspx ------------- <%@ Page Language="C#" %> <% String ctlname = "mytxt"; TextBox createdtxbx = (TextBox) Page.FindControl(ctlname); String value = createdtxbx.Text; Response.Write("The value of text box is " + value); %>
The above example finds the text box mytxt at run time and displays this value on the page. ********************************************************************** Tip of the Day! by Srinivasa Sivakumar To list all Windows Shortcut File information from ASP: Function ShowShortcutFile(vComputerName) Dim objLocator, objService, objWEBMCol, objWEBM Set objLocator = CreateObject("WbemScripting.SWbemLocator") 'Establish a connection to WMI If isEmpty(vComputerName) = True then Set objService = objLocator.ConnectServer Else Set objService = objLocator.ConnectServer(vComputerName) End If 'Get the Webm Service object Set objWEBMCol = objService.InstancesOf("Win32_ShortcutFile") Response.write "

Windows Shortcut File information:


    " 'Enumerate For Each objWEBM in objWEBMCol Response.write "
  • Name: " & objWEBM.Name & _ ",
    Description: " & objWEBM.Description & _ ",
    Caption: " & objWEBM.Caption & _ ",
    Access Mask: " & objWEBM.AccessMask & _ ",
    Compressed: " & objWEBM.Compressed & _ ",
    Compression Method: " & objWEBM.CompressionMethod & _ ",
    Encrypted: " & objWEBM.Encrypted & _ ",
    Encryption Method: " & objWEBM.EncryptionMethod & _ ",
    Drive: " & objWEBM.Drive & _ ",
    File Name: " & objWEBM.FileName & _ ",
    Extension: " & objWEBM.Extension & _ ",
    Path: " & objWEBM.Path & _ ",
    DOS File Name: " & objWEBM.EightDotThreeFileName & _ ",
    File Size: " & objWEBM.FileSize & _ ",
    File Type: " & objWEBM.FileType & _ ",
    File In Use Count: " & objWEBM.InUseCount & _ ",
    File Link Target: " & objWEBM.Target & _ ",
    Version: " & objWEBM.Version & "
  • " Next Response.write "
" 'Clean up Set objLocator = Nothing Set objService = Nothing Set objWEBMCol = Nothing Set objWEBM = Nothing End Function Note: Pass the computer name as the parameter. An empty string will work when you are accessing the local computer. ********************************************************************** Tip of the Day! by Sandra Gopikrishna The snippet demonstrates how to go about finding whether a given file is readonly or not: <% set fso = server.createobject("scripting.FileSystemObject") set thisfile = fso.GetFile(filename) if thisfile.Attributes and 1 then Response.write " The File Is Readonly " else Response.write " The File Is Not Readonly " end if set thisfile = nothing set fso = nothing %> ********************************************************************** Tip of the Day! by Michael Krakovskiy Is 1 > 2? Well, in ASP sometimes it can be. Consider the following code <% foo="1" bar=2 if foo > bar then response.write (foo&">"&bar) else response.write (foo&"<"&bar) end if %> Well, variable foo is a string and bar is an integer. In order to be able to use ">" operator correctly you need to cast them both as integers like this: <% foo="1" bar=2 if cint(foo) > cint(bar) then response.write (foo&">"&bar) else response.write (foo&"<"&bar) end if %> This is especially important when you are getting an integer value from a form (which will default to a string) and are trying to compare it to some integer. ********************************************************************** Tip of the Day! by Michael Krakovskiy Coding forms may prove very frustrating. The biggest problem is making calls to variables in form or querystring collections without any typos. For instance if you have and you try to get it as request.form("helo"), the typo that you made will not cause an error, but return an empty string. Besides, if you have a lot of variables, this will call for a lot of copying and pasting. I solved all of these problems with a simple piece of code that actually writes code for me. Lets say you have a form in a file called foo.asp
and the following code in a file called bar.asp: <% for each strName in request.form %> dim str<%=strName%> : str<%=strName%> = request.form("<%=strName%>")
<% next %> the output of bar.asp after the form is submitted will be : dim strfoo : strfoo = request.form("foo") dim strbar : strbar = request.form("bar") -- the asp code that is necessary to loadd foo and bar values into ASP variables. ********************************************************************** Tip of the Day! by Ian Vink To add script to your XSL, you must enclose the entire script in a CDATA tag so that the script inside will not be parsed by the XML parser. Notice how the SCRIPT tag is outside the actual script, which is in the CDATA tag. ********************************************************************** Tip of the Day! by Ian Vink After doing an XSLT transformation on an XML document, to view the resulting XML, simply "copy all" (CTRL+A, CTRL+C) the page as it views in IE then switch to Frontpage and press paste (CTRL+V). In the HTML view then will be the resulting HTML generated code. ********************************************************************** Tip of the Day! by Ian Vink In your XSL stylesheets, you can include Cascading Style Sheets to separate style from structure. Include a link to the CSS in the HEAD of the XSL Some code to display isd the PATH element is not blank ********************************************************************** Tip of the Day! by Michael Krakovskiy Nested conditional statements can get very hard to debug. The easiest way to track them is to add a comment to the end of the end statement which would tell the coder how the statement started. for instance: if strBlah="hello" then else 'if strBlah="hello" then end if 'if strBlah="hello" then This way, in order to find the beginning of the statement the coder needs to search for "if strBlah="hello" then" higher up in the code. It is very important not to forget to change the comments if the condition changes. An alternative is to enumerate if statements with unique integers or strings. ********************************************************************** Tip of the Day! by João Vilaça Sometimes, during debugging, it is useful to have a file where we can see what we get from a form. One way of doing this is as follows: <% Option Explicit %> <% dim fld response.write "Result from: " & request.serverVariables ("HTTP_REFERER") response.write "" response.write "" for each fld in request.form response.write "" next 'fld response.write "
FieldValue
" & fld & "" & request.form(fld) & "
" %> ********************************************************************** Tip of the Day! by Michael Krakovskiy To comment a large chunk of HTML text or asp code you can put it inside a conditional that always evaluates to false: <%if false then 'start comment%> ********************************************************************** Tip of the Day! by Michael Krakovskiy There is a little known danger in looping through recordsets. Consider the following code: 'rsFoo is a recordset on error resume next do while not rsFoo.eof response.write rsFoo("bar") rsFoo.movenext loop What would happen if rsFoo did not initialize correctly (or even was not declared)? The answer is -- there will be an infinite loop, and the page will never stop loading. If you will try to catch the error like this: do while not rsFoo.eof and err.number=0 response.write rsFoo("bar") rsFoo.movenext loop the loop will not break because the error will happen on the statement "rsFoo.eof" and the interpreter will immediately go to the next line. To successfully quit the loop you need to do this: err.clear 'make sure that code above does not trigger loop exit do while not rsFoo.eof if err.number<>0 then exit do end if response.write rsFoo("bar") rsFoo.movenext loop ********************************************************************** Tip of the Day! by Michael Krakovskiy It is possible to use GET and POST form methods at the same time. For instance: in form.asp:
hello.asp : <% dim strFooValue, strBarValue strFooValue=request.querystring("foo") strBarValue=request.form("bar") %> Note, that although the submission method of the form is "POST", the GET variables are also being propagated. This is useful in case you want to preserve some querystring flag that is used on the other parts of the site while submitting a POST form. **********************************************************************