Archive for June, 2009

 

ASP File_Get_Contents and File_Put_Contents

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.

 
 
 
 

» Recent Comments

  • Diego: When I've said that "is ...
  • Diego: @ Dan I mainly use...
  • Marcus: Can you make a bookmarks...

» Meta