Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

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];

     wpView.ViewFields.Delete("Title");

     // Update the view 
     wpView.Update();
 }
 break;
 }
}

This should work...

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

share|improve this answer
    
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 '12 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... –  Arsalan Adam Khatri Sep 26 '12 at 16:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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