public SP.Folder NewFolder(SPList list, string folderName, string currentDir) { if (!IsFolderValid(list, folderName, currentDir)) { return(null); } using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { SP.List splist = clientContext.ToList(list.Id); SP.Folder parentFolder = clientContext.Web.GetFolderByServerRelativeUrl(currentDir); clientContext.Load(parentFolder); // add a new folder SP.Folder newFolder = parentFolder.Folders.Add(folderName); parentFolder.Update(); clientContext.Load(newFolder); try { clientContext.ExecuteQuery(); } catch (Exception ex) { EventLogs.Warn(String.Format("An exception of type {0} occurred while creating a new folder with a name '{1}' for a directory '{2}'. The exception message is: {3}", ex.GetType().Name, folderName, currentDir, ex.Message), "SharePointClient", 778, CSContext.Current.SettingsID); return(null); } cacheService.RemoveByTags(new[] { GetTag(list.Id) }, CacheScope.Context | CacheScope.Process); return(newFolder); } }
public bool IsFolderValid(SPList list, string folderName, string currentDir) { folderName = folderName.Trim(); if (String.IsNullOrEmpty(folderName)) { return(false); } using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { SP.List splist = clientContext.ToList(list.Id); SP.Folder parentFolder = clientContext.Web.GetFolderByServerRelativeUrl(currentDir); clientContext.Load(parentFolder); var subfolders = clientContext.LoadQuery(parentFolder.Folders.Where(folder => folder.Name == folderName)); try { clientContext.ExecuteQuery(); } catch (Exception ex) { EventLogs.Warn(String.Format("An exception of type {0} occurred while loading subfolders for a directory '{1}'. The exception message is: {2}", ex.GetType().Name, currentDir, ex.Message), "SharePointClient", 778, CSContext.Current.SettingsID); return(false); } // subfolders.Count()>0 means, that the folder already exists return(!subfolders.Any()); } }
public void Initialize() { try { var web = SPSite.OpenWeb(SPSiteURL, Authentication); SPSiteName = web.Title; SPWebID = web.WebId; SPSiteID = web.SiteId; } catch (Exception ex) { EventLogs.Warn(String.Format(IntegrationManagerLoadError, ex.GetType().Name, ex.Message), "Integration Manager", 468626, CSContext.Current.SettingsID); } TEGroupName = TEHelper.GetGroupName(TEGroupId); }
public static void Event(string msg) { EventLogs.Warn(msg, "SharePoint", 3681); }