private ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var list = LookupList(listItemModelHost, wpModel); View view = null; if (wpModel.ViewId.HasValue && wpModel.ViewId != default(Guid)) view = list.Views.GetById(wpModel.ViewId.Value); else if (!string.IsNullOrEmpty(wpModel.ViewName)) view = list.Views.GetByTitle(wpModel.ViewName); context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); context.Load(list, l => l.DefaultView); if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; if (wpModel.TitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) result.TitleUrl = list.DefaultViewUrl; } return result; }
internal static ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, string webUrl, Guid? webId, string listUrl, string listTitle, Guid? listId, string viewTitle, Guid? viewId, string webPartTitleUrl ) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var targetWeb = listItemModelHost.HostWeb; if (webId.HasGuidValue() || !string.IsNullOrEmpty(webUrl)) { targetWeb = new LookupFieldModelHandler() .GetTargetWeb(listItemModelHost.HostClientContext.Site, webUrl, webId); } var list = LookupList(targetWeb, listUrl, listTitle, listId); View view = null; if (viewId.HasValue && viewId != default(Guid)) view = list.Views.GetById(viewId.Value); else if (!string.IsNullOrEmpty(viewTitle)) view = list.Views.GetByTitle(viewTitle); context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); // TODO, https://github.com/SubPointSolutions/spmeta2/issues/765 // list.DefaultView is not available, so a full fetch for list view is a must for SP2010. #if !NET35 context.Load(list, l => l.DefaultView); #endif if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); #if !NET35 result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; #endif result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; result.List = list; if (webPartTitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) result.TitleUrl = list.DefaultViewUrl; } #if !NET35 result.DefaultViewId = list.DefaultView.Id; #endif return result; }
protected override void OnBeforeDeploy(ListItemModelHost host, WebPartDefinitionBase webpart) { base.OnBeforeDeploy(host, webpart); var context = host.HostClientContext; var wpModel = webpart.WithAssertAndCast<XsltListViewWebPartDefinition>("model", value => value.RequireNotNull()); // save the old default view ID, then restore in OnAfterDeploy _currentListBindContext = LookupBindContext(host, wpModel); if (_currentListBindContext.TargetView != null) { _currentListBindContext.TargetView.DefaultView = true; _currentListBindContext.TargetView.Update(); context.ExecuteQueryWithTrace(); } }
private ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel, out Guid webId) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var list = LookupList(listItemModelHost, wpModel, out webId); View view = null; if (wpModel.ViewId.HasValue && wpModel.ViewId != default(Guid)) { view = list.Views.GetById(wpModel.ViewId.Value); } else if (!string.IsNullOrEmpty(wpModel.ViewName)) { view = list.Views.GetByTitle(wpModel.ViewName); } else if (!string.IsNullOrEmpty(wpModel.ViewUrl)) { var views = list.Views; context.Load(views, v => v.Include(r => r.ServerRelativeUrl)); context.ExecuteQueryWithTrace(); view = views.ToArray() .FirstOrDefault(v => v.ServerRelativeUrl.ToUpper().EndsWith(wpModel.ViewUrl.ToUpper())); } context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); context.Load(list, l => l.DefaultView); if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; if (wpModel.TitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) { result.TitleUrl = list.DefaultViewUrl; } } return(result); }
internal static ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, string webUrl, Guid?webId, string listUrl, string listTitle, Guid?listId, string viewUrl, string viewTitle, Guid?viewId, string webPartTitleUrl ) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var targetWeb = listItemModelHost.HostWeb; if (webId.HasGuidValue() || !string.IsNullOrEmpty(webUrl)) { var lookupFieldModelHandler = new LookupFieldModelHandler(); targetWeb = lookupFieldModelHandler .GetTargetWeb( listItemModelHost.HostClientContext.Site, webUrl, webId, listItemModelHost); result.WebId = targetWeb.Id; } var list = LookupList(targetWeb, listUrl, listTitle, listId); View view = null; if (viewId.HasValue && viewId != default(Guid)) { view = list.Views.GetById(viewId.Value); } else if (!string.IsNullOrEmpty(viewTitle)) { view = list.Views.GetByTitle(viewTitle); } else if (!string.IsNullOrEmpty(viewUrl)) { var views = list.Views; context.Load(views, v => v.Include(r => r.ServerRelativeUrl)); context.ExecuteQueryWithTrace(); view = views.ToArray() .FirstOrDefault(v => v.ServerRelativeUrl.ToUpper().EndsWith(viewUrl.ToUpper())); } context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); // TODO, https://github.com/SubPointSolutions/spmeta2/issues/765 // list.DefaultView is not available, so a full fetch for list view is a must for SP2010. #if !NET35 context.Load(list, l => l.DefaultView); #endif if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); #if !NET35 result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; #endif result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; result.List = list; result.List = list; if (webPartTitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) { result.TitleUrl = list.DefaultViewUrl; } } #if !NET35 result.DefaultViewId = list.DefaultView.Id; #endif return(result); }
internal static ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, string webUrl, Guid? webId, string listUrl, string listTitle, Guid? listId, string viewTitle, Guid? viewId, string webPartTitleUrl ) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var targetWeb = listItemModelHost.HostWeb; if (webId.HasGuidValue() || !string.IsNullOrEmpty(webUrl)) { targetWeb = new LookupFieldModelHandler() .GetTargetWeb(listItemModelHost.HostClientContext.Site, webUrl, webId); } var list = LookupList(targetWeb, listUrl, listTitle, listId); View view = null; if (viewId.HasValue && viewId != default(Guid)) view = list.Views.GetById(viewId.Value); else if (!string.IsNullOrEmpty(viewTitle)) view = list.Views.GetByTitle(viewTitle); context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); context.Load(list, l => l.DefaultView); if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; result.List = list; if (webPartTitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) result.TitleUrl = list.DefaultViewUrl; } result.DefaultViewId = list.DefaultView.Id; return result; }