public override object GetResponseData(HttpContext context) { try { string location = context.Request.Form["Location"]; System.IO.BinaryReader br = new System.IO.BinaryReader(context.Request.InputStream); int bytesToRead = (int)context.Request.InputStream.Length; var content = br.ReadBytes(bytesToRead); var metaData = new Hashtable() { { "Geo", location } }; SPWeb web = new SPSite(SPContext.Current.Web.Url).OpenWeb(); web.AllowUnsafeUpdates = true; var docLibrary = web.GetFolder("Shared Documents"); var files = docLibrary.Files; var addedFile = files.Add("Shared Documents/file.png", content, metaData); return(new { ID = addedFile.Item.ID, URL = addedFile.Url }); } catch (Exception x) { throw; } }
private void CheckFolders(XmlNode siteNode, string url) { using (SPWeb web = new SPSite(url).OpenWeb()) { XmlNodeList folderNodes = siteNode.SelectNodes("folder[@list='false']"); foreach (XmlNode folderNode in folderNodes) { string folderTitle = folderNode.Attributes["folder"].Value; string folderUrl = folderNode.Attributes["url"].Value; int itemCount = Convert.ToInt32(folderNode.Attributes["count"].Value); try { SPFolder folder = web.GetFolder(folderUrl); SPListItem item = folder.Item; int fileCount = folder.Files.Count; if (itemCount != fileCount) { output.Append(string.Format("folder: {0}, count differs. Source has {1} files and target has {2}: " + Environment.NewLine, folderUrl, itemCount, fileCount)); } } catch { output.Append(string.Format("folder missing: {0,20}" + Environment.NewLine, folderUrl)); } } } }
private void CheckFolders(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.Files) { return; } using (SPWeb web = new SPSite(url).OpenWeb()) { XmlNodeList folderNodes = siteNode.SelectNodes("folder[@list='false']"); foreach (XmlNode folderNode in folderNodes) { string folderTitle = folderNode.Attributes["folder"].Value; string folderUrl = folderNode.Attributes["url"].Value; output.Append(string.Format("checking folder: {0}" + Environment.NewLine, folderUrl)); try { SPFolder folder = web.GetFolder(folderUrl); SPListItem item = folder.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 = folderNode.SelectNodes("principal[@Group='true']"); CheckGroups(web, item, principalGroupNodes); XmlNodeList principalUserNodes = folderNode.SelectNodes("principal[@Group='false']"); CheckUsers(web, item, principalUserNodes); } else { output.Append(string.Format("target folder: {0,20}, is inheriting permissions" + Environment.NewLine, folderUrl)); } } catch { output.Append(string.Format("folder missing: {0,20}" + Environment.NewLine, folderUrl)); } } } }
private void CheckFolders(XmlNode siteNode, string url) { using (SPWeb web = new SPSite(url).OpenWeb()) { XmlNodeList alertNodes = siteNode.SelectNodes("alert[@type='List']"); foreach (XmlNode alertNode in alertNodes) { string alertTitle = alertNode.Attributes["title"].Value; string listTitle = alertNode.Attributes["list"].Value; string loginName = alertNode.Attributes["user"].Value; string objectType = alertNode.Attributes["object"].Value; bool isFolder = objectType.ToLower().Equals("folder"); if (isFolder) { string itemUrl = alertNode.Attributes["url"].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); SPFolder folder = web.GetFolder(itemUrl); SPListItem item = folder.Item; SPAlert newAlert = user.Alerts.Add(); newAlert.Title = alertTitle; newAlert.AlertType = SPAlertType.Item; 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)); } } } } }