English 中文(简体)
添加一个新的 SPView 到 SPList
原标题:Add a new SPView to an SPList

我需要从程序上创建视图并将其添加到列表中。 在 SPL 方法中, 有 SPView Collection 类型 SPView Collection 的视图属性 。
此方法有一个添加方法 。 但该方法不接受完整的 XML 公式 。 它被分为多个参数( 您设置查询、 加入等 ) 。 我需要一种方法, 使我能够通过完整 XML 。
I 正在考虑首先使用此添加方法创建一个 Dummy 视图, 然后读回视图, 最后使用 SetViewXml. < br/ {br/ > 方法。 但是它有点肮脏, 也许有些更好更简单的东西我错过了 。 谢谢!

最佳回答

尝试一下。 我认为您不需要 XML。 您只需要使用字符串收藏来添加列 。

  using (SPWeb web = properties.Feature.Parent as SPWeb)
  {

     System.Diagnostics.Debug.WriteLine("Creating the list");

     //web.AllowUnsafeUpdates = true; //use this in an application page no need in a dll

     web.Lists.Add("Customers", "Store informations about my Company Customers", SPListTemplateType.GenericList);

     web.Update();



     System.Diagnostics.Debug.WriteLine("Creating the Fields");

     SPList myNewList = web.Lists["Customers"];

     myNewList.Fields.Add("First Name", SPFieldType.Text, false);

     myNewList.Fields.Add("Last Name", SPFieldType.Text, false);

     myNewList.Fields.Add("Adress", SPFieldType.Text, false);

     myNewList.Fields.Add("City", SPFieldType.Text, false);

     myNewList.Fields.Add("Latest Purchase Date", SPFieldType.DateTime, false);

     myNewList.Fields.Add("Sales Comments", SPFieldType.Note, false);

     myNewList.Update();



     System.Diagnostics.Debug.WriteLine("Creating the view");

     System.Collections.Specialized.StringCollection strColl = new System.Collections.Specialized.StringCollection();

     strColl.Add("Title");

     strColl.Add("First Name");

     strColl.Add("Last Name");

     strColl.Add("Adress");

     strColl.Add("City");

     strColl.Add("Latest Purchase Date");

     strColl.Add("Sales Comments");

     myNewList.Views.Add("Summary", strColl, @"", 100, true, true, Microsoft.SharePoint.SPViewCollection.SPViewType.Html, false);

     myNewList.Update();

 }
问题回答

暂无回答




相关问题
SharePoint 2010 Blog site template and post security

I asked this question on msdn forums but got no response in 24 hours. I am pasting the question here, I am sure you guys out there can help me :) This is my first post: I created a blog site with SP ...

Sharepoint 2010 - Custom Ribbon

i m developing a sharepoint project and central admin pages (located in _layouts), and i want to use Ribbon bar. i have found this sample but i hope so, it is wrong.. http://sharepointsolutions.com/...

Printing an InfoPath 2010 form in SharePoint 2010

Does anyone know where the option to print an infopath form (in my case a customized list form) exists in SharePoint 2010? In MOSS this functionality comes out of the box but either I am missing ...

Sharepoint 2010 Email Event Receiver not firing?

I have two event recievers setup on a list in 2010. The first is a ItemAdded reciever that works every time: <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft....

Access Services and SharePoint 2010 - Need Info

I ve been asked to research the ability to publish Access solutions directly to SharePoint as demonstrated in the demo below. http://channel9.msdn.com/shows/Access/Microsoft-Access-2010-Demo/ I m ...

热门标签