/// <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> /// Loads options for combo box from SharePoint. /// Fills the options directly in the combo box. /// </summary> private void LoadListsFromSharePoint() { drpSharePointLists.DropDownList.Items.Clear(); int connectionID = SharePointConnectionID; var connectionInfo = SharePointConnectionInfoProvider.GetSharePointConnectionInfo(connectionID); if (connectionInfo == null) { return; } DataSet lists = null; try { ISharePointListService service = SharePointServices.GetService <ISharePointListService>(connectionInfo.ToSharePointConnectionData()); lists = service.GetLists(SharePointListType); } catch (Exception ex) { mShowConnectionWarning = true; EventLogProvider.LogWarning("SharePoint", "GETSHAREPOINTLISTS", ex, SiteContext.CurrentSiteID, String.Empty); } DataHelper.ForEachRow(lists, AddOptionToComboBoxFromRow); }
/// <summary> /// Deletes SharePoint connection. Called when the "Delete SharePoint connection" button is clicked. /// Expects the CreateSharePointConnection method to be run first. /// </summary> private void DeleteSharePointConnection() { // 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."); } // Delete the SharePoint connection from DB SharePointConnectionInfoProvider.DeleteSharePointConnectionInfo(connection); }
/// <summary> /// Gets and updates SharePoint connection. Called when the "Get and update SharePoint connection" button is clicked. /// Expects the CreateSharePointConnection method to be run first. /// </summary> private void GetAndUpdateSharePointConnection() { // 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."); } // Update the properties connection.SharePointConnectionDisplayName = connection.SharePointConnectionDisplayName.ToLowerCSafe(); // Save the changes into DB SharePointConnectionInfoProvider.SetSharePointConnectionInfo(connection); }
/// <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); } }