Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, January 27, 2012 5:29 AM
Hi,
I have two discussion board list "Discussion A" and "Discussion B". In "Discussion A", I have create a custom view "sanz view" and I try to copy that view from that list to "Discussion B". The view gets created but when i choose that view to see my discussion, I couldn't see any contents in it. When i clicked "flat" or "thread" view i could see my discussion items but couldn't see when i choose "sanz view".
Here is my code
string aa = "http://sanzsp10:35101/sites/MySimpleTarget";
using (SPSite site = new SPSite(aa))
{
SPWeb web = site.OpenWeb();
SPList sourceList = web.Lists["Discussion A"];
SPList targetList = web.Lists["Discussion B"];
var viewFields = new StringCollection();
targetViewCollection = targetList.Views;
foreach (SPView view in sourceList.Views)
{
if (view.Title.ToLower() == "apple view")
{
foreach (string fieldRef in view.ViewFields)
{
if (!viewFields.Contains(fieldRef))
viewFields.Add(fieldRef);
}
var newView = targetList.Views.Add(view.Title, viewFields, "", 100, true, false);
newView.Update();
}
}
}
All replies (2)
Friday, January 27, 2012 6:02 AM ✅Answered
I have done the same thing but using SharePoint web services. Following URL may help:
http://farhanfaiz.wordpress.com/2011/12/12/sharepoint-2101-migrate-list-views-to-sharepoint-online/
Also, as per my experience with web services, addView method doesn't provide much functionality. Try exploring updateView (or something like that) vis OM.
P.S. sorry moderator's, have to paste url of my open post.
http://farhanfaiz.wordpress.com
Friday, January 27, 2012 7:13 AM ✅Answered
Hi BhincheeBahal,
Thanks for your post.
SharePoint SUSHI
http://sushi.codeplex.com/wikipage?title=Copy%20View
Copy a SharePoint List Programmatically
http://geekswithblogs.net/AnneBougie/archive/2009/01/23/copy-a-sharepoint-list.aspx
Copy Items from one list to another using PowerShell
http://mysharepointofview.com/2009/09/copy-items-from-one-list-to-another-using-powershell
Copying a SharePoint 2010 List to another Site
http://blogs.officezealot.com/mauro/archive/2011/02/14/29908.aspx
Hope it helps.