예제 #1
0
        private static void SetFoldersToTreeview(SPFolder folder, ref TreeNode parentNode, string baseURL)
        {
            SPFolderCollection subFolders = folder.SubFolders;

            foreach (SPFolder subFolder in subFolders)
            {
                TreeNode folderNode = new TreeNode();
                folderNode.ImageUrl     = baseURL + "/_layouts/images/folder.gif";
                folderNode.Text         = subFolder.Name;
                folderNode.SelectAction = TreeNodeSelectAction.None;
                folderNode.ShowCheckBox = false;
                foreach (SPFile file in subFolder.Files)
                {
                    if (WPHelper.fileType(Path.GetExtension(file.Name).ToUpper()))
                    {
                        TreeNode fileNode = new TreeNode();
                        fileNode.Text         = file.Name;
                        fileNode.ImageUrl     = baseURL + "/_layouts/images/" + file.IconUrl;
                        fileNode.Value        = file.Url;
                        fileNode.SelectAction = TreeNodeSelectAction.None;
                        folderNode.ChildNodes.Add(fileNode);
                    }
                }
                parentNode.ChildNodes.Add(folderNode);
                SetFoldersToTreeview(subFolder, ref folderNode, baseURL);
            }
        }
예제 #2
0
        public ArtDevList ClearItemsIfModeDev()
        {
            if ((string)this.list.ParentWeb.AllProperties["DEV"] == "true")
            {
                if (this.list.BaseType == SPBaseType.GenericList)
                {
                    SPListItemCollection coll = this.list.Items;

                    foreach (SPListItem listitem in coll)
                    {
                        SPListItem itemToDelete = this.list.GetItemById(listitem.ID);
                        itemToDelete.Recycle();
                    }
                }

                if (this.list.BaseType == SPBaseType.DocumentLibrary)
                {
                    string             libURL  = this.list.ParentWeb.Url + "/" + this.list.RootFolder.Url;
                    SPFolderCollection folders = this.list.ParentWeb.Folders[libURL].SubFolders;

                    foreach (SPFolder folder in folders)
                    {
                        if (!folder.Name.Contains("Forms"))
                        {
                            SPListItem itemToDelete = this.list.GetItemById(folder.Item.ID);
                            itemToDelete.Recycle();
                        }
                    }
                }
            }


            return(this);
        }
예제 #3
0
        private static FolderNodeInfo[] GetFolders(ISharePointCommandContext context, FolderNodeInfo folderNodeInfo)
        {
            List <FolderNodeInfo> nodeInfos = new List <FolderNodeInfo>();

            try
            {
                SPList   styleLibrary = context.Web.GetList(Utilities.CombineUrl(context.Web.ServerRelativeUrl, "Style%20Library"));
                SPFolder folder       = styleLibrary.RootFolder;
                if (folderNodeInfo != null)
                {
                    folder = context.Web.GetFolder(folderNodeInfo.Url);
                }

                SPFolderCollection subfolders = folder.SubFolders;
                if (subfolders != null)
                {
                    nodeInfos = subfolders.ToFolderNodeInfo();
                }
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.FileSharePointCommands_RetrieveFoldersException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(nodeInfos.ToArray());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SPFolderCollection sfc = SPContext.Current.Web.Folders;
                ddl_Destination.Items.Add("---Make a selection---");
                foreach (SPFolder f in sfc.Cast <SPFolder>().OrderBy(t => t.Name))
                {
                    if (f.DocumentLibrary != null)
                    {
                        ddl_Destination.Items.Add(new ListItem(f.Name, f.Url));
                    }
                }

                SPListCollection lic = SPContext.Current.Web.Lists;
                ddl_Lists.Items.Add("---Make a selection---");
                foreach (SPList l in lic.Cast <SPList>().OrderBy(t => t.Title))
                {
                    //if(l.BaseType == SPBaseType.f
                    ddl_Lists.Items.Add(new ListItem(l.Title, l.ID.ToString()));
                }

                SPDocumentLibrary tempDocs = (SPDocumentLibrary)SPContext.Current.Web.Lists["Merge Templates"];
                //lb_Templates.Items.Add(new ListItem("---Make a selection---","-1",true);
                foreach (SPListItem i in tempDocs.Items.Cast <SPListItem>().OrderBy(t => t.Name))
                {
                    lb_Templates.Items.Add(new ListItem(i.Name, i.UniqueId.ToString()));
                }
                lb_Templates.DataBind();
            }
        }
        public void CreateFolder(string folderName)
        {
            if (string.IsNullOrEmpty(folderName))
            {
                return;
            }

            SPWeb website = null;

            try
            {
                website = GetWebSite();
                var library = (SPDocumentLibrary)website.Lists[ListName];
                SPFolderCollection folders = website.Folders;
                folders.Add(Utilities.RemoveSlashAtTheEnd(SiteUrl) + "/" + Utilities.RemoveSlashAtTheEnd(SiteName) + "/" + Utilities.RemoveSlashAtTheEnd(ListName) + "/" + Utilities.RemoveSlashAtTheEnd(folderName) + "/");
                library.Update();
            }
            catch (Exception ex)
            {
                var log = new AppEventLog(AppException.ExceptionMessage(ex, "CreateFolder", "ClsHelper"));
                log.WriteToLog();
            }
            finally
            {
                if (website != null)
                {
                    website.Dispose();
                }
            }
        }
예제 #6
0
        private void btnShowFiles_Click(object sender, EventArgs e)
        {
            SPFolderCollection folders = Web.Folders;

            foreach (SPFolder fld in folders)
            {
                Debug.WriteLine(string.Format("Folder: {0}, URL: {1} ", fld.Name, fld.ServerRelativeUrl));

                foreach (SPFile f in fld.Files)
                {
                    Debug.WriteLine(string.Format("File: {0}, Version: {1}.{2}", f.Name, f.MajorVersion, f.MinorVersion));

                    if (f.Versions.Count > 1)
                    {
                        SPFileVersionCollection versions = f.Versions;
                        foreach (SPFileVersion v in versions)
                        {
                            Debug.WriteLine("Version: " + v.VersionLabel);
                            Stream stm = new MemoryStream(v.OpenBinary());
                            ExportStream(@"d:\" + v.VersionLabel + "-" + f.Name, stm);
                        }
                    }
                }
            }
        }
예제 #7
0
 private void CreateSubFolders(string[] folderUrls, SPFolder folder)
 {
     for (int i = 0; i < folderUrls.Length; i++)
     {
         SPFolderCollection coll = folder.SubFolders;
         coll.Add(folder.ServerRelativeUrl + "/" + folderUrls[i]);
     }
 }
예제 #8
0
        private void LoadBanner()
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.OpenWeb(SPContext.Current.Site.RootWeb.ID))
                        {
                            SPList spList  = Utility.GetListFromURL(Constants.BANNER_LIBRARY_URL, web);
                            string banners = string.Empty;
                            if (spList != null)
                            {
                                SPFolder spFolder = spList.RootFolder;

                                if (!string.IsNullOrEmpty(BannerFolder))
                                {
                                    SPFolderCollection folderCollection = spFolder.SubFolders;

                                    foreach (SPFolder folder in folderCollection)
                                    {
                                        if (spFolder.Name == "Attachments" || spFolder.Item == null)
                                        {
                                            continue;
                                        }
                                        if (spFolder.Item.Name == BannerFolder)
                                        {
                                            spFolder = folder;
                                            break;
                                        }
                                    }
                                }

                                SPQuery spQuery = new SPQuery();
                                spQuery.Query   = "<OrderBy><FieldRef Name='OrderNumber'/></OrderBy>";
                                spQuery.Folder  = spFolder;

                                SPListItemCollection spItemCollection = spList.GetItems(spQuery);

                                foreach (SPItem spItem in spItemCollection)
                                {
                                    if (Convert.ToBoolean(spItem["Active"]))
                                    {
                                        banners += string.Format(liSlideShow, string.Format("{0}/{1}", site.MakeFullUrl(spFolder.ServerRelativeUrl), spItem["Name"]), spItem["Title"], spItem["Description"], spItem["RelatedLink"], '"');
                                    }
                                }
                            }
                            ulThumbList.InnerHtml = banners;
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message, AIAPortalFeatures.Infrastructure);
            }
        }
예제 #9
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.form1.Target    = "_self";
        this.Button1.Enabled = false;
        if (this.FileUpload3.PostedFile.ContentLength <= 0)
        {
            this.Label1.InnerText = "请选择文件。";
            return;
        }
        try
        {
            if (this.FileUpload3.PostedFile.ContentLength != 0)
            {
                SPWeb web = SPContext.Current.Web;
                web.AllowUnsafeUpdates = true;
                SPList list;
                try
                {
                    list = web.Lists["照片"];
                }
                catch (Exception)
                {
                    web.Lists.Add("照片", "临时照片存放库.", SPListTemplateType.PictureLibrary);
                    list = web.Lists["照片"];
                }

                SPFolderCollection spfolders = list.RootFolder.SubFolders;
                ArrayList          arr       = new ArrayList(spfolders.Count);
                //获取上传图片的文件名称(包含后缀)
                string[] imgTemp     = FileUpload3.PostedFile.FileName.Split('\\');
                string   imgFileName = imgTemp[imgTemp.Length - 1];

                foreach (SPFolder spf in spfolders)
                {
                    arr.Add(spf.Name);
                }
                if (!arr.Contains("Article"))
                {
                    list.RootFolder.SubFolders.Add("Article");
                }
                if (!arr.Contains("Comments"))
                {
                    list.RootFolder.SubFolders.Add("Comments");
                }
                list.RootFolder.SubFolders["Article"].Files.Add(imgFileName, FileUpload3.PostedFile.InputStream, true);//true覆盖原有文件
                web.AllowUnsafeUpdates = false;
                this.Label1.InnerText  = imgFileName + " 上传成功!单击“确定”插入图片。";
                this.StrSecond.Value   = web.ServerRelativeUrl + "/" + list.RootFolder.Url + "/Article/" + imgFileName;
            }
        }
        catch (Exception ex)
        {
            this.Button1.Enabled  = true;
            this.Label1.InnerText = ex.Message;
        }
    }
예제 #10
0
        public SPFolderCollectionInstance(ObjectInstance prototype, SPFolderCollection folderCollection)
            : this(prototype)
        {
            if (folderCollection == null)
            {
                throw new ArgumentNullException("folderCollection");
            }

            m_folderCollection = folderCollection;
        }
        /// <summary>Find Folder.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="oContainer">
        /// The o container.
        /// </param>
        /// <returns>A SPFolder
        /// </returns>
        private SPFolder FindFolder(string name, SPFolderCollection oContainer)
        {
            foreach (SPFolder f in oContainer)
            {
                if (f.Name == name)
                {
                    return(f);
                }
            }

            return(null);
        }
        /// <summary>Find Folder. </summary>
        /// <param name="name">The name.</param>
        /// <param name="sPFolderCollection">The SP Folder Collection container.</param>
        /// <returns>A SPFolder</returns>
        private SPFolder FindFolder(string name, SPFolderCollection sPFolderCollection)
        {
            foreach (SPFolder spFolder in sPFolderCollection)
            {
                if (spFolder.Name == name)
                {
                    return(spFolder);
                }
            }

            return(null);
        }
예제 #13
0
        internal void PopulateWithSubFolders(WBLocationTreeState treeState, TreeNodeCollection treeNodeCollection, String viewMode, SPFolder parentFolder)
        {
            SPFolderCollection subFolders = parentFolder.SubFolders;

            if (subFolders.Count > 0)
            {
                List <SPFolder> folders = new List <SPFolder>();
                foreach (SPFolder folder in subFolders)
                {
                    folders.Add(folder);
                }
                folders = folders.OrderBy(o => o.Name).ToList();

                foreach (SPFolder folder in folders)
                {
                    WBFolderTreeNode folderNode = new WBFolderTreeNode(folder);
                    TreeNode         node       = folderNode.AsTreeNode();

                    if (folder.SubFolders.Count > 0 || viewMode == VIEW_MODE__REPLACE)
                    {
                        node.Expanded         = false;
                        node.PopulateOnDemand = true;
                        if (viewMode == VIEW_MODE__BROWSE_FOLDERS)
                        {
                            node.SelectAction = TreeNodeSelectAction.Select;
                        }
                        else
                        {
                            node.SelectAction = TreeNodeSelectAction.Expand;
                        }
                    }
                    else
                    {
                        node.Expanded         = true;
                        node.PopulateOnDemand = false;
                        node.SelectAction     = TreeNodeSelectAction.Select;
                    }

                    treeNodeCollection.Add(node);
                }
            }
            else
            {
                if (viewMode == VIEW_MODE__REPLACE)
                {
                    PopulateWithDocuments(treeState, treeNodeCollection, viewMode, parentFolder);
                }
            }
        }
        public static SPFolder GetHighestFolder(SPWeb currentWeb, string targetLibraryName, string archiveFolderPrefix, ref int maxNumber)
        {
            try
            {
                SPListCollection webLists = currentWeb.Lists;
                webLists.IncludeRootFolder = true;

                SPList targetList = currentWeb.Lists[targetLibraryName];

                if (targetList.RootFolder.SubFolders.Count <= 1)
                {
                    targetList.RootFolder.SubFolders.Add(archiveFolderPrefix + "1");
                    ++maxNumber;
                    maxFolderIndex    = maxNumber;
                    highestFolderName = targetList.RootFolder.SubFolders[archiveFolderPrefix + maxNumber].Name;

                    return(targetList.RootFolder.SubFolders[archiveFolderPrefix + maxNumber.ToString()]);
                }

                SPFolderCollection folders = targetList.RootFolder.SubFolders;
                //SPFolder rootFolder = targetList.RootFolder;
                //SPFolderCollection folders = rootFolder.SubFolders.Folder.SubFolders;
                //MessageBox.Show(folders.Folder.SubFolders);
                //if (folders.Count == 0)
                //{
                //    targetList.RootFolder.SubFolders.Add(archiveFolderPrefix + "1");
                //    MessageBox.Show(folders[0].Name);
                //    return folders[0];
                //}
                ArrayList folderIndex = new ArrayList();

                foreach (SPFolder folder in folders)
                {
                    if (folder.Name.StartsWith(archiveFolderPrefix))
                    {
                        folderIndex.Add(int.Parse(folder.Name.Substring(archiveFolderPrefix.Length)));
                    }
                }
                maxNumber         = GetMaxNumber(folderIndex);
                maxFolderIndex    = maxNumber;
                highestFolderName = folders[archiveFolderPrefix + maxNumber.ToString()].Name;
                return(folders[archiveFolderPrefix + maxNumber.ToString()]);
            }
            catch (Exception ex)
            {
                throw new Exception("Problem while retrieving folders from " + currentWeb.Name + ex.Message);
            }
        }
        internal static List <FolderNodeInfo> ToFolderNodeInfo(this SPFolderCollection folders)
        {
            List <FolderNodeInfo> nodeInfos = new List <FolderNodeInfo>();

            foreach (SPFolder folder in folders)
            {
                FolderNodeInfo nodeInfo = new FolderNodeInfo
                {
                    Name = folder.Name,
                    Url  = folder.Url
                };
                nodeInfos.Add(nodeInfo);
            }

            return(nodeInfos);
        }
예제 #16
0
        public static List <FolderInfo> GetFoldersInFolder(SPFolder folder)
        {
            List <FolderInfo>  result = new List <FolderInfo>();
            FolderInfo         folderinfo;
            SPFolderCollection subFolders = folder.SubFolders;

            foreach (SPFolder subFolder in subFolders)
            {
                folderinfo      = new FolderInfo();
                folderinfo.Name = subFolder.Name;
                //folderinfo.Size = GetFolderSize(subFolder) / 1024;
                folderinfo.URL = subFolder.Url;
                //folderinfo.FilesNumber = GetNumberOfFilesInFolder(subFolder);
                result.Add(folderinfo);
            }
            return(result);
        }
예제 #17
0
        /// <summary>
        /// Get child folders for current parent folder.
        /// </summary>
        /// <param name="sb">The StringBuilder object which will hold the child folders' tree nodes JSON string.</param>
        /// <param name="parent_folder">The Parent Folder.</param>
        private void parse_subfolders(ref StringBuilder sb, SPFolder parent_folder)
        {
            SPFolderCollection folders = parent_folder.SubFolders;

            // first, fill these folders into arrays.
            string[]   folder_name_array = new string[folders.Count];
            SPFolder[] folder_array      = new SPFolder[folders.Count];
            for (int i = 0; i < folders.Count; i++)
            {
                folder_name_array[i] = folders[i].Name;
                folder_array[i]      = folders[i];
            }

            // sort the folders by their name, in ascent order.
            Array.Sort(folder_name_array, folder_array);
            // if current view is manually sorted by name in descent order,
            // then reverse the folder array.
            if (!string.IsNullOrEmpty(_sort_field) && !string.IsNullOrEmpty(_sort_dir) &&
                _sort_field.ToLower().Contains("name") &&
                _sort_dir.ToLower() == "desc")
            {
                Array.Reverse(folder_array);
            }

            // format the JSON string for each folder
            foreach (SPFolder child_folder in folder_array)
            {
                string child_folder_name = child_folder.Name.ToLower();
                if (child_folder_name == "forms" ||
                    child_folder_name == "attachments" ||
                    child_folder_name == "item")
                {
                    continue;                                                // exclude the built-in Forms folder.
                }
                format_json(ref sb, child_folder);
            }

            if (folders.Count > 0)
            {
                // We must remove the last comma.
                sb.Remove(sb.Length - 1, 1);
            }
        }
        private static void CopyDiscussionAttachments(SPListItem spliDiscussion, SPListItem targetItem)
        {
            try
            {
                SPFolder fldrDiscAttachments = spliDiscussion.Web.Folders["Lists"].SubFolders[spliDiscussion.ParentList.Title]
                                               .SubFolders["Attachments"].SubFolders[spliDiscussion.ID.ToString()];

                //if (fldrDiscAttachments.Files.Count > 0)
                targetItem.SystemUpdate(false);

                SPFolderCollection targetSubFoldersCollection = targetItem.Web.Folders["Lists"].SubFolders[targetItem.ParentList.Title]
                                                                .SubFolders["Attachments"].SubFolders;

                bool isFolderExist = false;

                foreach (SPFolder folder in targetSubFoldersCollection)
                {
                    if (folder.Name == targetItem.ID.ToString())
                    {
                        isFolderExist = true;
                        break;
                    }
                }

                if (isFolderExist)
                {
                    SPFolder targetDiscAttachments = targetSubFoldersCollection[targetItem.ID.ToString()];

                    foreach (SPFile file in targetDiscAttachments.Files)
                    {
                        targetItem.Attachments.DeleteNow(file.Name);
                    }
                }

                foreach (SPFile file in fldrDiscAttachments.Files)
                {
                    byte[] binFile = file.OpenBinary();
                    targetItem.Attachments.AddNow(file.Name, binFile);
                }
            }
            catch { }
        }
예제 #19
0
        private bool FolderExistsImplementation(SPFolderCollection folderCollection, string folderName)
        {
            if(folderCollection == null)
               {
               throw new ArgumentNullException("folderCollection");
               }
               if(string.IsNullOrEmpty(folderName))
               {
               throw new ArgumentException("folderName");
               }

            foreach(SPFolder f in folderCollection)
            {
                if(f.Name.Equals(folderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return true;
                }
            }
            return false;
        }
예제 #20
0
        void ddl_Controls_SelectedIndexChanged(object sender, EventArgs e)
        {
            string control  = ddl_Controls.SelectedValue;
            SPList stylelib = SPContext.Current.Site.RootWeb.Lists.TryGetList("Style Library");

            if (!string.IsNullOrEmpty(control))
            {
                SPFolder           controlFolder = stylelib.RootFolder.SubFolders[control];
                SPFolderCollection styleFolders  = controlFolder.SubFolders;
                List <SPFolder>    empty         = new List <SPFolder>();
                foreach (SPFolder folder in controlFolder.SubFolders)
                {
                    bool found = false;
                    foreach (SPFile file in folder.Files)
                    {
                        if (string.Compare("definition.xml", file.Name, true) == 0)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        empty.Add(folder);
                    }
                }
                ddl_Style.DataSource = styleFolders;
                ddl_Style.DataBind();

                foreach (SPFolder folder in empty)
                {
                    ddl_Style.Items.Remove(folder.Name);
                }

                if (ddl_Style.Items.Count == 0)
                {
                    ddl_Controls.Items.Remove(controlFolder.Name);
                }
            }
        }
예제 #21
0
    public string InsertImage()
    {
        try
        {
            if (this.FileUpload3.PostedFile.ContentLength != 0)
            {
                SPWeb web = SPContext.Current.Web;
                web.AllowUnsafeUpdates = true;

                SPList             list      = web.Lists["照片"];
                SPFolderCollection spfolders = list.RootFolder.SubFolders;
                ArrayList          arr       = new ArrayList(spfolders.Count);
                //获取上传图片的文件名称(包含后缀)
                string[] imgTemp     = FileUpload3.PostedFile.FileName.Split('\\');
                string   imgFileName = imgTemp[imgTemp.Length - 1];

                foreach (SPFolder spf in spfolders)
                {
                    arr.Add(spf.Name);
                }
                if (!arr.Contains("Article"))
                {
                    list.RootFolder.SubFolders.Add("Article");
                }
                if (!arr.Contains("Comments"))
                {
                    list.RootFolder.SubFolders.Add("Comments");
                }
                list.RootFolder.SubFolders["Article"].Files.Add(imgFileName, FileUpload3.PostedFile.InputStream, true);//true覆盖原有文件
                web.AllowUnsafeUpdates = false;
                return(imgFileName + " 上传成功!#" + web.ServerRelativeUrl + "/" + list.RootFolder.Url + "/" + imgFileName);
            }
            return("#");
        }
        catch (Exception ex)
        {
            this.Label1.InnerText = ex.Message;
            return("#");
        }
    }
예제 #22
0
        private void CreateDirectories(string path, SPFolderCollection oFolderCollection)
        {
            //Upload Multiple Files
            foreach (var oFi in new DirectoryInfo(path).GetFiles())
            {
                var fileStream = System.IO.File.OpenRead(oFi.FullName);
                var spfile     = oFolderCollection.Folder.Files.Add
                                     (oFi.Name, fileStream, true);
                spfile.Update();
            }

            //Upload Multiple Folders
            foreach (var oDi in new DirectoryInfo(path).GetDirectories())
            {
                var sFolderName = oDi.FullName.Split('\\')
                                  [oDi.FullName.Split('\\').Length - 1];
                var spNewFolder = oFolderCollection.Add(sFolderName);
                spNewFolder.Update();
                //Recursive call to create child folder
                CreateDirectories(oDi.FullName, spNewFolder.SubFolders);
            }
        }
예제 #23
0
        private void EnableAuditSettings(string site)
        {
            string auditLogLib  = "ForSiteAuditing";
            string auditLogPath = "/" + auditLogLib + "/";

            try
            {
                using (SPWeb webNew = new SPSite(site).OpenWeb())
                {
                    SPSite spSite = webNew.Site;
                    Guid   id     = webNew.Lists.Add(auditLogLib, "For Auditing", SPListTemplateType.DocumentLibrary);

                    SPList listdoc = webNew.Lists[id];
                    listdoc.OnQuickLaunch = false;
                    listdoc.Hidden        = true;
                    listdoc.Update();

                    SPDocumentLibrary  _MyDocLibrary = (SPDocumentLibrary)webNew.Lists[auditLogLib];
                    SPFolderCollection _MyFolders    = webNew.Folders;
                    string             folderURL     = spSite.Url + auditLogPath + "AuditReports";
                    _MyFolders.Add(folderURL);  //"ttp://adfsaccount:2222/My%20Documents/" + txtUpload.Text + "/");

                    _MyDocLibrary.Update();


                    spSite.TrimAuditLog = true;
                    spSite.AuditLogTrimmingRetention = 90;
                    Microsoft.Office.RecordsManagement.Reporting.AuditLogTrimmingReportCallout.SetAuditReportStorageLocation(spSite, folderURL);
                    //AuditLogTrimmingReportCallout.SetAuditReportStorageLocation

                    //   Audi
                    spSite.Audit.AuditFlags = SPAuditMaskType.Delete | SPAuditMaskType.Update | SPAuditMaskType.SecurityChange | SPAuditMaskType.SecurityChange | SPAuditMaskType.SchemaChange | SPAuditMaskType.Search;

                    //  site.Audit.AuditFlags =(Microsoft.SharePoint.SPAuditMaskType)auditOptions;
                    spSite.Audit.Update();
                }
            }
            catch { }
        }
예제 #24
0
        public static List <FolderInfo> GetFoldersInFolder(SPFolder folder)
        {
            List <FolderInfo>  result = new List <FolderInfo>();
            FolderInfo         folderinfo;
            SPFolderCollection subFolders = folder.SubFolders;

            foreach (SPFolder subFolder in subFolders)
            {
                // skip the default "Forms" folder which has no SPListItem
                if (subFolder.Name == "Forms" && subFolder.Item == null)
                {
                    continue;
                }
                folderinfo             = new FolderInfo();
                folderinfo.Name        = subFolder.Name;
                folderinfo.Size        = GetFolderSize(subFolder) / 1024;
                folderinfo.URL         = subFolder.Url;
                folderinfo.FilesNumber = GetNumberOfFilesInFolder(subFolder);
                result.Add(folderinfo);
            }
            return(result);
        }
예제 #25
0
        /// <summary>
        /// Copy subfolders and files of folder to a path
        /// </summary>
        /// <param name="myFolder">the folder that you want to get its subfolder and files</param>
        /// <param name="destinationPath">the path that you want to copy files of folder to</param>
        private void CreateSubDirectory(SPFolder myFolder, string destinationPath)
        {
            //get the document library of myFolder
            SPList             myList             = myFolder.DocumentLibrary;
            int                myListLength       = myList.Items.Count;
            SPListItem         myListItem         = myList.Items[0];
            string             tempPath           = destinationPath;
            SPFolderCollection myFolderCollection = myFolder.SubFolders;
            SPFileCollection   myFileCollection   = myFolder.Files;
            int                subFolderLength    = myFolderCollection.Count;
            int                subFileLength      = myFileCollection.Count;

            if (subFolderLength > 0 || subFileLength > 0)
            {
                if (subFolderLength > 0)
                {
                    for (int i = 0; i < subFolderLength; i++)
                    {
                        if (myFolderCollection[i].Name != "Forms")
                        {
                            tempPath += "\\" + myFolderCollection[i].Name;
                            if (!Directory.Exists(tempPath))
                            {
                                Directory.CreateDirectory(tempPath);
                            }
                            CreateSubDirectory(myFolderCollection[i], tempPath);
                            tempPath = destinationPath;
                        }
                    }
                }
                foreach (SPFile item in myFileCollection)
                {
                    DirectoryInfo myDirectoryInfo = new DirectoryInfo(destinationPath);
                    string        tempFilePath    = destinationPath;
                    tempFilePath += "\\" + item.Name;
                    if (File.Exists(tempFilePath))
                    {
                        File.Delete(tempFilePath);
                    }
                    using (FileStream myFileStream = new FileStream(tempFilePath, FileMode.Create, FileAccess.Write))
                    {
                        const int bufferSize = 4 * 1024 * 1024;
                        //byte[] fileContentBuffer = new byte[bufferSize];
                        byte[] fileContent = item.OpenBinary();
                        int    num         = fileContent.Length / bufferSize;
                        int    data        = fileContent.Length % bufferSize;
                        int    start       = 0;
                        while (start < num)
                        {
                            myFileStream.Write(fileContent, start * bufferSize, bufferSize);
                            start++;
                        }
                        myFileStream.Write(fileContent, start * bufferSize, data);
                    }
                    for (int a = 0; a < myListLength; a++)
                    {
                        if (myList.Items[a].Name == item.Name)
                        {
                            myListItem = myList.Items[a];
                            break;
                        }
                    }
                    myListItem["Source Path"] = tempFilePath;
                    myListItem.Update();
                    tempFilePath = destinationPath;
                }
            }
        }
        private void traverseFolders(SPFolderCollection folders)
        {
            foreach (SPFolder folder in folders)
            {
                Console.WriteLine("Folder: "+folder.Name);
                SPFileCollection files = folder.Files;

                for (int i=0; i<files.Count; i++)
                {
                    totalFileSize += files[i].Length;
                    Console.WriteLine("\tFile: "+files[i].Name.ToString());
                    fileCount ++;
                }

                traverseFolders(folder.SubFolders);

            }
        }
예제 #27
0
        public static void CreateFolderTree(string spsURL, string libName, string fileFolders)
        {
            using (SPSite site = new SPSite(spsURL)) {
                using (SPWeb web = site.OpenWeb()) {
                    string fullpath    = spsURL + "/" + libName;
                    char   charReplace = '_';
                    char[] sch_or      = { '|' };
                    char[] sch_star    = { '*' };
                    char[] sch_slash   = { '\\' };
                    string logFile     = "c:\\logs.txt";
                    string limitGroup  = "TestGroup";

                    using (System.IO.StreamReader sr = new System.IO.StreamReader(fileFolders)) {
                        while (!sr.EndOfStream)
                        {
                            string   s       = sr.ReadLine();
                            string   forPath = fullpath;
                            string[] sarr    = s.Split(sch_or);
                            sarr[0] = StringClean(sarr[0], charReplace);
                            string[] FPath         = sarr[0].Split(sch_slash);
                            string[] FCoordinators = sarr[1].Split(sch_star);
                            string[] FAuthors      = sarr[2].Split(sch_star);
                            string[] FReaders      = sarr[3].Split(sch_star);
                            string[] FApprovers    = sarr[4].Split(sch_star);
                            int      cols          = FPath.GetLength(FPath.Rank - 1);
                            for (int i = 1; i < cols; i++)
                            {
                                SPFolder exFolder = web.GetFolder(forPath + "/" + FPath[i]);
                                if (!exFolder.Exists)
                                {
                                    SPFolderCollection colFolders = web.GetFolder(forPath).SubFolders;
                                    colFolders.Add(FPath[i]);

                                    if (!exFolder.Exists)
                                    {
                                        WriteLog("===> Warning!!! Folder not create: " + forPath + "/" + FPath[i], logFile);
                                    }
                                }
                                if (i == cols - 1)
                                {
                                    foreach (string coord in FCoordinators)
                                    {
                                        // spsURL, libName, Path, User, Permission
                                        if (coord != "")
                                        {
                                            string[] scoord = coord.Split(sch_slash);
                                            if (scoord[0] == "EMEA")
                                            {
                                                AddToGroup(spsURL, limitGroup, coord);
                                                SetPermUser(spsURL, libName, forPath + "/" + FPath[i], coord, "Full Control");
                                            }
                                        }
                                    }
                                    foreach (string author in FAuthors)
                                    {
                                        if (author != "")
                                        {
                                            string[] sauthor = author.Split(sch_slash);
                                            if (sauthor[0] == "EMEA")
                                            {
                                                AddToGroup(spsURL, limitGroup, author);
                                                SetPermUser(spsURL, libName, forPath + "/" + FPath[i], author, "Contribute");
                                            }
                                        }
                                    }
                                    foreach (string reader in FReaders)
                                    {
                                        if (reader != "")
                                        {
                                            string[] sreader = reader.Split(sch_slash);
                                            if (sreader[0] == "EMEA")
                                            {
                                                AddToGroup(spsURL, limitGroup, reader);
                                                SetPermUser(spsURL, libName, forPath + "/" + FPath[i], reader, "Read");
                                            }
                                        }
                                    }
                                    foreach (string approver in FApprovers)
                                    {
                                        if (approver != "")
                                        {
                                            string[] sapprover = approver.Split(sch_slash);
                                            if (sapprover[0] == "EMEA")
                                            {
                                                AddToGroup(spsURL, limitGroup, approver);
                                                SetPermUser(spsURL, libName, forPath + "/" + FPath[i], approver, "Design");
                                            }
                                        }
                                    }
                                }
                                forPath += "/" + FPath[i];
                            }
                            forPath = "";
                        }
                    }
                }
            }
        }         // Close CreateFolderTree
예제 #28
0
        // Specific files according to user criteria in all sites
        public List <string> _getSpecificDocsInSiteCollection()
        {
            List <string>   FileRefs = new List <string>();
            SPSiteDataQuery DocFilesQuery;

            using (SPSite site = new SPSite(SiteUrl))
            {
                //using (SPWeb web = site.OpenWeb("/"))
                using (SPWeb web = site.OpenWeb())
                {
                    user = null;
                    if (UserLoginName != "")
                    {
                        user = web.EnsureUser(UserLoginName);// only when specific user
                    }
                    DocFilesQuery = new SPSiteDataQuery();

                    DocFilesQuery.Lists = "<Lists BaseType='1' /><Lists Hidden = \"TRUE\" />";// generic list // better!
                    //query.Lists = "<Lists ServerTemplate='101' /><Lists Hidden = \"TRUE\" />";// doc lib

                    DocFilesQuery.Query = CriteriaQuery();

                    // Select only needed columns: file reference
                    DocFilesQuery.ViewFields = "<FieldRef Name='FileRef' />";

                    // Search in all webs of the site collection
                    DocFilesQuery.Webs = "<Webs Scope='SiteCollection' />";

                    // constructring file url from GetSiteDataQuery
                    DataRowCollection filerows = web.GetSiteData(DocFilesQuery).Rows;
                    foreach (DataRow row in filerows)
                    {
                        // add relativeUrl into FileRef collection
                        FileRefs.Add(getRelativeFileRef(row["FileRef"].ToString()));
                    }


                    // specific attachments
                    SPListCollection listcoll = web.Lists;
                    foreach (SPList list in listcoll)
                    {
                        SPFolderCollection foldercoll = list.RootFolder.SubFolders;
                        foreach (SPFolder folder in foldercoll)
                        {
                            if (folder.Name == "Attachments")
                            {
                                SPFolderCollection attachmentFolders = folder.SubFolders;
                                foreach (SPFolder itemFolder in attachmentFolders)
                                {
                                    SPFileCollection files = itemFolder.Files;
                                    foreach (SPFile file in files)
                                    {
                                        if (CriteriaApply(file))
                                        {
                                            FileRefs.Add(file.ServerRelativeUrl);
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }

            return(FileRefs);
        }
예제 #29
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite siteCollection = properties.Feature.Parent as SPSite)
                {
                    using (SPWeb web = siteCollection.OpenWeb())
                    {
                        SPList list               = web.Lists["Documents"];
                        string memGrpName         = "Folder_Templates_Member";
                        string memPermName        = "PWC Contribute";
                        string visGrpName         = "Folder_Templates_Visitor";
                        string visPermName        = "Read";
                        string blackbeltGroupName = "BlackBelt";
                        string greenbeltGroupName = "GreenBelt";
                        FormHomePage(siteCollection.OpenWeb().Url + "/SitePages/BreakThroughProcertProjectsTracking.aspx", "Header", "BreakThroughProcertProjectsTracking.aspx", "");
                        AddGroupUsers(siteCollection.OpenWeb().Url + "/SitePages/AddGroupUsers.aspx", "Header", "", "");
                        EmailCommentNotification(siteCollection.OpenWeb().Url + "/SitePages/EmailNotification.aspx", "Header", "EmailNotification.aspx", "");
                        CreateList(web, "Lookup_Organization_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_Organization_List", "Lookup_Organization_List");
                        CreateList(web, "Lookup_ProcertMultilingual_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_ProcertMultilingual_List", "Lookup_ProcertMultilingual_List");
                        CreateList(web, "Lookup_Plant_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_Plant_List", "Lookup_Plant_List");
                        CreateList(web, "Lookup_ProjectType_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_ProjectType_List", "Lookup_ProjectType_List");
                        CreateList(web, "Lookup_ProjectTeamData_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_ProjectTeamData_List", "Lookup_ProjectTeamData_List");
                        CreateList(web, "Lookup_ProjectTeamRole_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_ProjectTeamRole_List", "Lookup_ProjectTeamRole_List");
                        CreateList(web, "BreakThroughProcertProjectsTracking", "This List Is used In BreakThroughProcertProjectsTracking.", "BreakThrough Procert Projects Tracking", "BreakThroughProcertProjectsTracking");
                        CreateList(web, "Lookup_OtherAttachments_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_OtherAttachments_List", "Lookup_OtherAttachments_List");
                        CreateList(web, "Lookup_ProcertEmailConfiguration", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_ProcertEmailConfiguration", "Lookup_ProcertEmailConfiguration");

                        CreateList(web, "Lookup_Metricsarea_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_Metricsarea_List", "Lookup_Metricsarea_List");

                        CreateDiscussionList(web);
                        DeletecolumninDiscussion(web);
                        AddColumnToDiscussion(web);

                        if (!ContainsGroup(web.SiteGroups, blackbeltGroupName))
                        {
                            CreateSubSiteGroup(web, blackbeltGroupName, memPermName, "This is Six Sigma Black Belt Group");
                        }
                        if (!ContainsGroup(web.SiteGroups, greenbeltGroupName))
                        {
                            CreateSubSiteGroup(web, greenbeltGroupName, memPermName, "This is Six Sigma Green Belt Group");
                        }
                        if (!ContainsGroup(web.SiteGroups, memGrpName))
                        {
                            CreateSFGroup(web, memGrpName, memPermName, "member");
                        }
                        if (!ContainsGroup(web.SiteGroups, visGrpName))
                        {
                            CreateSFGroup(web, visGrpName, visPermName, "visitor");
                        }
                        SPFolderCollection spFolderColl = list.RootFolder.SubFolders;
                        if (!web.GetFolder(web.ServerRelativeUrl + list.RootFolder + "/Templates").Exists)
                        {
                            SPFolder folder        = spFolderColl.Add("Templates");
                            SPContentType secFolCT = list.ContentTypes["PWC Secure Folder"];
                            folder.Item[SPBuiltInFieldId.ContentTypeId] = secFolCT.Id;
                            folder.Item.IconOverlay = "SecureFolderIcon.png";
                            folder.Item.SystemUpdate();
                            string[] FolderUrls = { "Info", "Info/Background", "Info/Problem Statement", "Info/Project Metrics", "Info/Benefits", "Info/Costs", "Info/Financial Analysis", "Info/Milestones", "Updates", "Updates/Quad Charts", "Gates", "Gates/Define", "Gates/Measure", "Gates/Analyze", "Gates/Improve", "Gates/Control", "Final Report" };
                            CreateSubFolders(FolderUrls, folder);
                            SetFolderPermissions(web, "Templates", memGrpName, visGrpName, blackbeltGroupName, greenbeltGroupName, folder);
                        }

                        GrantPermissionOnSitePages(web);
                    }
                }
            });
        }
예제 #30
0
        /// <summary>
        /// get the sub node of all directories and files from document library
        /// </summary>
        /// <param name="myNode">the xmlNode to save the attributes and innerText</param>
        /// <param name="myFolder">the SPFolder that you want to get its all sub directories and files</param>
        /// <param name="myXmlDoc">the XmlDocument to save your information</param>
        /// <returns></returns>
        private XmlNode GetSubNodeAllDirectory(XmlNode myNode, SPFolder myFolder, XmlDocument myXmlDoc)
        {
            SPFolderCollection myFolderCollection = myFolder.SubFolders;
            SPFileCollection   myFileCollection   = myFolder.Files;
            int myFolderLength = myFolderCollection.Count;
            int myFileLength   = myFileCollection.Count;
            int totalLength    = myFolderLength + myFileLength;

            if (myFolderLength > 0 || myFileLength > 0)
            {
                XmlNode[] myXmlNode = new XmlNode[totalLength];
                if (myFolderLength > 0)
                {
                    for (int i = 0; i < myFolderLength; i++)
                    {
                        if (myFolderCollection[i].Name != "Forms")
                        {
                            myXmlNode[i] = myXmlDoc.CreateElement(ChangeString(myFolderCollection[i].Name));
                            SPList myList = myFolder.DocumentLibrary;

                            SPListItem myListItem = null;
                            //myListItem = myFolder.Item;
                            for (int k = 0; k < myList.Folders.Count; k++)
                            {
                                if (myList.Folders[k].Name.ToString() == myFolderCollection[i].Name.ToString())
                                {
                                    myListItem = myList.Folders[k];
                                }
                            }
                            AddProperitys(myXmlNode[i], myXmlDoc, myListItem);
                            myFolder = myFolderCollection[i];
                            GetSubNodeAllDirectory(myXmlNode[i], myFolder, myXmlDoc);
                            myFolder = myFolder.ParentFolder;
                        }
                    }
                }
                for (int j = 0; j < myFileLength; j++)
                {
                    SPList     myList     = myFileCollection[j].DocumentLibrary;
                    SPListItem myListItem = null;
                    // myListItem = myFileCollection[j].Item;
                    for (int k = 0; k < myList.Items.Count; k++)
                    {
                        if (myList.Items[k].Name.ToString() == myFileCollection[j].Name.ToString())
                        {
                            myListItem = myList.Items[k];
                        }
                    }
                    myXmlNode[j + myFolderLength] = myXmlDoc.CreateElement(ChangeString(myFileCollection[j].Name));
                    AddProperitys(myXmlNode[j + myFolderLength], myXmlDoc, myListItem);
                }
                for (int i = 0; i < totalLength; i++)
                {
                    if (myXmlNode[i] != null)
                    {
                        myNode.AppendChild(myXmlNode[i]);
                    }
                }
            }
            return(myNode);
        }
예제 #31
0
        private static void EnumerateFolders(SPFolderCollection copyFolders)
        {
            foreach (SPFolder subFolder in copyFolders)
            {
                if (subFolder.Name != "Forms")
                {
                    SPFileCollection subFiles = subFolder.Files;

                    CopyFiles(subFiles);
                }

                SPFolderCollection subFolders = subFolder.SubFolders;

                EnumerateFolders(subFolders);
            }
        }
예제 #32
0
        private Dictionary<string, SPFolder> sortFolders(SPFolderCollection folders)
        {
            Dictionary<string, SPFolder> sortedFolders = new Dictionary<string, SPFolder>();

            foreach (SPFolder folder in folders)
            {
                sortedFolders.Add(folder.Name, folder);
            }

            return sortedFolders;
        }
예제 #33
0
        private void SyncStyles(string style)
        {
            try
            {
                string control  = ddl_Controls.SelectedValue;
                SPList stylelib = SPContext.Current.Site.RootWeb.Lists.TryGetList("Style Library");
                if (!string.IsNullOrEmpty(control))
                {
                    SPFolder           controlFolder = stylelib.RootFolder.SubFolders[control];
                    SPFolderCollection styleFolders  = controlFolder.SubFolders;
                    bool            exists           = false;
                    List <SPFolder> empty            = new List <SPFolder>();
                    foreach (SPFolder folder in controlFolder.SubFolders)
                    {
                        bool found = false;
                        foreach (SPFile file in folder.Files)
                        {
                            if (string.Compare("definition.xml", file.Name, true) == 0)
                            {
                                string content = SPContext.Current.Site.RootWeb.GetFileAsString(file.Url);
                                if (content.Contains("Processor=\"Design\""))
                                {
                                    found = true;
                                }
                                break;
                            }
                        }

                        if (!found)
                        {
                            empty.Add(folder);
                        }

                        if (folder.Name == style)
                        {
                            exists = true;
                        }
                    }

                    ddl_Style.DataSource = styleFolders;
                    if (exists)
                    {
                        ddl_Style.SelectedValue = style;
                    }
                    else
                    {
                        ddl_Style.SelectedIndex = 0;
                    }
                    ddl_Style.DataBind();

                    foreach (SPFolder folder in empty)
                    {
                        ddl_Style.Items.Remove(folder.Name);
                    }

                    if (ddl_Style.Items.Count == 0)
                    {
                        ddl_Controls.Items.Remove(controlFolder.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }