Programmatically I created a list which is type of GenericList. in the onet.xml file of my Web template I added following

<View List="Lists/MyList" BaseViewID="1" WebPartZoneID="Left" WebPartOrder="1"  />

It works but when I go to the page the list shows only the Title column and I have to got to edit webpart and choose default view "All objects" to show my columns.

I have tried to modify the default view, I have tried to add new Content Type and delete alla other content types, I have tried to hide Title, I have tried to delete Title (but failed because it is basetype and cannot delete it), I have tried to create new view and add it as default. but no success. first time I go to the page it shows only Title and I have to edit the web part.

1 Answer 1

SPLimitedWebPartManager mgr = null;

mgr = web.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)

 // Check if the webpart title is "Shared Documents"
 if (wp.Title == "Shared Documents")
 //Convert the webpart to list view webpart type 
 ListViewWebPart listWP = (ListViewWebPart)wp;

 if (listWP != null)
     Guid viewID = new Guid(listWP.ViewGuid);
     SPView wpView = list.Views[viewID];


     // Update the view 

This should work...

Ref: http://social.msdn.microsoft.com/Forums/eu/sharepointdevelopment/thread/ae4c27c8-42ef-4bbf-b6a7-5957f2160835

  • thanks, I dont know where do I use your code. Do I need to create a new feature? in a feature I cannot get default.aspx because it has not been created yet.
    – Medes
    Sep 26, 2012 at 12:13
  • yes I think you need to create a feature and write the code there, I really don't have idea at what point in time you have the default.aspx created... Sep 26, 2012 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.