/// <summary> /// Gets metadata about all lists stored on the SharePoint server using "My new connection". Called when the "Get all lists" button is clicked. /// Expects the CreateSharePointConnection method to be run first. /// </summary> private void GetAllLists() { // Get the SharePoint connection from DB SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("MyNewConnection", SiteContext.CurrentSiteID); if (connection == null) { throw new CMSAPIExampleException("SharePoint connection 'My new connection' was not found."); } // Convert SharePointConnectionInfo object into connection data SharePointConnectionData connectionData = connection.ToSharePointConnectionData(); // Get list service implementation ISharePointListService listService = SharePointServices.GetService <ISharePointListService>(connectionData); // Choose SharePoint list type that will be retrieved. // You can use enum or template identifier (listed in http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx) int listType = SharePointListType.ALL; try { // Get all lists of specified type (all list types are retrieved in this case) DataSet results = listService.GetLists(listType); if ((results.Tables.Count == 0) || (results.Tables[0].Rows.Count == 0)) { throw new CMSAPIExampleException("No lists were retrieved from SharePoint server."); } } catch (Exception ex) { throw new CMSAPIExampleException(ex.Message); } }
/// <summary> /// Gets connection data constructed from actual values of the form fields. /// </summary> /// <returns>Connection data</returns> private SharePointConnectionData GetConnectionData() { var connectionData = new SharePointConnectionData() { SharePointConnectionPassword = SharePointConnectionPassword, SharePointConnectionSiteUrl = SharePointConnectionSiteUrl, SharePointConnectionUserName = SharePointConnectionUserName }; return(connectionData); }
/// <summary> /// Gets connection data constructed from actual values of the form fields. /// </summary> /// <returns>Connection data</returns> private SharePointConnectionData GetConnectionData() { var connectionData = new SharePointConnectionData() { SharePointConnectionAuthMode = SharePointConnectionAuthMode, SharePointConnectionDomain = SharePointConnectionDomain, SharePointConnectionPassword = SharePointConnectionPassword, SharePointConnectionSharePointVersion = SharePointConnectionSharePointVersion, SharePointConnectionSiteUrl = SharePointConnectionSiteUrl, SharePointConnectionUserName = SharePointConnectionUserName }; return(connectionData); }
/// <summary> /// Gets specified file from SharePoint server using "My new connection". Called when the "Get file" button is clicked. /// Expects the CreateSharePointConnection method to be run first. /// </summary> private void GetFile() { // Verify the file path has been provided. string filePath = txtFilePath.Text; if (String.IsNullOrWhiteSpace(filePath)) { throw new CMSAPIExampleException("Empty value for File type is not allowed."); } // Get the SharePoint connection from DB SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("MyNewConnection", SiteContext.CurrentSiteID); if (connection == null) { throw new CMSAPIExampleException("SharePoint connection 'My new connection' was not found."); } // Convert SharePointConnectionInfo object into connection data SharePointConnectionData connectionData = connection.ToSharePointConnectionData(); // Get file service implementation ISharePointFileService fileService = SharePointServices.GetService <ISharePointFileService>(connectionData); try { // Get file object ISharePointFile file = fileService.GetFile(filePath); // Get file metadata string extension = file.Extension; // Get stream of file's binary content Stream fileContentStream = file.GetContentStream(); // Get byte array of file's binary content byte[] fileContentBytes = file.GetContentBytes(); } catch (Exception ex) { throw new CMSAPIExampleException(ex.Message); } }
/// <summary> /// Gets all items of specified SharePoint list using "My new connection". Called when the "Get list items" button is clicked. /// Expects the CreateSharePointConnection method to be run first. /// </summary> private void GetListItems() { // Verify the list name has been provided. string listName = txtListName.Text; if (String.IsNullOrWhiteSpace(listName)) { throw new CMSAPIExampleException("Empty value for List name is not allowed."); } // Get the SharePoint connection from DB SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("MyNewConnection", SiteContext.CurrentSiteID); if (connection == null) { throw new CMSAPIExampleException("SharePoint connection 'My new connection' was not found."); } // Convert SharePointConnectionInfo object into connection data SharePointConnectionData connectionData = connection.ToSharePointConnectionData(); // Get list service implementation ISharePointListService listService = SharePointServices.GetService <ISharePointListService>(connectionData); try { // Get specified list's items DataSet results = listService.GetListItems(listName); if ((results.Tables.Count == 0) || (results.Tables[0].Rows.Count == 0)) { throw new CMSAPIExampleException("No list's items were retrieved from SharePoint server."); } } catch (Exception ex) { throw new CMSAPIExampleException(ex.Message); } }
/// <summary> /// Gets connection data constructed from actual values of the form fields. /// </summary> /// <returns>Connection data</returns> private SharePointConnectionData GetConnectionData() { var connectionData = new SharePointConnectionData() { SharePointConnectionAuthMode = SharePointConnectionAuthMode, SharePointConnectionDomain = SharePointConnectionDomain, SharePointConnectionPassword = SharePointConnectionPassword, SharePointConnectionSharePointVersion = SharePointConnectionSharePointVersion, SharePointConnectionSiteUrl = SharePointConnectionSiteUrl, SharePointConnectionUserName = SharePointConnectionUserName }; return connectionData; }