|
|
||||||
|
#1
|
|
|
|
|
Hi,
I have created cusotm list that need to display in a webpart using feature on default.aspx page of a site created using balnk site (not using code). Any help would be appreciated. Thanks, Durga |
|
|
|
#2
|
|
|
|
|
You could use the list view webpart. The way I have done it in the
past was to create a feature and use a feature event handler. Inside the feature activated event, you would put code in there that would connect to the site, get an instance of default.aspx page, an instance of the web part manager on that page, and you would then create a listview webpart, assign it to your list, then add that webpart to the web part manager and update your page. Unfortunately all the above requires code since you want to do this with a feature. Here is some example code that would add the webpart to the page which you would put inside your feature activated event: using (SPSite iLoveBeerSite = new SPSite(I_LOVE_BEER_SITE)) { using (SPWeb iLoveBeerWeb = iLoveBeerSite.OpenWeb()) { SPFile defaultPage = iLoveBeerWeb.GetFile("default.aspx"); if (defaultPage != null) { //get the web part manager SPLimitedWebPartManager webPartMgr = defaultPage.GetLimitedWebPartManager(System.Web.UI .WebControls.WebParts.PersonalizationScope.Shared) ; SPList calendarList = iLoveBeerWeb.GetList("/ lists/calendar/"); ListViewWebPart calendarWebPart = new ListViewWebPart(); calendarWebPart.Title = "Calendar"; calendarWebPart.ListName = calendarList.ID.ToString("B").ToUpper(); calendarWebPart.Hidden = false; calendarWebPart.ViewType = ViewType.Calendar; calendarWebPart.ViewGuid = calendarList.DefaultView.ID.ToString("B").ToUpper( ); webPartMgr.AddWebPart(calendarWebPart, "Left", 0); MessageBox.Show("Web Part Added!"); } } } The above code should do what I described, I am adding a calendar, but a calendar is just another type of list, so the code should be the same. Thanks, Tony Testa [url down] On May 18, 8:30 pm, Durga <Du> wrote: [..] |
|
#3
|
|
|
|
|
The generally accepted way to do this is through site definitions. You will
want to setup a good solution with a site definition using visual studio first. Here is my blog on how to do this: http://greggalipeau.wordpress.com/20...visual-studio/ In the blog mentioned above I show how to setup a site definition with your own default.aspx page and master page (if you don't want a custom master page just skip the master page ideas). After you have the site definition setup like this you can create your feature for your custom list. A great way to do this is to reverse engineer the feature through the Solution Generator tool that comes with Visual Studio Extensions for WSS and then copy and paste the feature into your solution (just be careful with this approach because the VSeWSS tool hides the feature.xml file - you can see it if you use the WSP view in Visual studio under other views). After the new feature is in your SharePoint solution in Visual Studio you have to modify the onet.xml file of the site definition to make it show when the site is created. To do this you need three things: 1. Reference your feature id in the SiteTemplates or WebTemplates section of the onet.xml based on the scope you give to the feature. This will make this list feature available to your new site. 2. Add an instance of the list to the onet.xml file under the Configurations section. This will make sure the site creates an instance of the available list. 3. Add a View to the list in the Module section for your site definition. This will create the list webpart on the page you are creating. Anyways, this might seem complicated if you haven't built custom site definitions before. But, this is the way SharePoint does this with it's out-of-the-box sites, so it is the best available option for us developers. In the blog I mention above I mention to copy the out-of-the-box sts site definition to start with. You can notice they do the same thing for their lists. An example is the announcement list they instantiate. In the end you will have your new, custom link in "Select a template" in SharePoint and you will have complete control over how it builds. Good luck with this, Greg p.s. You might notice I told you to just reverse engineer the list with the Visual Studio Extensions Solution Generator tool and not to reverse engineer the whole site. This is just because I don't personally like the solutions the VSeWSS tool creates. It is really a personal preference for me. But, this is another solution for someone trying to learn site definitions. I just feel like I have more control if I build the solution out myself with a tool like WSPBuilder and then only reverse engineer difficult things like lists. |
|
#4
|
|
|
|
|
Thanks for the solution. Does this mean we can not use feature without code
to do this?. I am looking for plain fetaure without any code. If not I will follow your solution. |
|
|
| Similar Threads | |
| When will MS add a tree view feature to Shared Documents webpart? When will MS add a tree view feature to Shared Documents webpart? |
|
| List View webpart (WSSv3) On my root site TOP LEVEL (WSSv3) i created a Document Lib i was expecting to see it has a webpart on my subsites but i can't find it?? So i saved my Document Lib from my top... |
|
| List View WebPart Hi, As I found that doc lib. uses ListViewWebPart to display documents list. I want to know how can I change the source of ListViewWebPart ? basically I want to populate... |
|
| How to use randomized list view in an default webpart? Hi everyone: I want to let my data list in the webpart has an randomized order,so that everytime when the page loaded, I can see different first row of the datasheet.How... |
|
| List view webpart on several areas Is it possible to add a list view webpart for the same list on two areas or in other ways show data from the same list in two areas? I know it is possible to make a dataview,... |
|
|
All times are GMT. The time now is 07:27 AM. | Privacy Policy
|