bHyZDV8VA0CY7nRKSxXree3EjqtT3j ********************************************************************** Tip of the Day! by Srinivasa Sivakumar <% Function ShowDCOMApplications(vComputerName) Dim objLocator, objService, objWEBMCol, objWEBM Set objLocator = CreateObject("WbemScripting.SWbemLocator") 'Establish a connection to WMI If isEmpty(vServerName) = True then Set objService = objLocator.ConnectServer Else Set objService = objLocator.ConnectServer(vComputerName) End If 'Get the Webm Service object Set objWEBMCol = objService.InstancesOf("Win32_DCOMApplication") Response.write "

DCOM Applications:


" 'Clean up Set objLocator = Nothing Set objService = Nothing Set objWEBMCol = Nothing Set objWEBM = Nothing End Function Call ShowDCOMApplications("your computer")%> 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 In ASP Tool Tips are employed to show usefull information when mouse moves over a specific region in webpage. The way tool tips are implemented is different in netscape and InternetExplorer. The following piece of HTML shows a method of implementing tool tip thats compatible with both Ineternet Explorer and Netscape Navigator. Tool Tip Compatibility

Tool Tip Demonstration

It should be noted in the above example that 'alt' attribute is used to display tooltip in Netscape Navigator and 'title' is used to display tooltip in Internet Explorer. By using both we get the tooltip in IE as well as netscape navigator ********************************************************************** Tip of the Day! by Sandra Gopikrishna Here is the code that can be employed for finding out the number of records returned by the query irrespective of the cursor being employed. It should be noted that forward only cursor returns record count as -1 always. <% 'constructing the recordset and firing the query goes here .............. 'to hold the record count dim count rs.movefirst 'rs stands for recordset do until (rs.eof and rs.bof) count = count + 1 rs.movenext loop %> ********************************************************************** ********************************************************************** Tip of the Day! by Sandra Gopikrishna If a webpage doesnt involve any server side activities it is advisable to save the page with the .html extension. When a web page is named with .asp then the page is sent to the asp.dll which compiles the script in the code. When content of the HTML page with .asp extension is passed in to asp.dll it takes some time to check the content for any scripts. So it's better to go for HTML pages rather than for asp pages when there is no server side functionality. ********************************************************************** Tip of the Day! by Sandra Gopikrishna ASP allows us to mix server script along with client script. By employing this method we can use inbuilt functions provided by server script(VBScript) inside client script(Javascript).The following example demonstrates the above method mixscript.asp ------------- Testing ASP Reset Functionality

When the above page is opened in a browser the text box is populated with the value "string" which is returned by MID function of VBScript ********************************************************************** Tip of the Day! by Sandra Gopikrishna ASP code as every know is a mixture of HTML and script. The HTML content in asp page can be presented in the following two ways 1. constructing html string and then employing response.write to display the string as shown below <% dim x x = "

Say Hello

" response.write x %> 2. Intermixing html and asp as shown <% dim x %>

Say Hello

It is advisable to follow first method as it involves only one write statement when compared to second method which uses write statements each and every time it encounters html tag ********************************************************************** Tip of the Day! by Srinivasa Sivakumar How to list all Windows Startup Commands information from ASP? <% Function ShowStartupCommand(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_StartupCommand") Response.write "

Windows Startup Commands:


" 'Clean up Set objLocator = Nothing Set objService = Nothing Set objWEBMCol = Nothing Set objWEBM = Nothing End Function Call ShowStartupCommand("your computer")%> 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 Srinivasa Sivakumar How to list all the printers installed in the server from ASP? <% Function ShowPrinters(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_Printer') Response.write '

Printers:


' 'Clean up Set objLocator = Nothing Set objService = Nothing Set objWEBMCol = Nothing Set objWEBM = Nothing End Function Call ShowPrinters('your computer')%> 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 Here is an interesting method for finding out the version of the Http protocol that the webserver is employing. <% response.write "Web server is using the following protocol " & _ request.servervariables("SERVER_PROTOCOL") %> ********************************************************************** ********************************************************************** Tip of the Day! by Ian Vink Many functions can't take null strings and values. To ensure that a variable is not null, and if it is, to make it = "" you can use this small example function: Function NotNull(vOrig) If(IsNull(vOrig)) then NotNull = "" else NotNull = vOrig end if End Function ********************************************************************** ********************************************************************** Tip of the Day! by Ian Vink If you wish to turn the background color of your resulting XSL transformation to white when the user presses the PRINT button, use this small code sample. (IE only) ********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP, the Error object provides a property by name 'Source' by which the object that generated the error can be determined. This property is generally made use of in applications that employ different objects. The following piece of code demonstrates the method of using the Source property of err object. <% on error resume next set conn = server.createobject("adodb.connection") conn.open "dsn_name", "uid", "pwd" sql = "select * from asp" set rs = conn.execute(sql) if err.number <> 0 then Response.write err.source end if %> ********************************************************************** ********************************************************************** Tip of the Day! by Srinivasa Sivakumar How to create a new Windows process from ASP. Function CreateANewProcess(vComputerName, vCommandLine) Dim objLocator, objService, objWEBMCol, vNewProcessID, t 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.Get("Win32_Process") 'Check the object variable If objWEBMCol Is Nothing Then Response.write "Unable get the handle of the Processes" Else 'Create the new process if objWEBMCol.Create(vCommandLine, NULL, vNewProcessID) = 0 then Response.write "The New Process ID is: " & vNewProcessID Else Response.write "There was an error while creating the new Process" End if End if 'Clean up Set objLocator = Nothing Set objService = Nothing Set objWEBMCol = Nothing Set vNewProcessID = 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 Ian Vink When you are in a for-each loop in XSL, to see if you're at the top mode node in the selection, use the context() method. do some code here ********************************************************************** Tip of the Day! by Sandra Gopikrishna Sometimes we come across a situation where the data gets added into database after opening up the recordset object. In order to update the recordset object with newly added data at the database, we can use the 'Requery' method of the recordset object of ADO. The Requery method is equivalent to closing the recordset object and then opening it again. The following piece of code demonstrates the method of using the 'Requery' Method. requerydb.asp ------------- <% set conn = server.createobject("adodb.connection") conn.open "asp", "scott" ,"tiger" set rs = server.createobject("adodb.recordset") sql = "select * from emp" rs.open sql,conn,3 Response.write " The initial values fetched from database are
" for i = 0 to rs.recordcount - 1 response.write rs(0) & "
" rs.movenext next ' Add some new values to database ********************************************************************** Tip of the Day! by S Bashkar The following VB.NET tip demonstrates a method of populating the ListBox Control employing the ADODataReader Class. It should be noted that we need to import the classes System.Data and System.Data.ADO before we use the ADODataReader Class. poplist.aspx ------------------ Imports System.Data Imports System.Data.ADO Dim cono As New ADOConnection() conn.ConnectionString = strConnect Try conn.Open() Dim cd As New ADOCommand(“select * from authors”, conn) Dim dr As ADODataReader cd.Execute(dr) While dr.Read() listbox1.Items.Add(dr(“au_lname”)) End While 'catch anmy resulting exception Catch err As Exception MsgBox(err.ToString) Finally 'Close the function before exiting the routine If conn.State = DBObjectState.Open Then conn.Close() End Try ********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP Filtering of particular elements of an array can be done on the fly by employing the 'Filter' Function provided with VBScript.The Following example demonstrates the method of using 'Filter' Function: <% origarray = Array("alpha", "beta", "gama", "theta", "cosine") 'Display the original array Response.write " The contents of original array is :
" for i = 0 to ubound(origarray) Response.write origarray(i) & "
" next ' Filter the array such that it contains items having alphabet e filteredarr = Filter(origarray, "e", True, vbTextCompare) 'Display the filtered items Response.write "
The Items having the letter 'e' are
" for i = 0 to ubound(filteredarr) response.write filteredarr(i) & "
" next %> ********************************************************************** Tip of the Day! by Ian Vink Change your ASP page into an XML data provider. To have an ASP page become an XML data provider, add these two lines of code to the top of your ASP page: Response.ContentType = "text/xml" Response.Write "" Then continue with your ASP page to response.write the XML data. You can then call this page by XML enabled objects, like XML islands. ********************************************************************** Tip of the Day! by Sandra Gopikrishna In SQLServer the SQL State of error object can be determined by employing 'SQLState' Property of the error object. The following piece of code demonstrates the method of determining the sql state of the error object. <% on error resume next set conn = server.createobject("adodb.connection") conn.open "dsn_name", "uid", "pwd" sql = "select * from asp" set rs = conn.execute(sql) if err.number <> 0 then Response.write err.sqlstate end if %> ********************************************************************** Tip of the Day! by Ian Vink Convert a recordset into Url encoded text When you are converting a recordset to XML some of the data may be passed as an URL later on in your code, use the SERVER.URLENCODE method to convert the recordset data into URL encoded text. do until rs.eof for each field in rs.fields response.write "<" & ucase(field.name) & ">" response.write server.URLEncode(field.value) response.write "" next rs.movenext loop ********************************************************************** Tip of the Day! by S Bashkar It is possible to use the Intrinsic objects such as Server Application and session in an webservice by importing the System.web.services.webservice. The following ASP.NET Snippet demonstrates how to achieve the above concept in an ASP.NET Page using VB.NET Language imports System.web.services public class classname : inherits webservices classname in the above snippet refers to the class name of the webservice. ********************************************************************** Tip of the Day! by Rahul Khandare So,use this with Connection object : <% strSQL = "Insert into TableName (field1, field2) " & _ " Values ( value1, value2)" objConnection.Execute strSQL %> or do the same thing with the Command object's Execute method. <% Set objCommand = Server.CreateObject("ADODB.Command") Set objCommand.ActiveConnection = objConnection objCommand.CommandText = strSQ objCommand.CommandType = adCMDText objCommand.Execute %> instead of doing this: <% Recordset.AddNew Recordset("FieldName") = new value Recordset.Update %> To choose between the Connection or the Command object, use this rule. If the same or similar query is being executed many times with minor changes such as parameter changes then use the Command object since it allows the database engine to cache your SQL execution plan and improve performance. If the query is only being executed once, use the Connection object's Execute statement. ********************************************************************** Tip of the Day! by Sandra Gopikrishna Instead of hard coding the Data Source Name, userid and password of database in each ASP Page, They can be conveniently stored as application variables in application_Onstart event of global.asa file as follows global.asa sub Application_OnStart() application("dsn_name") = "mydsn" application("user_id") = "myid" application("password") = "mypassword" end sub ********************************************************************** Tip of the Day! by Steven Hayes If you are calling CDO folder objects from ASP remember to work around the 'Rootfolder' property as it does not work in ASP. This holds true if you are calling a CDO COM object from ASP. A simple little work around to get a handle on the required folder object is to hardcode the folder ID using GetFolder(FolderID) and make it a child of an InfoStore object that set to 'objInfoStores.Item(PUBLIC_FOLDER_INDEX)'. ********************************************************************** Tip of the Day! by Ian Vink When a new user comes to your site, a Session object is created for that user for the duration of their visit. You can record both objects and data in their session variables. These follow the user around your site and can be accessed by you ASP scripts. In this example each user that comes to the site will have a "Sales.Order" COM object created for them and an AGE variable created for them. Each can then be accessed as needed in your ASP application. <% Set Session("SaleTool") = Server.CreateObject("Sales.Order") Session("AGE") = 45 %> ********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP at the end of each page the database objects such as recordsets, connections e.t.c are set to null. In ASP.NET it is not required to follow the before said procedure as ASP.NET does garbage collection itself. ********************************************************************** ********************************************************************** Tip of the Day! by S Bashkar WebServices of the ASP.NET are stateless in the normal state. ASP.NET Constructs a new instance for each incoming call and destroys it at the end of the call.The WebService Base class of ASP.NET application supports two types of states one is Application State and the other is session state. In the Application level all the users accessing the webservice can manipulate it where as in the session level only the user of that session alone can manipulate the webservice. ********************************************************************** ********************************************************************** Tip of the Day! by Srinivasa Sivakumar Sending email with attachments from ASP.NET is made extremely easy by using the MailAttachment class available at System.Web.Util namespace. Here is a sample, <% @Import Namespace="System.Web.Util" %> ********************************************************************** Tip of the Day! by Srinivasa Sivakumar The .NET framework provides the memory management for all the .NET applications. The memory is reclaimed by the process called Garbage collection. We can manually trigger the garbage collection by calling the “Collect” method of the System.GC class. System.Gc.Collect() ********************************************************************** Tip of the Day! by S Bashkar ADO.NET offers two managed providers for connecting to the data store, one for connecting to SQL server datastore directly and other for accessing other databases through OLEDB layer. Using SQL Server will provide easy database access as there is no need to pass through the intermediate OLEDB data layer that happens in the case of other databases.The two Connection objects with which to connect to data stores are: The SQLConnection for connecting to Microsoft SQL Server and the ADOConnection for connecting via an OLE DB provider. The following code snippet demonstrates the method of using the SQLConnection and ADOConnection objects in an ASP.NET Page. 'SQL Server database String sConnectionString = "server=localhost;uid=sa;pwd=;database=pubs"; SQLConnection con = new SQLConnection(sConnectionString); con.Open(); 'Other Databases String sConnectionString = "Provider= SQLOLEDB.1; Data Source=localhost; uid=sa; pwd=; Initial Catalog=pubs"; ADOConnection con = new ADOConnection(sConnectionString); con.Open(); ********************************************************************** Tip of the Day! by S. Vaidyaraman When a request is made to a server it returns a status line containing a three-digit code and a short description of the status of the response. This codes can be classified into 5 different types: 1## - Informational. These codes mainly contains additional information. 2## - Success. These codes are returned when the request has been successfully executed by the server.Eg: Status Code 200 indicated the successful retrieval of web page. 3## - Redirection. These codes indicate that additional action must be taken before the request can be satisfied. Eg: Status code 301 can indicates that a page has been moved and the browser may be redirected to the new page. 4## - Client Error. These codes are returned when the server cannot satify or fulfill the browser's request.Eg: Staus Code 404 indicates that the URL is not found 5## - Server Error. These codes indicate a server side problem. Eg: Status Code 503 indicates that the server has too many requests to process ********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP+ Use Page.IsValid method to determine if the form validated correctly or not. After the form is validated correctly we can proceed with other process otherwise we can abort the process. page.isValid can be implemented in asp+ page employing VB as follows if Page.IsValid then response.write ("validation succesfull..") End IF ********************************************************************** Tip of the Day! by Sandra Gopikrishna In ASP+ employing VB if we forget to put the response.write statements in "()" we will receive the following error. Compilation Error Message BC30800 - No Parenthesis ********************************************************************** Today on ASPToday, at http://www.asptoday.com/content/articles/20010710.asp: File uploading using the .NET Remoting service by Gary Wu ******************************************************************* Tip of the Day! By Ian Vink When you need to create complex SQL, create the Joins, Links and Relationships in Microsft Access then switch to SQL view and copy the SQL to your ASP page. It ensures the syntax is correct. ********************************************************************** Tip of the Day! by Ian Vink This example will open and print out a Word Document to the default printer after adding an address to it. These two lines of the example ensure that no message boxes appear on the Word application on the server, as this would stop the application from closing. wApp.printout false wApp.activedocument.close false <% dim wApp set wApp = Server.CreateObject("Word.application") wApp.visible = true wApp.Documents.Open C:\temp\ianvink.com\BlankOrder.doc" wApp.Selection.TypeText "Ian Vink" wApp.Selection.TypeParagraph wApp.Selection.TypeText "Box 7200 Luna" wApp.Selection.TypeParagraph wApp.Selection.TypeText "The Moon, ONT" wApp.Selection.TypeParagraph wApp.Selection.TypeText "N0M 1T0" wApp.Selection.TypeParagraph wApp.printout false wApp.activedocument.close false wApp.quit set wApp=nothing %> ********************************************************************** Tip of the Day! by Ian Vink You can slightly improve the performance of your ASP application by using local scope (defining them inside subroutines and functions). The reason is that local variables are resolved into tables lookups when the page is compiled by the server. This enables faster execution when run. ********************************************************************** Tip of the Day! by S. Vaidyaraman In ASP.NET Page tracing can be enabled by setting the Trace Option of page directive to TRUE. Page-level tracing allows to write debugging statements to the clients page as part of the output.This can be done using the Trace.Write and Trace.Warn methods, passing a category and message for each statement. The following ASP.NET Snippet Demonstrates the method of using Trace. write() and Trace.warn() methods . pagetrace.aspx -------------- <%@ PAGE TRACE = "TRUE" LANGUAGE = "VB" %> <% dim x as string x = "10" Trace.Write("myTrace",x) x = "20" Trace.Warn("mytrace warning",x) %> when the above page is run the content of x is written to the page as part of client output. Note that the content output resulting from Warn method of trace is displayed in red color on the screen. ********************************************************************** Tip of the Day! by Srinivasa Sivakumar 3. Sending emails with ASP.NET Sending email from ASP.NET is extremely easy as like using the newmail object in ASP. The System.Web.Util namespace exposes classes to send email. Here is a sample, <% @Import Namespace="System.Web.Util" %> ********************************************************************** Tip of the Day! by Sandra Gopikrishna Manipulation of Binary files can be done on the fly using Stream object provided with ADO 2.5. The following example demonstrates the method of using stream object for reading a gif file and outputting the content of this file to the screen. The meta tag provided below helps us to access ADO Constants without providing the include file by binding the ado type library. <% 'Create a stream object Dim streamobj Set streamobj = Server.CreateObject("ADODB.Stream") 'Open a GIF file streamobj.Type = adTypeBinary streamobj.Open streamobj.LoadFromFile "test.gif" 'Output the contents of the stream object Response.ContentType = "image/gif" Response.BinaryWrite streamobj.Read 'Clean up.... streamobj.Close Set streamobj = Nothing %> ********************************************************************** Tip of the Day! by Sandra Gopikrishna In order to store visitor preferences the websites normally employ cookies. If the number of preferences to be stored in cookies are large in number and are interrelated, it is better to go for cookie dictionary. Cookie dictionary contains group of cookies. The following example demonstrates the method of creating cookie dictionary in ASP Page <% Response.cookies("visitor")("bodycolor") = "red" Response.cookies("visitor")("frames") = "no" Response.cookies("visitor")("fontcolor") = "yellow" %> The following example demonstrates the method of using cookie dictionary to store the user preferences visiting a website **********************************************************************