Ejemplo n.º 1
0
        ///<summary>
        ///Get all of the files and folders in the specified folder.
        ///</summary>
        ///<param name="clientContext">The client context.</param>
        ///<param name="folder">The folder to read.</param>
        ///<param name="hostWeb">The host Web.</param>
        private void GetSubfolders(ClientContext clientContext, Folder folder, String hostWeb)
        {
            if (folder.ItemCount > 0)
            {
                // Are there files in this folder?
                if (folder.Files != null)
                {
                    GetFilesInFolder(clientContext, folder, hostWeb);
                }

                // Next, look for any subfolders in this folder.
                FolderCollection subfolders = folder.Folders;
                clientContext.Load <FolderCollection>(subfolders);
                clientContext.ExecuteQuery();
                if (subfolders.Count > 0)
                {
                    // There must have been some subfolders.
                    foreach (Folder subfolder in subfolders)
                    {
                        clientContext.Load <Folder>(subfolder);
                        clientContext.ExecuteQuery();
                        if (subfolder != null)
                        {
                            GetSubfolders(clientContext, subfolder, hostWeb);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Gets all files of all folders of the web.
        /// </summary>
        /// <param name="clientContext">the ClientContext</param>
        /// <param name="folder">the folder</param>
        /// <param name="files">already found files</param>
        /// <returns>all files</returns>
        private List <FileCollection> GetFilesOfAllFolder(ClientContext clientContext, Folder folder, List <FileCollection> files)
        {
            FolderCollection folders = folder.Folders;

            clientContext.Load(folders);
            clientContext.ExecuteQuery();

            if (folders.Count == 0)
            {
                FileCollection currentFiles = folder.Files;
                clientContext.Load(currentFiles);
                clientContext.ExecuteQuery();

                files.Add(currentFiles);
            }
            else
            {
                foreach (Folder f in folders)
                {
                    files = this.GetFilesOfAllFolder(clientContext, f, files);
                }
            }

            return(files);
        }
Ejemplo n.º 3
0
        private static bool FolderExistsImplementation(FolderCollection folderCollection, string folderName)
        {
            if (folderCollection == null)
            {
                throw new ArgumentNullException("folderCollection");
            }

            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentNullException("folderName");
            }

            // TODO: Check for any other illegal characters in SharePoint
            if (folderName.Contains('/') || folderName.Contains('\\'))
            {
                throw new ArgumentException("The argument must be a single folder name and cannot contain path characters.", "folderName");
            }

            folderCollection.Context.Load(folderCollection);
            folderCollection.Context.ExecuteQueryRetry();
            foreach (Folder folder in folderCollection)
            {
                if (folder.Name.Equals(folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public async Task Init()
        {
            var folderList = await App._instance.IO.GetLocalDataAsync <List <FolderItem> >(StaticString.FolderListFileName);

            var historyList = await App._instance.IO.GetLocalDataAsync <List <HistoryItem> >(StaticString.HistoryListFileName);

            FolderCollection.Clear();
            DisplayHistoryCollection.Clear();
            if (!folderList.IsNullOrEmpty())
            {
                folderList.ForEach(p => FolderCollection.Add(p));
            }
            else
            {
                var folderItem = new FolderItem(App._instance.App.GetLocalizationTextFromResource(LanguageName.Default), FeatherSymbol.Activity);
                FolderCollection.Add(folderItem);
                await SaveFolderList();
            }

            string lastSelectedFolderId = App._instance.App.GetLocalSetting(Settings.LastSelectFolderId, "");

            if (!FolderCollection.Any(p => p.Id == lastSelectedFolderId))
            {
                lastSelectedFolderId = FolderCollection.First().Id;
            }

            CurrentSelectedFolder = FolderCollection.Where(p => p.Id == lastSelectedFolderId).First();

            if (!historyList.IsNullOrEmpty())
            {
                AllHistoryList = historyList;
                historyList.Where(p => p.FolderId == lastSelectedFolderId).ToList().ForEach(p => DisplayHistoryCollection.Add(p));
                HistoryChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 5
0
        private void LoadSubFolders(FolderCollection allFolders)
        {
            this.clientContext.Load(allFolders);
            this.clientContext.ExecuteQuery();

            foreach (Folder subFolder in allFolders)
            {
                if (subFolder.Name == "Forms")  //Forms ist von SharePoint
                {
                    continue;
                }
                foreach (SharePointFolder folder in this.sharePointFolderList)
                {
                    this.clientContext.Load(subFolder.ParentFolder);
                    this.clientContext.ExecuteQuery();
                    if (folder.GetFolderName() == subFolder.ParentFolder.Name)
                    {
                        this.sharePointFolder = new SharePointFolder(subFolder.Name, subFolder.ServerRelativeUrl, folder);
                        folder.AddSubFolder(this.sharePointFolder);
                    }
                }

                if (CheckForSubFolders(subFolder))
                {
                    LoadSubFolders(subFolder.Folders);
                }

                LoadFiles(subFolder);
            }
        }
Ejemplo n.º 6
0
        public static void DeployFileToThemeFolderSite(this Web web, byte[] fileBytes, string fileName, string themeFolderVersion = "15")
        {
            // Get the path to the file which we are about to deploy
            List themesList = web.GetCatalog(123);

            // get the theme list
            web.Context.Load(themesList);
            web.Context.ExecuteQuery();

            Folder           rootFolder  = themesList.RootFolder;
            FolderCollection rootFolders = rootFolder.Folders;

            web.Context.Load(rootFolder);
            web.Context.Load(rootFolders, f => f.Where(folder => folder.Name == themeFolderVersion));
            web.Context.ExecuteQuery();

            Folder folder15 = rootFolders.FirstOrDefault();

            // Use CSOM to upload the file in
            FileCreationInformation newFile = new FileCreationInformation();

            newFile.Content   = fileBytes;
            newFile.Url       = UrlUtility.Combine(folder15.ServerRelativeUrl, fileName);
            newFile.Overwrite = true;

            Microsoft.SharePoint.Client.File uploadFile = folder15.Files.Add(newFile);
            web.Context.Load(uploadFile);
            web.Context.ExecuteQuery();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取指定站点下的所有文档库
        /// </summary>
        /// <param name="siteUrl">站点地址</param>
        /// <returns>返回的所有文档库</returns>
        public FolderCollection GetAllFolders()
        {
            FolderCollection folderList = null;

            try
            {
                if (clientContext != null)
                {
                    //创建客户端对象模型
                    using (clientContext)
                    {
                        //获取站点下的所有文档库
                        folderList = clientContext.Web.Folders;

                        LoadMethod(clientContext.Web.Lists);
                        LoadMethod(clientContext.Web.Folders);
                    }
                }
            }
            catch (Exception ex)
            {
                MethodLb.CreateLog(this.GetType().FullName, "GetAllFolders", ex.ToString());
            }
            finally
            {
            }
            //返回所有文档
            return(folderList);
        }
        private void InitializeTreeview()
        {
            if (Vault != null)
            {
                FolderCollection folderCollection = Vault.DefaultStore.Library.GetTopLevelFolders();
                VvTreeNode       node;
                foreach (Folder folder in folderCollection)
                {
                    node = new VvTreeNode(folder.FolderID, folder.Name);
                    node.Nodes.Add(new VvTreeNode(Guid.Empty, ""));
                    TreeView1.Nodes.Add(node);
                }

                if (TreeView1.GetNodeCount(false) > 0)
                {
                    //if selected folder ID was passed in then try and find that folder in the tree
                    //and selected it

                    if (_selectedFolderId.Equals(Guid.Empty))
                    {
                        node = (VvTreeNode)TreeView1.Nodes[0];
                        if (node != null)
                        {
                            TreeView1.SelectedNode = node;
                            LoadChildTreeNodes(node);
                            _selectedFolder = Vault.DefaultStore.Library.GetFolder(node.NodeID);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("You are not logged in to the Target VisualVault Server", "Error", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 9
0
        /*PERMISOS ELEVADOS*/
        public bool ExistePedido(string pedido)
        {
            bool retornar = false;

            using (var clientContext = this.context)
            {
                Web web = clientContext.Web;
                clientContext.Load(web);
                var pedidos = clientContext.Web.Lists.GetByTitle(Listas.CarpetaRaiz);
                clientContext.Load(pedidos);
                FolderCollection carpetas = pedidos.RootFolder.Folders;

                clientContext.Load(carpetas);
                clientContext.ExecuteQuery();

                foreach (Folder carpeta in carpetas)
                {
                    if (carpeta.Name == pedido)
                    {
                        retornar = true;
                    }
                }
            }
            return(retornar);
        }
Ejemplo n.º 10
0
 public void Setup()
 {
     m_collection = new FolderCollection(FolderShortcutOrigin.HostApplication);
     m_collection.AddShortcut("Anna", @"C:\temp");
     m_collection.AddShortcut("Betina", @"[Anna]");
     m_collection.AddShortcut("Christina", @"[Anna]\sub");
 }
Ejemplo n.º 11
0
        private static bool FolderExistsImplementation(FolderCollection folderCollection, string folderName)
        {
            if (folderCollection == null)
            {
                throw new ArgumentNullException("folderCollection");
            }

            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentNullException("folderName");
            }

            // TODO: Check for any other illegal characters in SharePoint
            if (folderName.Contains('/') || folderName.Contains('\\'))
            {
                throw new ArgumentException(CoreResources.FileFolderExtensions_CreateFolder_The_argument_must_be_a_single_folder_name_and_cannot_contain_path_characters_, "folderName");
            }

            folderCollection.Context.Load(folderCollection);
            folderCollection.Context.ExecuteQueryRetry();
            foreach (Folder folder in folderCollection)
            {
                if (folder.Name.Equals(folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 12
0
        private static Folder EnsureFolderImplementation(FolderCollection folderCollection, string folderName)
        {
            // TODO: Check for any other illegal characters in SharePoint
            if (folderName.Contains('/') || folderName.Contains('\\'))
            {
                throw new ArgumentException("The argument must be a single folder name and cannot contain path characters.", "folderName");
            }

            folderCollection.Context.Load(folderCollection);
            folderCollection.Context.ExecuteQuery();
            foreach (Folder folder in folderCollection)
            {
                if (string.Equals(folder.Name, folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(folder);
                }
            }

            var newFolder = folderCollection.Add(folderName);

            folderCollection.Context.Load(newFolder);
            folderCollection.Context.ExecuteQuery();

            return(newFolder);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Add name to the block list if it is not already present.
        /// </summary>
        /// <param name="name">Name of user to block</param>
        public void Block(string name)
        {
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (RuleGroup ruleGroup in ruleGroups)
            {
                if (ruleGroup.rule.Any(rule => rule.property == "Author" && rule.value.ToString() == name))
                {
                    return;
                }
            }
            RuleGroup newRuleGroup = new RuleGroup
            {
                type       = RuleGroupType.Any,
                title      = string.Format(Resources.BlockFrom, name),
                active     = true,
                actionCode = RuleActionCodes.Unread | RuleActionCodes.Clear,
                rule       = new[]
                {
                    new Rule
                    {
                        property = "Author",
                        value    = name,
                        op       = PredicateBuilder.Op.Equals
                    }
                }
            };

            AddRule(newRuleGroup);

            FolderCollection.ApplyRules(newRuleGroup);
        }
Ejemplo n.º 14
0
        public static bool DeleteAllFileFromSharePoint(string libraryName, string ThreadFolderPath)
        {
            try
            {
                using (ClientContext clientContext = GetContextObject())
                {
                    Web web = clientContext.Web;
                    clientContext.Load(web, website => website.ServerRelativeUrl);
                    clientContext.ExecuteQuery();

                    Regex  regex           = new Regex(Configuration.SiteUrl, RegexOptions.IgnoreCase);
                    string documentLibrary = regex.Replace(Configuration.FileUrl, string.Empty);

                    FolderCollection folderList = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/" + libraryName + "/" + ThreadFolderPath).Folders;
                    clientContext.Load(folderList);
                    clientContext.ExecuteQuery();
                    var folders = folderList.ToList();
                    foreach (Microsoft.SharePoint.Client.Folder folderDelete in folders)
                    {
                        folderDelete.DeleteObject();
                        folderDelete.Recycle();
                        clientContext.ExecuteQuery();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 15
0
        public static List <string> GetFolderListFromSharePoint(string targetDocLib)
        {
            List <string> yearFolderList = new List <string>();

            try
            {
                using (ClientContext clientContext = GetContextObject())
                {
                    Web web = clientContext.Web;
                    clientContext.Load(web, website => website.ServerRelativeUrl);
                    clientContext.ExecuteQuery();

                    Regex            regex = new Regex(Configuration.SiteUrl, RegexOptions.IgnoreCase);
                    string           strSiteRelavtiveURL = regex.Replace(targetDocLib, string.Empty);
                    FolderCollection folderList          = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/" + strSiteRelavtiveURL).Folders;
                    clientContext.Load(folderList);
                    clientContext.ExecuteQuery();
                    var folders = folderList.ToList();
                    foreach (Folder folder in folders)
                    {
                        if (folder.Name != "Forms") //Direct files at library comes under Forms folder
                        {
                            yearFolderList.Add(folder.Name);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(yearFolderList);
        }
        /// <summary>
        /// Request the folder structure for a specific path
        /// </summary>
        /// <param name="path">The path to search</param>
        /// <param name="commonFolders">The list of common folders to update</param>
        /// <param name="parent">The parent folder</param>
        /// <param name="isFirstLevel">if <code>true</code>, will request the subfolders of all folders found. Thsi settign depends on the current FolderTreeBrowseMode</param>
        /// <returns>A list of folders</returns>
        internal FolderCollection GetFolders(string path, CommonFolderCollection commonFolders, Folder parent = null, bool isFirstLevel = false)
        {
            var            result = new FolderCollection(this, parent);
            var            cmd    = string.Format(Capabilities.XList && !Capabilities.XGMExt1 ? ImapCommands.XList : ImapCommands.List, path, Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full ? "*" : "%");
            IList <string> data   = new List <string>();

            if (!SendAndReceive(cmd, ref data))
            {
                return(result);
            }

            for (var i = 0; i < data.Count - 1; i++)
            {
                var folder = Folder.Parse(data[i], ref parent, this);
                commonFolders.TryBind(ref folder);

                if (Behavior.ExamineFolders)
                {
                    folder.Examine();
                }

                if (folder.HasChildren && (isFirstLevel || Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full))
                {
                    folder.SubFolders = GetFolders(folder.Path + Behavior.FolderDelimeter, commonFolders, folder);
                }

                result.AddInternal(folder);
            }

            return(result);
        }
Ejemplo n.º 17
0
        private void GetFolderNamesWithFilter(FolderCollection allFolders)
        {
            try {
                Folder rootFolder = this.site.Lists.GetByTitle(this.listName).RootFolder;
                this.clientContext.Load(rootFolder, rf => rf.ServerRelativeUrl);
                this.clientContext.ExecuteQuery();
                Folder folder = this.site.GetFolderByServerRelativeUrl(rootFolder.ServerRelativeUrl + "/" + this.filter);
                this.clientContext.Load(folder);
                this.clientContext.ExecuteQuery();

                this.sharePointFolder = new SharePointFolder(folder.Name, folder.ServerRelativeUrl, null);
                this.sharePointFolderList.Add(this.sharePointFolder);
                this.filteredFolder = folder;
            } catch (Exception ex) {
                if (ex is System.IO.FileNotFoundException || ex is ServerException)
                {
                    this.sharePointFolderList.Clear();
                    this.sharePointFolder = null;
                    this.filteredFolder   = null;
                }
                else
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 18
0
        public static List <string> GetFileListFromSP(string libraryName, string folderName, string groupType, string SPDirPath)
        {
            List <string> filePaths = new List <string>();

            using (ClientContext context = GetContextObject())
            {
                Web web = context.Web;
                context.Load(web, website => website.ServerRelativeUrl);
                context.ExecuteQuery();

                IEnumerable <List> docLibs = context.LoadQuery(web.Lists.Where(l => l.BaseTemplate == 101));

                context.ExecuteQuery();

                if (groupType == "Multi")
                {
                    FolderCollection folderList = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/" + libraryName + "/" + folderName).Folders;
                    context.Load(folderList);
                    context.ExecuteQuery();
                    var folders = folderList.ToList();

                    foreach (Folder folder in folders)
                    {
                        Console.WriteLine(folder.Name + "---- File count " + folder.ItemCount);

                        FileCollection fileList = folder.Files;
                        context.Load(fileList);
                        context.ExecuteQuery();
                        foreach (Microsoft.SharePoint.Client.File file in fileList)
                        {
                            Console.WriteLine(folder.Name + "---- File Name " + file.Name);
                            string filePath = Path.Combine(SPDirPath, folderName.Replace("/", "\\"), folder.Name, file.Name);
                            //string groupfullName = Path.Combine(folderName, folder.Name).Replace("\\", "/");
                            //filePaths.Add(new Tuple<string,string> (filePath, groupfullName));
                            filePaths.Add(filePath);
                        }
                    }
                }
                else if (groupType == "Single")
                {
                    FileCollection fileList = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/" + libraryName + "/" + folderName).Files;
                    context.Load(fileList);
                    context.ExecuteQuery();
                    var files = fileList.ToList();

                    foreach (Microsoft.SharePoint.Client.File file in fileList)
                    {
                        Console.WriteLine(folderName + "---- File Name " + file.Name);
                        string filePath = Path.Combine(SPDirPath, folderName.Replace("/", "\\"), file.Name);
                        //filePaths.Add(new Tuple<string, string>(filePath, folderName.Replace("\\", "/")));
                        filePaths.Add(filePath);
                    }
                }
                else if (groupType == "")
                {
                }
            }
            return(filePaths);
        }
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            string siteUrl     = txtboxSiteUrl.Text;
            string folderPath  = txtboxFolderPath.Text;
            string libraryName = txtboxLibraryName.Text;

            try
            {
                using (ClientContext ctx = new ClientContext(siteUrl))
                {
                    Web          web      = ctx.Web;
                    string       pwd      = "******";
                    SecureString password = new SecureString();
                    for (int i = 0; i < pwd.Length; i++)
                    {
                        password.AppendChar(pwd[i]);
                    }
                    ctx.Credentials = new System.Net.NetworkCredential("******", password);
                    ctx.Load(web);
                    ctx.ExecuteQuery();
                    Microsoft.SharePoint.Client.List dUplaod = web.Lists.GetByTitle(libraryName);
                    String[]         fileNames = Directory.GetFiles(@folderPath);
                    bool             exists    = false;
                    DirectoryInfo    dInfo     = new DirectoryInfo(@folderPath);
                    FolderCollection folders   = dUplaod.RootFolder.Folders;
                    char[]           sep       = { '\\' };
                    ctx.Load(folders);
                    ctx.ExecuteQuery();
                    foreach (Folder eFolder in folders)
                    {
                        if (eFolder.Name.Equals(dInfo.Name))
                        {
                            foreach (String fileName in fileNames)
                            {
                                String[] names = fileName.Split(sep);
                                FileCreationInformation fCInfo = new FileCreationInformation();
                                fCInfo.Content   = System.IO.File.ReadAllBytes(fileName);
                                fCInfo.Url       = names[names.Length - 1];
                                fCInfo.Overwrite = true;
                                eFolder.Files.Add(fCInfo);
                                exists = true;
                            }
                        }
                    }

                    if (!exists)
                    {
                        Folder tFolder = folders.Add(siteUrl + "/" + libraryName + "/" + dInfo.Name);
                        ctx.ExecuteQuery();
                        UploadFile(ctx, tFolder, dInfo);
                    }
                    MessageBox.Show("The Execution is completed");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 20
0
        public async Task SaveFolderList()
        {
            IsFolderListChanged = false;
            List <FolderItem> folderList = new List <FolderItem>();

            folderList = FolderCollection.ToList();
            await App._instance.IO.SetLocalDataAsync(StaticString.FolderListFileName, JsonConvert.SerializeObject(folderList));
        }
Ejemplo n.º 21
0
        private static Folder CreateFolderImplementation(FolderCollection folderCollection, string folderName)
        {
            var newFolder = folderCollection.Add(folderName);
            folderCollection.Context.Load(newFolder);
            folderCollection.Context.ExecuteQueryRetry();

            return newFolder;
        }
        public static Folder GetByName(this FolderCollection folders, string name)
        {
            var ctx = folders.Context;

            ctx.Load(folders);
            ctx.ExecuteQuery();
            return(Enumerable.FirstOrDefault(folders, fldr => fldr.Name == name));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Connect to the server and display mailbox statistics.
        /// </summary>
        private async void Connect(object sender, EventArgs e)
        {
            _window.Busy = true;
            Imap client = null;

            try
            {
                client = new Imap();
                await client.ConnectAsync(ServerName, ServerPort, Mode);
            }
            catch (Exception ex)
            {
                _window.Busy = false;
                Util.ShowException(ex);
                return;
            }

            if (!string.IsNullOrEmpty(UserName))
            {
                try
                {
                    await client.AuthenticateAsync(UserName, Password);
                }
                catch (Exception ex)
                {
                    _window.Busy = false;
                    Util.ShowException(ex);
                    return;
                }
            }

            StringBuilder output = new StringBuilder();

            try
            {
                await client.SelectAsync("INBOX");

                FolderCollection rootFolders = await client.ListFoldersAsync();

                output.AppendFormat("{0} folders in the root folder.\n", rootFolders.Count);
                ImapMessageCollection msgs = await client.ListMessagesAsync(ImapEnvelopeParts.Size);

                long size = 0;
                for (int i = 0; i < msgs.Count; i++)
                {
                    size += msgs [i].Size;
                }
                output.AppendFormat("{0} messages in INBOX folder. Total size: {1} bytes.\n", msgs.Count, size);
            }
            catch (Exception ex)
            {
                _window.Busy = false;
                Util.ShowException(ex);
                return;
            }
            _window.Busy = false;
            Util.ShowMessage("Mailbox Info", output.ToString());
        }
        public static FolderCollection GetFolders(ClientContext cc, List list)
        {
            FolderCollection folders = list.RootFolder.Folders;

            cc.Load(folders);
            cc.ExecuteQuery();

            return(folders);
        }
Ejemplo n.º 25
0
        private Folder GetFolderIfExists(List list, string folder)
        {
            FolderCollection folders = list.RootFolder.Folders;

            SPContext.Load(folders, fl => fl.Include(ct => ct.Name).Where(ct => ct.Name == folder));

            SPContext.ExecuteQuery();

            return(folders.FirstOrDefault());
        }
        /// <summary>
        /// Creates collection of <see cref="ImapFolder"/> from <paramref name="folders"/>.
        /// </summary>
        /// <param name="folders"><see cref="MailBee.ImapMail.FolderCollection"/> instance.</param>
        /// <returns>ImapFolder collection</returns>
        private IEnumerable <ImapFolder> GetFolders(FolderCollection folders)
        {
            var result = new List <ImapFolder>();

            for (var i = 0; i < folders.Count; i++)
            {
                result.Add(new ImapFolder(folders[i]));
            }
            return(result.OrderBy(f => f.NestingLevel));
        }
        public static string[] GetFolderNames(ClientContext cc, List list, FolderCollection folders)
        {
            string[] foldernames = new string[folders.Count];

            for (int i = 0; i < folders.Count; i++)
            {
                foldernames[i] = folders[i].Name;
            }

            return(foldernames);
        }
Ejemplo n.º 28
0
 private void GetNodesFromFolders(FolderCollection folders, TreeListNode root)
 {
     foreach (var folder in folders)
     {
         tlFolders.AppendNode(new object[] { folder.Name }, root, folder.Path);
         if (folder.HasChildren)
         {
             GetNodesFromFolders(folder.SubFolders, tlFolders.Nodes.LastNode);
         }
     }
 }
Ejemplo n.º 29
0
        private Pollux.Entities.DocumentoItem MontarDocumentoPasta(DateTime datacriacao, string nomedapasta, string urlrelativa, string urlSite, ClientContext spClientContext)
        {
            Pollux.Entities.DocumentoItem        docItem   = new Pollux.Entities.DocumentoItem();
            List <Pollux.Entities.DocumentoItem> listaDocs = new List <Pollux.Entities.DocumentoItem>();

            // preenche com as informações da pasta
            docItem.DataCriacao   = datacriacao;
            docItem.Nome          = nomedapasta;
            docItem.Tamanho       = string.Empty;
            docItem.TipoDocumento = 993520001;
            docItem.URL           = ObterUrlArquivo(urlSite, urlrelativa);

            #region  Obtem os documentos da subpasta
            var    rootWeb        = spClientContext.Web;
            Folder pastaPrincipal = rootWeb.GetFolderByServerRelativeUrl(urlrelativa);

            spClientContext.Load(pastaPrincipal, fs => fs.Files, p => p.Folders);
            spClientContext.ExecuteQuery();

            FileCollection fileCollection = pastaPrincipal.Files;

            //lista os documentos da pasta
            foreach (var arquivo in fileCollection)
            {
                listaDocs.Add(MontarDocumento(arquivo, urlSite));
            }
            #endregion

            #region Obtem as subpasta que estão em camasas existem na subpasta pai
            var rootweb = spClientContext.Web;
            FolderCollection folderCollection = rootweb.GetFolderByServerRelativeUrl(urlrelativa).Folders;

            spClientContext.Load(folderCollection, fs => fs.Include(f => f.ListItemAllFields));
            spClientContext.ExecuteQuery();
            //lista os arquivos da subpasta
            foreach (Folder subFolder in folderCollection)
            {
                // This property is now populated
                var item = subFolder.ListItemAllFields;

                // This is where the dates you want are stored
                var created             = (DateTime)item["Created"];
                var nomedasubpasta      = (string)item["Title"];
                var urlrelativaSubpasta = (string)item["FileRef"];

                //Cria recursividade de documentos e subpastas
                listaDocs.Add(MontarDocumentoPasta(created, nomedasubpasta, urlrelativaSubpasta, urlSite, spClientContext));
            }
            #endregion

            docItem.DocumentoItens = listaDocs;

            return(docItem);
        }
Ejemplo n.º 30
0
        static public String UploadToTeamSite(String localPath)
        {
            var siteUrl = ConfigurationManager.AppSettings["teamSiteUrl"];

            using (ClientContext clientContext = new ClientContext(siteUrl))
            {
                string username = ConfigurationManager.AppSettings["username"];

                //decrypt password
                string base64Encoded = ConfigurationManager.AppSettings["password"];
                string password;
                byte[] data = System.Convert.FromBase64String(base64Encoded);
                password = System.Text.ASCIIEncoding.ASCII.GetString(data);

                NetworkCredential _myCredentials = new NetworkCredential(username, password);
                clientContext.Credentials = _myCredentials;
                clientContext.ExecuteQuery();

                var ServerVersion = clientContext.ServerLibraryVersion.Major;

                var site = clientContext.Site;
                var web  = clientContext.Site.RootWeb;

                clientContext.Load(web, w => w.ServerRelativeUrl);
                clientContext.ExecuteQuery();

                var serverRelativeUrl = clientContext.Site.RootWeb.ServerRelativeUrl;

                //Check and create folder
                string name = DateTime.Now.ToString("yyyy.MM.dd");
                Microsoft.SharePoint.Client.List list = clientContext.Web.Lists.GetByTitle("CookieCheckerResults");
                FolderCollection folders = list.RootFolder.Folders;
                clientContext.Load(list);
                clientContext.Load(folders);
                clientContext.ExecuteQuery();

                var folderExists = folders.Any(X => X.Name == name);
                if (!folderExists)
                {
                    Folder newFolder = folders.Add(name);
                    clientContext.Load(newFolder);
                    clientContext.ExecuteQuery();
                }

                //Add the file
                string[] Splits = localPath.Split('\\');
                using (FileStream fs = new FileStream(localPath, FileMode.Open))
                {
                    Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/sites/sp_team_nbg/CookieCheckerResults/" + name + "/" + Splits[Splits.Length - 1], fs, true);
                }

                return(ConfigurationManager.AppSettings["teamSiteUrl"] + "/CookieCheckerResults/" + name);
            }
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Function to verify if Folder already exists in Site Assets
 /// </summary>
 /// <param name="matterCenterAssetsFolder">Matter Center Assets Folder</param>
 /// <param name="clientContext">Client Context</param>
 /// <param name="siteAssets">Site Assets</param>
 /// <param name="matterLandingFolder">Matter Landing Folder</param>
 /// <param name="listFolders">List Folder</param>
 /// <returns>List of items in folder</returns>
 private static ListItemCollection CheckFolderExists(string matterCenterAssetsFolder, ClientContext clientContext, out List siteAssets, out ListItemCollection matterLandingFolder, out FolderCollection listFolders)
 {
     CamlQuery camlQuery = new CamlQuery();
     camlQuery.ViewXml = @"<View><Query><Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='Folder'>" + matterCenterAssetsFolder + "</Value></Eq></Where></Query><ViewFields><FieldRef Name='FileLeafRef' /></ViewFields></View>";
     siteAssets = clientContext.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["LibraryName"]);
     matterLandingFolder = siteAssets.GetItems(camlQuery);
     listFolders = siteAssets.RootFolder.Folders;
     clientContext.Load(matterLandingFolder);
     clientContext.Load(siteAssets.RootFolder);
     clientContext.Load(listFolders);
     clientContext.ExecuteQuery();
     return matterLandingFolder;
 }
Ejemplo n.º 32
0
        internal FolderCollection GetFolders(string path, CommonFolderCollection commonFolders, Folder parent = null, bool isFirstLevel = false)
        {
            var result = new FolderCollection(this, parent);
            var cmd = string.Format(Capabilities.XList && !Capabilities.XGMExt1 ? ImapCommands.XList : ImapCommands.List, path, Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full || (parent != null && Behavior.LazyFolderBrowsingNotSupported) ? "*" : "%");
            IList<string> data = new List<string>();

            if (!SendAndReceive(cmd, ref data))
            {
                return result;
            }

            for (var i = 0; i < data.Count - 1; i++)
            {
                var folder = Folder.Parse(data[i], ref parent, this);
                commonFolders.TryBind(ref folder);

                if (Behavior.ExamineFolders)
                {
                    folder.Examine();
                }

                if (folder.HasChildren && (isFirstLevel || Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full))
                {
                    folder.SubFolders = GetFolders(folder.Path + Behavior.FolderDelimeter, commonFolders, folder);
                }

                result.AddInternal(folder);
            }

            return result;
        }
Ejemplo n.º 33
0
        private static bool FolderExistsImplementation(FolderCollection folderCollection, string folderName)
        {
            if (folderCollection == null)
            {
                throw new ArgumentNullException("folderCollection");
            }

            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentNullException("folderName");
            }

            if (folderName.ContainsInvalidUrlChars())
            {
                throw new ArgumentException(CoreResources.FileFolderExtensions_CreateFolder_The_argument_must_be_a_single_folder_name_and_cannot_contain_path_characters_, "folderName");
            }

            folderCollection.Context.Load(folderCollection);
            folderCollection.Context.ExecuteQueryRetry();
            foreach (Folder folder in folderCollection)
            {
                if (folder.Name.Equals(folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 34
0
        private static Folder EnsureFolderImplementation(FolderCollection folderCollection, string folderName, Folder parentFolder = null)
        {
            Folder folder = null;

            folderCollection.Context.Load(folderCollection);
            folderCollection.Context.ExecuteQueryRetry();
            foreach (Folder existingFolder in folderCollection)
            {
                if (string.Equals(existingFolder.Name, folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    folder = existingFolder;
                    break;
                }
            }

            if (folder == null)
            {
                folder = CreateFolderImplementation(folderCollection, folderName, parentFolder);
            }

            return folder;
        }
Ejemplo n.º 35
0
        private static Folder CreateFolderImplementation(FolderCollection folderCollection, string folderName, Folder parentFolder = null)
        {
            ClientContext context = null;
            if (parentFolder != null)
            {
                context = parentFolder.Context as ClientContext;
            }

            List parentList = null;

            if (parentFolder != null)
            {
                parentFolder.EnsureProperty(p => p.Properties);
                if (parentFolder.Properties.FieldValues.ContainsKey("vti_listname"))
                {
                    if (context != null)
                    {
                        Guid parentListId = Guid.Parse((String)parentFolder.Properties.FieldValues["vti_listname"]);
                        parentList = context.Web.Lists.GetById(parentListId);
                        context.Load(parentList, l => l.BaseType, l => l.Title);
                        context.ExecuteQueryRetry();
                    }
                }
            }

            if (parentList == null)
            {
                // Create folder for library or common URL path
                var newFolder = folderCollection.Add(folderName);
                folderCollection.Context.Load(newFolder);
                folderCollection.Context.ExecuteQueryRetry();
                return newFolder;
            }
            else
            {
                // Create folder for generic list
                ListItemCreationInformation newFolderInfo = new ListItemCreationInformation();
                newFolderInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
                newFolderInfo.LeafName = folderName;
                parentFolder.EnsureProperty(f => f.ServerRelativeUrl);
                newFolderInfo.FolderUrl = parentFolder.ServerRelativeUrl;
                ListItem newFolderItem = parentList.AddItem(newFolderInfo);
                newFolderItem["Title"] = folderName;
                newFolderItem.Update();
                context.ExecuteQueryRetry();

                // Get the newly created folder
                var newFolder = parentFolder.Folders.GetByUrl(folderName);
                // Ensure all properties are loaded (to be compatible with the previous implementation)
                context.Load(newFolder);
                context.ExecuteQuery();
                return (newFolder);
            }
        }
Ejemplo n.º 36
0
        private static bool FolderExistsImplementation(FolderCollection folderCollection, string folderName)
        {
            if (folderCollection == null)
                throw new ArgumentNullException("folderCollection");

            if (string.IsNullOrEmpty(folderName))
                throw new ArgumentNullException("folderName");

            // TODO: Check for any other illegal characters in SharePoint
            if (folderName.Contains('/') || folderName.Contains('\\'))
            {
                throw new ArgumentException("The argument must be a single folder name and cannot contain path characters.", "folderName");
            }

            folderCollection.Context.Load(folderCollection);
            folderCollection.Context.ExecuteQuery();
            foreach (Folder folder in folderCollection)
            {
                if (folder.Name.Equals(folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 37
0
        private static Folder CreateFolderImplementation(FolderCollection folderCollection, string folderName)
        {
            var newFolder = folderCollection.Add(folderName);
            folderCollection.Context.Load(newFolder);
            folderCollection.Context.ExecuteQuery();

            return newFolder;
        }
Ejemplo n.º 38
0
        ////Get the document set as folder from folders collection.
        private Folder GetDocumentSetFolder(FolderCollection folders,string folderName)
        {
            Folder returnValue= null;
            foreach (Folder folder in folders)
            {
                if (folder.Name == folderName)
                {
                    returnValue = folder;
                    break;
                }
            }

            return returnValue;
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Upload files to SharePoint assets library
        /// </summary>
        /// <param name="matterCenterAssetsFolder">Matter Center Assets Folder</param>
        /// <param name="clientContext">Client Context</param>
        /// <param name="siteAssets">Site Assets</param>
        /// <param name="listFolders">List Folders</param>
        /// <param name="listval">Configuration values from Configuration Excel</param>
        private static void UploadFilesToFolder(string matterCenterAssetsFolder, ClientContext clientContext, List siteAssets, FolderCollection listFolders, Dictionary<string, string> listval)
        {
            try
            {
                // Add matter landing folder
                listFolders.Add(matterCenterAssetsFolder);
                siteAssets.RootFolder.Update();
                siteAssets.Update();
                clientContext.Load(listFolders, folders => folders.Include(folderProperty => folderProperty.Name, folderProperty => folderProperty.ServerRelativeUrl).Where(folder => folder.Name == matterCenterAssetsFolder));
                clientContext.ExecuteQuery();

                Console.WriteLine("\n " + matterCenterAssetsFolder + " folder created...");
                string matterCenterAssetsUrl = listFolders.FirstOrDefault().ServerRelativeUrl;
                string staticContentFolder = ConfigurationManager.AppSettings["StaticContentFolder"];
                if (!string.IsNullOrWhiteSpace(matterCenterAssetsUrl))
                {
                    string parentDirectory = Convert.ToString(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, CultureInfo.InvariantCulture) + "\\" + staticContentFolder + "\\" + matterCenterAssetsFolder;
                    string matterLandingAssetsFolder = ConfigurationManager.AppSettings["MatterLandingAssets"];
                    string webDashboardAssetsFolder = ConfigurationManager.AppSettings["WebDashboardAssets"];
                    string commonAssetsFolder = ConfigurationManager.AppSettings["CommonAssets"];
                    string documentLandingAssetsFolder = ConfigurationManager.AppSettings["DocumentLandingAssets"];

                    string images = ConfigurationManager.AppSettings["Images"];
                    string scripts = ConfigurationManager.AppSettings["Scripts"];
                    string styles = ConfigurationManager.AppSettings["Styles"];

                    // Create matter landing assets and web dashboard assets folder
                    listFolders.Add(matterCenterAssetsUrl + "/" + matterLandingAssetsFolder);
                    listFolders.Add(matterCenterAssetsUrl + "/" + matterLandingAssetsFolder + "/" + images);
                    listFolders.Add(matterCenterAssetsUrl + "/" + matterLandingAssetsFolder + "/" + scripts);
                    listFolders.Add(matterCenterAssetsUrl + "/" + matterLandingAssetsFolder + "/" + styles);

                    // Add web dashboard folder
                    listFolders.Add(matterCenterAssetsUrl + "/" + webDashboardAssetsFolder);
                    listFolders.Add(matterCenterAssetsUrl + "/" + webDashboardAssetsFolder + "/" + images);
                    listFolders.Add(matterCenterAssetsUrl + "/" + webDashboardAssetsFolder + "/" + scripts);
                    listFolders.Add(matterCenterAssetsUrl + "/" + webDashboardAssetsFolder + "/" + styles);

                    // Add common assets folder
                    listFolders.Add(matterCenterAssetsUrl + "/" + commonAssetsFolder);
                    listFolders.Add(matterCenterAssetsUrl + "/" + commonAssetsFolder + "/" + images);
                    listFolders.Add(matterCenterAssetsUrl + "/" + commonAssetsFolder + "/" + scripts);
                    listFolders.Add(matterCenterAssetsUrl + "/" + commonAssetsFolder + "/" + styles);

                    // Add document landing folder
                    listFolders.Add(matterCenterAssetsUrl + "/" + documentLandingAssetsFolder);
                    listFolders.Add(matterCenterAssetsUrl + "/" + documentLandingAssetsFolder + "/" + images);
                    listFolders.Add(matterCenterAssetsUrl + "/" + documentLandingAssetsFolder + "/" + scripts);
                    listFolders.Add(matterCenterAssetsUrl + "/" + documentLandingAssetsFolder + "/" + styles);

                    siteAssets.Update();
                    clientContext.ExecuteQuery();

                    Console.WriteLine("Created matter landing and web dashboard assets folders.");

                    Console.WriteLine(" ------- Starting to upload assets ------- ");

                    // Upload matter landing assets
                    UploadAssets(parentDirectory + "\\" + matterLandingAssetsFolder, "*", matterCenterAssetsUrl + "/" + matterLandingAssetsFolder, clientContext, listval);
                    // Upload web dashboard images
                    UploadAssets(parentDirectory + "\\" + webDashboardAssetsFolder + "\\" + images, "*", matterCenterAssetsUrl + "/" + webDashboardAssetsFolder + "/" + images, clientContext, listval);
                    // Upload web dashboard scripts
                    UploadAssets(parentDirectory + "\\" + webDashboardAssetsFolder + "\\" + scripts, "*", matterCenterAssetsUrl + "/" + webDashboardAssetsFolder + "/" + scripts, clientContext, listval);
                    // Upload web dashboard styles
                    UploadAssets(parentDirectory + "\\" + webDashboardAssetsFolder + "\\" + styles, "*", matterCenterAssetsUrl + "/" + webDashboardAssetsFolder + "/" + styles, clientContext, listval);
                    // Upload matter landing images
                    UploadAssets(parentDirectory + "\\" + matterLandingAssetsFolder + "\\" + images, "*", matterCenterAssetsUrl + "/" + matterLandingAssetsFolder + "/" + images, clientContext, listval);
                    // Upload matter landing scripts
                    UploadAssets(parentDirectory + "\\" + matterLandingAssetsFolder + "\\" + scripts, "*", matterCenterAssetsUrl + "/" + matterLandingAssetsFolder + "/" + scripts, clientContext, listval);
                    // Upload matter landing styles
                    UploadAssets(parentDirectory + "\\" + matterLandingAssetsFolder + "\\" + styles, "*", matterCenterAssetsUrl + "/" + matterLandingAssetsFolder + "/" + styles, clientContext, listval);
                    // Upload common images
                    UploadAssets(parentDirectory + "\\" + commonAssetsFolder + "\\" + images, "*", matterCenterAssetsUrl + "/" + commonAssetsFolder + "/" + images, clientContext, listval);
                    // Upload common scripts
                    UploadAssets(parentDirectory + "\\" + commonAssetsFolder + "\\" + scripts, "*", matterCenterAssetsUrl + "/" + commonAssetsFolder + "/" + scripts, clientContext, listval);
                    // Upload common styles
                    UploadAssets(parentDirectory + "\\" + commonAssetsFolder + "\\" + styles, "*", matterCenterAssetsUrl + "/" + commonAssetsFolder + "/" + styles, clientContext, listval);

                    UploadAssets(parentDirectory + "\\" + documentLandingAssetsFolder + "\\" + scripts, "*", matterCenterAssetsUrl + "/" + documentLandingAssetsFolder + "/" + scripts, clientContext, listval);

                    UploadAssets(parentDirectory + "\\" + documentLandingAssetsFolder + "\\" + images, "*", matterCenterAssetsUrl + "/" + documentLandingAssetsFolder + "/" + images, clientContext, listval);

                    UploadAssets(parentDirectory + "\\" + documentLandingAssetsFolder + "\\" + styles, "*", matterCenterAssetsUrl + "/" + documentLandingAssetsFolder + "/" + styles, clientContext, listval);
                }
                else
                {
                    Console.WriteLine("\n Something went wrong. The matter center assets folder is not created or unable to browse.");
                }
            }
            catch (Exception exception)
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
            }
        }
Ejemplo n.º 40
0
        private static Folder EnsureFolderImplementation(FolderCollection folderCollection, string folderName)
        {
            // TODO: Check for any other illegal characters in SharePoint
            if (folderName.Contains('/') || folderName.Contains('\\'))
            {
                throw new ArgumentException("The argument must be a single folder name and cannot contain path characters.", "folderName");
            }

            folderCollection.Context.Load(folderCollection);
            folderCollection.Context.ExecuteQuery();
            foreach (Folder folder in folderCollection)
            {
                if (string.Equals(folder.Name, folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return folder;
                }
            }

            var newFolder = folderCollection.Add(folderName);
            folderCollection.Context.Load(newFolder);
            folderCollection.Context.ExecuteQuery();

            return newFolder;
        }