public SPListItem Get(string url, Guid listId, string listItemId) { var item = new SPListItem(); SPListItemGetOptions options = null; int itemId; if (int.TryParse(listItemId, out itemId)) { options = new SPListItemGetOptions(itemId); } Guid uniqueId; if (Guid.TryParse(listItemId, out uniqueId)) { options = new SPListItemGetOptions(uniqueId); } if (options != null && !item.Errors.Any()) { options.Url = url; try { item = PublicApi.ListItems.Get(listId, options); } catch (InvalidOperationException ex) { item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidId))); } catch (SPInternalException ex) { item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.NotFound))); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.Get() method for SPWebUrl: {1} ListId: {2} ListItemId: {3}. The exception message is: {4}", ex.GetType(), url, listId, listItemId, ex.Message); SPLog.UnKnownError(ex, message); item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.UnknownError))); } } else { item.Errors.Add(new Error(typeof(ArgumentException).ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidId))); } return(item); }
public bool CanEdit(string url, Guid listId, string listItemId) { var canEdit = false; try { SPListItemGetOptions options = null; int itemId; if (int.TryParse(listItemId, out itemId)) { options = new SPListItemGetOptions(itemId); } Guid uniqueId; if (Guid.TryParse(listItemId, out uniqueId)) { options = new SPListItemGetOptions(uniqueId); } if (options == null) { throw new Exception("ListItemId cannot be empty."); } options.Url = url; canEdit = PublicApi.ListItems.CanEdit(listId, options); } catch (InvalidOperationException) { } catch (SPInternalException) { } catch (Exception ex) { var message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.CanEdit() method ListItemId: {1} ListId: {2} Url: {3}. The exception message is: {4}", ex.GetType(), listItemId, listId, url, ex.Message); SPLog.UnKnownError(ex, message); } return(canEdit); }