function readFile()
{
var strToday = new Date();
var strFileName = strToday.getFullYear() + "" + pad((strToday.getMonth()+1)) + "" + pad(strToday.getDate());
//alert(strFileName);
jQuery.get('/myserver/IS/mn/ErrorLogs/DailyLog_'+strFileName+'.log', function(data) {
displayFile(data);
//process text file line by line
});
}
Above we simply get the .log file from the location in SharePoint and then use the function displayFile to process the contents of the file that has been returned.
Below is the full code for the page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>IS Monitoring Status Messages</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
ul
{
margin-left:15px;
}
li.completed
{
list-style-image: url('green_small.png');
font-family:verdana,arial,helvetica,sans-serif;
font-size:8pt;
}
li.error
{
list-style-image: url('red_small.png');
font-family:verdana,arial,helvetica,sans-serif;
font-size:8pt;
}
</style>
<script type="text/javascript" src="/myserver/IS/mn/Files%20To%20Share/jquery-1.10.2.js"></script>
<script type="text/javascript">
readFile();
// function to read from a text file held in SharePoint instead of SharePoint list data
function readFile()
{
var strToday = new Date();
var strFileName = strToday.getFullYear() + "" + pad((strToday.getMonth()+1)) + "" + pad(strToday.getDate());
//alert(strFileName);
jQuery.get('/myserver/IS/mn/ErrorLogs/DailyLog_'+strFileName+'.log', function(data) {
displayFile(data);
//process text file line by line
//$('#div').html(data.replace('n','<br />'));
//$('#StatusMessagesTest').html(data.replace('\n','<br />'));
});
}
function pad(d)
{
return (d < 10) ? '0' + d.toString() : d.toString();
}
function displayFile(strData)
{
//alert(strData);
var statusMessagesArray = strData.split('\n');
var strOutput;
strOutput = "<ul class='statusMessage'>";
statusMessagesArray = statusMessagesArray.reverse();
if (statusMessagesArray.length > 1)
{
for (var i = 1; i < (statusMessagesArray.length); i++)
{
//if ($("statusMessagesArray[i]:contains('Completed')"))
if (statusMessagesArray[i].toLowerCase().indexOf('completed') > 0)
{
strOutput = strOutput + "<li class='completed'>";
strOutput = strOutput + statusMessagesArray[i];
strOutput = strOutput + "</li>";
}
else
{
strOutput = strOutput + "<li class='error'>";
strOutput = strOutput + statusMessagesArray[i];
strOutput = strOutput + "</a></li>";
}
}
}
else
{
if (statusMessagesArray.length == 1)
{
if (statusMessagesArray[0].toLowerCase().indexOf('completed') > 0)
{
strOutput = strOutput + "<li class='completed'>";
strOutput = strOutput + statusMessagesArray[0];
strOutput = strOutput + "</li>";
}
else
{
strOutput = strOutput + "<li class='error'>";
strOutput = strOutput + statusMessagesArray[0];
strOutput = strOutput + "</a></li>";
}
}
}
strOutput = strOutput + "</ul>";
document.getElementById("StatusMessages").innerHTML = strOutput;
}
// End of area to read from a text file held in SharePoint instead of SharePoint list data
</script>
</head>
<BODY>
<div id="StatusMessages" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px">
</div>
</BODY></html>
No comments:
Post a Comment