Sunday, March 22, 2009

Classic ASP: dump text file contents into array

The code below is reading text file and putting its lines into array.
After the code is executed, each item of the array will be one
line of the text file.


<%

Function ReadTextFile(strFilePath)

 Dim objFSO, objFile, strAllFile

 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

 Set objFile = objFSO.OpenTextFile(strFilePath)

 strAllFile = ""

 If Not(objFile.AtEndOfStream) Then

  strAllFile = objFile.ReadAll

 End If

 objFile.Close

 Set objFile = Nothing

 Set objFSO = Nothing

 

 strAllFile = Replace(strAllFile, Chr(13)&Chr(10), Chr(13))

 strAllFile = Replace(strAllFile, Chr(10)&Chr(13), Chr(13))

 ReadTextFile = Split(strAllFile, Chr(13))

End Function



'usage

Const FILE_NAME="myfile.txt"

Dim arrLines, x, curLine

Response.Write("reading file: " & FILE_NAME & "...<br />")

arrLines = ReadTextFile(Server.MapPath(FILE_NAME))

Response.Write("amount of lines: " & (UBound(arrLines)+1) & "<br />")

Response.Write("file contents:<hr />")

For x=0 To UBound(arrLines)

 curLine = arrLines(x)

 Response.Write("Line #" & (x+1) & " " & Server.HTMLEncode(curLine) & "<br />")

Next

Response.Write("<hr />")

%>



Source: http://forums.aspfree.com/

Tuesday, March 10, 2009

Loading an XML file with Javascript.

Should fill the data from the XML file into the span tag on the HTML document.

<script type="text/javascript">
function parseXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDocVal = "/xmlfile.xml";
xmlDoc.load(xmlDocVal);
document.getElementById("divtarget").innerHTML=
xmlDoc.getElementsByTagName("xmlnodesource")[0]
.childNodes[0].nodeValue;

XML File
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xmlnodesource>Data</xmlnodesource>

HTML
<span id="divtarget"></span>

Basic ASP XML Output

ASP XML Output

<%
response.contentType="text/xml"
response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.write("<note>mooage</note>")
%>

Tuesday, March 3, 2009

Including a file in ASP

I always forget the exact statement for this for some reason, ill probably remember now ;)

<!--#include file="wisdom.inc"-->

http://www.w3schools.com/asp/asp_incfiles.asp