**********************************************************************
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 Michael Krakovskiy
You can use the colon character ':' to make your ASP code more
readable.
':' allows to put two or more statements on the same line.
This is especially useful in variable declarations:
dim strBlah : strBlah='hello' 'this is an example variable declaration
Declaring a variable and assigning it a value on the same line has an
additional benefit of reminding you to delete dim statement in case you
decide to get rid of the variable.
**********************************************************************
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 %>
"
%>
**********************************************************************
Tip of the Day!
by Ian Vink
In XSL, to conditionally display an XML element, use a TEXT attribute
of the XSL:IF command.
Some code to display isd the PATH element is not blank
**********************************************************************
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
Notice how the SCRIPT tag is outside the actual script, which is in the
CDATA tag.
**********************************************************************
Tip of the Day!
by Ian Vink
If you need to quickly check the size of a folder on your web server,
you can use this code:
<%
Set fso = server.CreateObject("Scripting.FileSystemObject")
if fso.GetFolder("C:\inetpub\wwwroot\user\fred").Size > SomeLimit then
response.write "Your folder is too large"
end if
%>
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
The following short ASP snippet demonstrates a method of retrieving
files in the desktop of the machine hosting the asp file.
<%
set fso = server.createobject("scripting.FileSystemObject")
dsktopfoldername = fso.buildpath(fso.GetSpecialFolder(0), "Desktop")
set desktopfolder = fso.GetFolder(desktopfoldername)
set desktopfiles = desktopfolder.GetFiles
'desktopfiles holds all the files available in the desktop folder of
the
'Host Machine
%>
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
The following short asp snippet enables us to find out whether a
parameter
attribute is set or not:
<%
...
if(param.attributes and adparamnullable) then
'do the necessary action
end if
.....
%>
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
Using ASP it is possible to find out the age of a given file by
employing
the following short snippet using FileSystemObject.
<%
set fso = server.createobject("scripting.FileSystemObject")
set thisfile = fso.GetFile("c:\myfile.txt")
'ensure that myfile.txt is available in c:\ of the machine
dtcreated = thisfile.DateCreated
Response.write "The given file is " & Int(now() - dtCreated) & " days
old"
' note that the above mentioned snippet gives the age of the file in
days
%>
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
Using Databinding feature in ASP.NET we can bind the Datagrid control
to XML File just like binding to a dataset. Also it should be noted that
the controls can be binded to COM+ Components directly. The following
ASP.NET Tip demonstrates a method of binding the datagrid control to an
xml file.
myxml.xml
---------------
Joe24ProgrammarJohn28Systems Analyst
bindxml.aspx
------------------
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.IO" %>
In this example the datagrid control in the file 'bindxml.aspx' is
databinded to the xml file 'myxml.xml'
**********************************************************************
Tip of the Day!
by S Hari
CREATE PROCEDURE xp_cdosendmail(
@Addr VARCHAR(255),
@Msg VARCHAR(8000),
@Subj VARCHAR(255),
@From VARCHAR(255) = 'defaultemail@domain.com') AS
DECLARE @CDO INT, @result INT, @Out INT
--Create CDONTS.NewMail object
EXECUTE @result = sp_OACreate 'CDONTS.NewMail', @CDO OUT
IF @result <> 0 PRINT 'CDONTS.NewMail'
--Call Send method of the object
EXECUTE @result = sp_OAMethod @CDO, 'Send', NULL, @From, @Addr, @Subj,
@Msg,
0
IF @result <> 0 PRINT 'Send'
--Destroy CDO
EXECUTE @result = sp_OADestroy @CDO
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
The following piece of code demonstrates a method of connecting to an
Access database from an ASP.NET page. It employs the following ADO.NET
objects for data access:
1.DataSet
2.ADOConnection
3.ADODataSetCommand
The final output is bound to a DataGrid control of ASP.NET and
displayed on the page
accessdb.aspx
-------------
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
The following ASP.NET Tip demonstrates a method of retrieving values
from a database
and displaying these values as XML content in the client's browser by
employing
server control.
dispxml.aspx
------------------
<%@ Page ContentType='text/xml' %>
<%@ Import Namespace='System.Data' %>
<%@ Import Namespace='System.Data.SQL' %>
<%@ Import Namespace='System.Xml' %>
**********************************************************************
Tip of the Day!
by Ian Vink
To write the Euro character to a browser, use this code:
Response.Write "€"
This will work for any Unicode character as well.
**********************************************************************
Tip of the Day!
by Ian Vink
When checking to see if a user have clicked YES on a msgbox, check to
see if the message box is equal to vbYes. The same applies for vbNo.
DeleteMessage = "Delete?"
if msgbox (DeleteMessage, vbyesno) = vbYes Then
frmSets.Submit()
End If
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
The following piece of code demonstrates a method of counting the total
number of bytes sent by the client in the request header and displays
the
data sent by the client using the Binary write method of the response
object
<%
total_bytes = Request.TotalBytes
Response.Write "The Total Number of Bytes sent by the client in the
request header is " & total_bytes
client_data = Request.BinaryRead(total_bytes)
Response.BinaryWrite (client_data)
%>
**********************************************************************
Tip of the Day!
by Sandra Gopikrishna
Reading the content from a text file can be done instantaneously by
employing streamreader and File objects of the namespace "System.IO". The
Following Piece of code demonstrates the method of reading the content
of a text file in ASP.NET.
readtext.aspx
-------------
<%@ Import Namespace="System.IO" %>
<%
Response.write("Reading from the text file in ASP.NET ")
'create a stream reader object
Dim streamreaderobj As StreamReader
'declare a variable for holding the content read from the file
Dim filecont As String
'Open an existing text file and assign it to streamreader object
streamreaderobj = File.OpenText( "c:\myfile.txt" )
'Read the content of the file line by line employing streamreaderobj
'Note that when filecont gets a value emptystring ("") it indicates
end of file
Do
filecont = streamreaderobj.ReadLine()
Response.Write( filecont & " " )
Loop Until filecont = ""
'close the streamreader object after the reading operation
streamreaderobj.Close
Response.write(" Done with reading the content from the file in
ASP.NET")
%>
**********************************************************************
Tip of the Day!
by Ian Vink
In your XSL, to loop through a node of XML data, use the for-each
command and the select attribute to determine which node to use. This
example will output the all PRODUCTNAME elements of the PRODUCT node.
**********************************************************************