/// <summary> /// Initializes a new instance of the <see cref="SharePointMonitor"/> class. /// </summary> /// <param name="monitorConfig">The monitor configuration.</param> public SharePointMonitor(MonitorConfig monitorConfig) : base(monitorConfig) { _library = new SharePointDocumentLibrary(MonitorLocation); _timer = new Timer(new TimerCallback(TimerFire)); // Set up a temporary path and make sure it exists _tempPath = Path.Combine(Path.GetTempPath(), "SharePointMonitor", _library.Name); System.IO.Directory.CreateDirectory(_tempPath); // Initialize the document criteria _query = new SharePointDocumentQuery() { DocumentLimit = 50, CreationDelay = TimeSpan.FromMinutes(2) }; }
/// <summary> /// Populates a SharePointDocumentLibrary object from the contents of SharePoint Document Library with the supplied title on the server. /// </summary> /// <param name="title">The title of the document library with the documents to retrieve.</param> /// <param name="camlQuery">Optional: The XML representing the CAML query you'd like to make of the documents in /// the document library. If not supplied, all documents will be retrieved.</param> /// <returns>A SharePointDocumentLibrary representing the library on the server, or null if the library could not be found, the /// user does not have sufficient permissions to access the library, or library's contents could otherwise not /// be retrieved.</returns> public SharePointDocumentLibrary GetDocumentLibraryByTitle(string title, string camlQuery = CAML_GET_ALL_ITEMS) { try { // Get the library from SharePoint. List list = clientContext.Web.Lists.GetByTitle(title); // Query the library. CamlQuery query = new CamlQuery { ViewXml = camlQuery }; ListItemCollection listItemCollection = list.GetItems(query); Load(clientContext, listItemCollection); // Create a SharePointDocumentLibrary object to populate. SharePointDocumentLibrary documentLibrary = new SharePointDocumentLibrary(list, listItemCollection); return documentLibrary; } catch { return null; } }