protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite sitecollection = new SPSite(Url)) { using (SPWeb web = sitecollection.OpenWeb()) { SPList list = web.Lists["Aufgaben"]; SPListItem listitem = list.Items.Add(); SPContentType ConType = list.ContentTypes[ContentType.ToString()]; if (ConType != null) { listitem["ContentTypeId"] = ConType.Id; } if (!String.IsNullOrEmpty(Title) & listitem.Fields.ContainsField("Title")) { listitem["Title"] = Title.ToString(); } if (!String.IsNullOrEmpty(Descript) & (listitem.Fields.ContainsField("Beschreibung") | listitem.Fields.ContainsField("Body"))) { listitem["Beschreibung"] = Descript.ToString(); } if (!String.IsNullOrEmpty(Link) & listitem.Fields.ContainsField("Link")) { LinkFieldValue lfValue = new LinkFieldValue(); lfValue.NavigateUrl = Link.ToString(); lfValue.Text = "Link zu Dokument"; lfValue.UseDefaultIcon = false; listitem["Link"] = lfValue; } if (!String.IsNullOrEmpty(AccountName) & listitem.Fields.ContainsField("AssignedTo")) { SPUserCollection users = web.Users; SPUser user = UserExists(users, AccountName.ToString()); if (user != null) { listitem["AssignedTo"] = user; } else { SPGroupCollection groups = web.Groups; if (GroupExists(groups, AccountName.ToString())) { listitem["AssignedTo"] = web.Groups[AccountName.ToString()]; } } } if (!String.IsNullOrEmpty(Quelle) & listitem.Fields.ContainsField("Aufgabenquelle")) { listitem["Aufgabenquelle"] = Quelle.ToString(); } if ((TargetDate.ToString() != string.Empty) & (listitem.Fields.ContainsField("DueDate"))) { listitem["DueDate"] = TargetDate; } if (listitem.Fields.ContainsField("WorkflowID")) { listitem["WorkflowID"] = WorkflowID; } listitem.Update(); TaskID = listitem.ID; } } }); return(base.Execute(executionContext)); }
/// <summary> /// Scans through the fields in the list to check supported fields for broken links /// </summary> /// <param name="Item">The list item to check</param> /// <param name="PageUri">The full url of the page</param> private void ScanListFields(SPListItem Item, Uri PageUri) { foreach (SPField field in Item.Fields) { switch (field.TypeAsString) { case "HTML": case "Link": try { if ((Item[field.Title] != null) && !string.IsNullOrEmpty(Item[field.Title].ToString())) { StringCollection AllLinks = LinkCheckerUtilities.GetLinksFromHTML(Item[field.Title].ToString()); // Make all the links relative then validate foreach (string Url in AllLinks) { try { ValidateLink(PageUri, new Uri(PageUri, Url), Url, BrokenLinkType.HtmlField); } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error checking link '{0}' at '{1}'", Url, PageUri.ToString())); } } } } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error: Unable to check links for field {0} at {1} - Error Message: {2}, Stack Trace: {3}", field.Title, Item.Url, ex.Message, ex.StackTrace)); } break; case "Note": SPFieldMultiLineText fieldAsMultiLineText = (SPFieldMultiLineText)field; if ((fieldAsMultiLineText.RichText) && (Item[field.Title] != null) && !string.IsNullOrEmpty(Item[field.Title].ToString())) { StringCollection AllLinks = LinkCheckerUtilities.GetLinksFromHTML(Item[field.Title].ToString()); foreach (string Url in AllLinks) { try { ValidateLink(PageUri, new Uri(PageUri, Url), Url, BrokenLinkType.HtmlField); } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error checking link '{0}' at '{1}'", Url, PageUri.ToString())); } } } break; case "URL": try { if ((Item[field.Title] != null) && !string.IsNullOrEmpty(Item[field.Title].ToString())) { SPFieldUrlValue UrlValue = new SPFieldUrlValue(Item[field.Title].ToString()); try { ValidateLink(PageUri, new Uri(UrlValue.Url), UrlValue.Url, BrokenLinkType.LinkField); } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error checking link '{0}' at '{1}'", UrlValue.Url, PageUri.ToString())); } } } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error: Unable to check links for field {0} at {1} - Error Message: {2}, Stack Trace: {3}", field.Title, Item.Url, ex.Message, ex.StackTrace)); } break; case "SPLink": try { if ((Item[field.Title] != null) && !string.IsNullOrEmpty(Item[field.Title].ToString())) { try { string Url = new LinkFieldValue(Item[field.Title].ToString()).NavigateUrl; Uri uri = new Uri(PageUri, Url); ValidateLink(PageUri, uri, Url, BrokenLinkType.LinkField); } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error checking link '{0}' at '{1}'", Item[field.Title].ToString(), PageUri.ToString())); } } } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error: Unable to check links for field {0} at {1} - Error Message: {2}, Stack Trace: {3}", field.Title, Item.Url, ex.Message, ex.StackTrace)); } break; case "Image": try { if ((Item[field.Title] != null) && !string.IsNullOrEmpty(Item[field.Title].ToString())) { ImageFieldValue ImgValue = new ImageFieldValue(Item[field.Title].ToString()); try { Uri uri = new Uri(PageUri, ImgValue.ImageUrl); ValidateLink(PageUri, uri, ImgValue.ImageUrl, BrokenLinkType.LinkField); } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error checking image link '{0}' at '{1}'", ImgValue.ImageUrl, PageUri.ToString())); } } } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error: Unable to check links for field {0} at {1} - Error Message: {2}, Stack Trace: {3}", field.Title, Item.Url, ex.Message, ex.StackTrace)); } break; case "SummaryLinks": try { if ((Item[field.Title] != null) && !string.IsNullOrEmpty(Item[field.Title].ToString())) { SummaryLinkFieldValue LinksFieldValue = new SummaryLinkFieldValue(Item[field.Title].ToString()); foreach (SummaryLink Link in LinksFieldValue.SummaryLinks) { try { ValidateLink(PageUri, new Uri(Link.LinkUrl), Link.LinkUrl, BrokenLinkType.SummaryLinkField); } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error checking link '{0}' at '{1}'", Link.LinkUrl, PageUri.ToString())); } } } } catch (Exception ex) { Utility.LogError(ex, string.Format("LinkChecker: Error: Unable to check links for field {0} at {1} - Error Message: {2}, Stack Trace: {3}", field.Title, Item.Url, ex.Message, ex.StackTrace)); } break; } } }