private void TryConnect() { _mainForm.SetOperationText("Connecting to SharePoint Server..."); Exception error = null; try { // To make sure we can connect to this 2010 SharePoint Server, use // the helper to get the lists SharePoint.SPHelper helper = new SharePoint.SPHelper(_serverSettingsToTry); SharePoint.SPListInfo[] lists = helper.GetLists(); if (lists == null || lists.Length == 0) { error = new Exception("Could not find any lists in the SharePoint Server.\n\nTry again with a different server."); } else { // We are golden, save the lists and the server properties _lists = lists; _serverSettings = _serverSettingsToTry; } } catch (Exception ex) { // Throw our own exception with info error = new Exception(string.Format("Error: {0}\n\nReasons might be:\n- Invalid credentials\n- Invalid Proxy settings\n- Server may not be SharePoint 2010. Try again with a valid URL to SharePoint 2010", ex.Message)); } _mainForm.EndOperation(error); }
private void FillItems(SharePoint.SPItemInfo parentItem) { _curerntFolderItem = parentItem; _errorLabel.Visible = false; _sharePointItemsListView.BeginUpdate(); _sharePointItemsListView.Items.Clear(); // Get the items of the selected list SharePoint.SPListInfo listInfo = _documentLibrariesListBox.SelectedItem as SharePoint.SPListInfo; if (listInfo != null) { try { using (WaitCursor wait = new WaitCursor()) { SharePoint.SPHelper helper = new SharePoint.SPHelper(_serverSettings); SharePoint.SPItemInfo[] items = helper.GetChildren(listInfo, parentItem); // If we have a parent item, add the special "move folder up" item if (parentItem != null) { SharePoint.SPItemInfo item = new SharePoint.SPItemInfo(); item.ItemType = SharePoint.SPItemType.Folder; item.Name = ".."; item.ParentItem = parentItem.ParentItem; _sharePointItemsListView.AddSharePointItem(item); } // Add the children (folders first) to the list view foreach (SharePoint.SPItemInfo item in items) { if (item.ItemType == Ocr2SharePointDemo.SharePoint.SPItemType.Folder) { _sharePointItemsListView.AddSharePointItem(item); } } foreach (SharePoint.SPItemInfo item in items) { if (item.ItemType == Ocr2SharePointDemo.SharePoint.SPItemType.File) { _sharePointItemsListView.AddSharePointItem(item); } } } } catch (Exception ex) { _errorLabel.Text = "Error: " + ex.Message; _errorLabel.Visible = true; } } _sharePointItemsListView.EndUpdate(); UpdateUIState(); }
public SPListInfo(Uri siteUri, List list) { Id = list.Id; Title = list.Title; ServerRelativeUrl = list.RootFolder.ServerRelativeUrl; AbsoluteUri = SPHelper.CombineUrl(siteUri, ServerRelativeUrl); BaseTemplate = (SPTemplateType)list.BaseTemplate; Created = list.Created; Description = list.Description; }
public SPItemInfo(Uri siteUri, ListItem item, SPListInfo parentList, SPItemInfo parentItem) { Id = item.Id; ParentListId = parentList.Id; ParentItem = parentItem; ItemType = item.FileSystemObjectType == FileSystemObjectType.File ? SPItemType.File : SPItemType.Folder; if (!DateTime.TryParse(item.FieldValuesAsText["Created"], out Created)) { Created = DateTime.Now; } DisplayName = item.DisplayName; Name = item.FieldValuesAsText["FileLeafRef"]; Title = item.FieldValuesAsText["Title"]; ServerRelativeUrl = item.FieldValuesAsText["FileRef"]; AbsoluteUri = SPHelper.CombineUrl(siteUri, ServerRelativeUrl); Author = item.FieldValuesAsText["Author"]; FileExtension = item.FieldValuesAsText["File_x0020_Type"]; }