various shenanigans.

JQuery Sharepoint Document Library for most Recent File(s).

I have an email-enabled document library where reports in PDF format are delivered daily.
I need to display the most recent reports embedded on a Web Part page.
The filenames are structured as name_datestamptimestamp.pdf
Different reports are sent here so I have to discern a part of the filename (eg. LAN Utilization, WAN Utilization)

<script type="text/javascript" src="/jquery-1.8.3.min.js"></script><script type="text/javascript">// <![CDATA[
//alert("So Far So Good");
$(document).ready(function() {
// alert("Document is Ready");
 var soapEnv =
 "<?xml version="1.0" encoding="utf-8"?>  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
<soap:Body>  
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">  
 <listName>CMReports</listName>  
<viewFields>  
<ViewFields> 
 <FieldRef Name='LinkFilenameNoMenu' /> 
 </ViewFields> 
 </viewFields> 
 <query> 
 <Query> 
 <Where> 
 <Contains> 
 <FieldRef Name='FileLeafRef' /> 
 <Value Type='File'>PARTOFFILENAME</Value> 
 </Contains> 
 </Where> 
 <OrderBy> 
 <FieldRef Name='Modified' Ascending='FALSE' /> 
 </OrderBy> 
 </Query> 
 </query> 
 <rowLimit>1</rowLimit> 
 </GetListItems> 
 </soap:Body> 
 </soap:Envelope>";
// alert(soapEnv);
$.ajax({
 url: "/_vti_bin/lists.asmx",
 type: "POST",
 dataType: "xml",
 data: soapEnv,
 complete: processResult,
 contentType: "text/xml; charset="utf-8""
 });
});
 function processResult(xData, Status) 
 { 
 // alert(xData.responseXML.xml);
 $(xData.responseXML).find("z\:row").each(function() {
 // alert($(this).attr("ows_LinkFilenameNoMenu"));
 var ObjHTML = "<embed width='940' height='1024' src='SUBSITE/DOCUMENTLIBRARY" + $(this).attr("ows_LinkFilenameNoMenu") + "#navpanes=0' type='application/pdf'></embed>";
 // $("#PDF").append(xData.responseXML.xml);
 // alert(ObjHTML);
 $("#SPDF").append(ObjHTML);
 });
 }
// ]]></script>
<div id="SPDF" />

I saved this snippet in an HTML file and call it from a Content Editor Web Part elsewhere.

Close Bitnami banner
Bitnami