ASP File_Get_Contents and File_Put_Contents

June 10th, 2009

As I’ve become more of a PHP developer than an ASP developer, one thing I’ve noticed is that it is 10x easier to read/write text files with PHP. Simple use file_get_contents() and be done. ASP isn’t so nice. But it can be done, so I’m creating those for simplicity here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%
Function File_Get_Contents(strFile)
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFile, 1)
	File_Get_Contents = objFile.ReadAll()
	Set objFile = Nothing
	Set objFSO = Nothing
End Function
 
Function File_Put_Contents(strFile, strContents, blnAppend)
	If blnAppend Then
		intMode = 8
	Else
		intMode = 2
	End If
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFile, intMode, True)
	objFile.Write(strContents)
	Set objFile = Nothing
	Set objFSO = Nothing
End Function
%>

Of course this file_get_contents doesn’t support remote URLs, but it can easily be added.

 

How to access your cell phone voicemail from another phone

September 9th, 2008

This is certainly no new news, but I’m fairly sure many aren’t aware of this simple feature.

Say you left your phone at home and you were expecting a call, but your friend remembered his phone — tough luck, right?  Nope (obviously, or I wouldn’t have made this post).

Here’s what you can do…just pick up any phone and do the following:

  1. Dial your 10-digit wireless number.
  2. Press the * key when you hear your personal greeting.
  3. Enter your personal passcode.
  4. Follow the voice prompts.

Free Web FLV Flash Player

September 3rd, 2008

I’ve used this product multiple times myself, so I thought it would be worthwhile posting it for anyone else looking for a web flash player. The great thing about it is it is very versatile, customizable, and FREE. The JW FLV Media player is suitable to handle FLV, MP4, MP3, AAC, JPG, PNG and GIF formats.

The player, which can play both audio and video, was written by Jeroen Wijering quite a while ago and became very successful. He has since ran with the success and co-founded Longtail Video.

A useful thing to do with this player is to download a copy onto your computer. You can then load FLV’s you’ve downloaded from Youtube, etc. into it and play them offline. This eliminates the need to install a bloated FLV player onto your PC (which likely isn’t a problem for most, but meh.).

To see the video player in action, check out these funny videos.

Classic ASP: More Efficient Database Recordset, GetRows() XoiseRecordset

July 31st, 2008

I’ve created what I believe to be a more efficient recordset object for traversing rows returned from a database query. I implemented all methods/properties that I feel make sense to implement. There’s definite room for improvement, but it’s a good start. My reasoning for creating this is that I like the functionality of using recordsets (via Server.CreateObject("ADODB.Recordset")), but there is a HUGE drawback in that it is horrible on the database. The Server.CreateObject approach makes a database call every time a EOF, BOF, or a traversal method (ie. MoveNext, MovePrevious, etc.) is called. My fix is to use the GetRows() method to return it as a multidimensional array and just implement my own class with the same (or similar) functionality. There is also an advantage to using this Recordset over just plain using the GetRows() method. I went ahead and implemented a way to extract the column names from the query, which allows you to grab the information using the column name, instead of the index of the array (ie. objRS("Column_Name")). You may also access the data using the column index if you prefer. Note that I haven’t implemented support for "SELECT * FROM Tbl…" syntax, so you’ll HAVE to use the index for this. There is one main usage difference to note. Rather than opening the recordset with .Open SQL_String, Connection_Object, you must individually update the .Conn and .SQL properties. I’ll most likely change this if there is enough interest and I create a newer version. If I do that, I’ll most likely provide cache support. Download: XoiseRecordset.zip (1.29KB) Usage:

<!-- #Include File = "XoiseRecordset.inc" -->
<%
' Create database connection object
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open = &quot;Connection String Here&quot;
 
' Create my recordset object
' Was: Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set objRS = New XoiseRecordset
 
' Set property data
objRS.Conn = objConn
objRS.SQL = &quot;SELECT Col1, Col2, 3+3 AS Col3 FROM Tbl;&quot;
 
' Iterate through the data
' Note: I DID implement paging, if you want to use that!
While Not objRS.EOF
	strCol1 = objRS(&quot;Col1&quot;)
	strCol2 = objRS(&quot;Col2&quot;)
	strCol3 = objRS.Row(2) ' Index starts from 0
	objRS.MoveNext()
Wend
 
' Destroy recordset object
' No need for .Close!
Set objRS = Nothing
 
'Destroy database connection
objConn.Close()
Set objConn = Nothing
%>

Retrieve Data:

  • objRS("Column_Name")
  • objRS.Item("ColumnName")
  • objRS.Row(0)

Implemented Methods/Properties:

  • Conn
  • SQL
  • EOF()
  • BOF()
  • MoveNext()
  • MoveFirst()
  • MoveFirst()
  • MoveLast()
  • Move()
  • GetRows()
  • RecordCount()
  • PageCount()
  • PageSize()
  • AbsolutePage()
  • AbsolutePosition()