Esempio n. 1
0
        private void CheckFiles(XmlNode siteNode, string url)
        {
            bool containsIgnoreInheritance = ContainsAttribute("ignoreinheritance", siteNode);
            bool containsImportOptions     = ContainsAttribute("import", siteNode);

            bool ignoreInheritance = containsIgnoreInheritance ?
                                     Boolean.Parse(siteNode.Attributes["ignoreinheritance"].Value) :
                                     true;

            ImportOptions importOptions = containsImportOptions ?
                                          (ImportOptions)Enum.Parse(typeof(ImportOptions), siteNode.Attributes["import"].Value) :
                                          ImportOptions.All;

            if (importOptions == ImportOptions.Folders)
            {
                return;
            }

            using (SPWeb web = new SPSite(url).OpenWeb())
            {
                XmlNodeList fileNodes = siteNode.SelectNodes("file");

                foreach (XmlNode fileNode in fileNodes)
                {
                    string fileTitle = fileNode.Attributes["file"].Value;
                    string fileUrl   = fileNode.Attributes["url"].Value;
                    output.Append(string.Format("checking file: {0}" + Environment.NewLine, fileUrl));
                    try
                    {
                        SPFile     file = web.GetFile(fileUrl);
                        SPListItem item = file.Item;

                        bool breakInheritance = !item.HasUniqueRoleAssignments && !ignoreInheritance;
                        bool applyPermissions = item.HasUniqueRoleAssignments || breakInheritance;

                        if (applyPermissions)
                        {
                            if (breakInheritance)
                            {
                                output.Append(string.Format("Breaking Inheritance!" + Environment.NewLine));
                                item.BreakRoleInheritance(false, false);
                            }

                            XmlNodeList principalGroupNodes = fileNode.SelectNodes("principal[@Group='true']");
                            CheckGroups(web, item, principalGroupNodes);

                            XmlNodeList principalUserNodes = fileNode.SelectNodes("principal[@Group='false']");
                            CheckUsers(web, item, principalUserNodes);
                        }
                        else
                        {
                            output.Append(string.Format("target file: {0,20}, is inheriting permissions" + Environment.NewLine, fileUrl));
                        }
                    }
                    catch { output.Append(string.Format("file missing: {0,20}" + Environment.NewLine, fileUrl)); }
                }
            }
        }
Esempio n. 2
0
        private void CheckItems(XmlNode siteNode, string url)
        {
            using (SPWeb web = new SPSite(url).OpenWeb())
            {
                XmlNodeList alertNodes = siteNode.SelectNodes("alert[@type='Item']");
                foreach (XmlNode alertNode in alertNodes)
                {
                    string alertTitle = alertNode.Attributes["title"].Value;
                    string listTitle  = alertNode.Attributes["list"].Value;
                    string loginName  = alertNode.Attributes["user"].Value;
                    int    itemId     = Int32.Parse(alertNode.Attributes["id"].Value);
                    string itemUrl    = alertNode.Attributes["url"].Value;
                    string objectType = alertNode.Attributes["object"].Value;

                    output.Append(string.Format("user: {0,20}...", loginName));
                    try
                    {
                        SPList list = web.Lists[listTitle];
                        SPClaimProviderManager cpm = SPClaimProviderManager.Local;
                        SPClaim userClaim          = cpm.ConvertIdentifierToClaim(loginName, SPIdentifierTypes.WindowsSamAccountName);
                        SPUser  user = web.EnsureUser(userClaim.ToEncodedString());

                        string      eventType   = alertNode.Attributes["event"].Value;
                        SPEventType spEventType = (SPEventType)Enum.Parse(typeof(SPEventType), eventType);

                        string           eventFrequency   = alertNode.Attributes["frequency"].Value;
                        SPAlertFrequency spAlertFrequency = (SPAlertFrequency)Enum.Parse(typeof(SPAlertFrequency), eventFrequency);

                        string      type        = alertNode.Attributes["type"].Value;
                        SPAlertType spAlertType = (SPAlertType)Enum.Parse(typeof(SPAlertType), type);

                        SPListItem item = null;
                        if (list.BaseType == SPBaseType.DocumentLibrary)
                        {
                            SPFile file = web.GetFile(itemUrl);
                            item = file.Item;
                        }
                        else
                        {
                            item = list.GetItemById(itemId);
                        }

                        SPAlert newAlert = user.Alerts.Add();

                        newAlert.Title            = alertTitle;
                        newAlert.AlertType        = spAlertType;
                        newAlert.Item             = item;
                        newAlert.DeliveryChannels = SPAlertDeliveryChannels.Email;
                        newAlert.EventType        = spEventType;
                        newAlert.AlertFrequency   = spAlertFrequency;
                        newAlert.Status           = SPAlertStatus.On;
                        newAlert.Update(false);
                        output.Append(string.Format("Complete" + Environment.NewLine));
                    }
                    catch (Exception ex) { output.Append(string.Format("error: {0,20}" + Environment.NewLine, ex.Message)); }
                }
            }
        }
Esempio n. 3
0
        public string DownloadAttachment(string attachment)
        {
            string sWeb    = System.Configuration.ConfigurationManager.AppSettings["Server"];
            string sList   = System.Configuration.ConfigurationManager.AppSettings["List"];
            string tempXml = string.Empty;

            using (SPWeb web = new SPSite(sWeb).OpenWeb())
            {
                SPList list = web.Lists[sList];

                string fileUrl = string.Format("{0}/Attachments/{1}/{2}",
                                               list.RootFolder.ServerRelativeUrl,
                                               this.id,
                                               attachment);
                SPFile file = web.GetFile(fileUrl);
                byte[] data = file.OpenBinary();

                //content = System.Text.Encoding.UTF8.GetString(data);
                tempXml = Scheduler.Instance.CreateTmpFile();
                System.IO.File.WriteAllBytes(tempXml, data);
            }

            return(tempXml);
        }