Monday, February 4, 2013

How to create a List in Sharepoint 2007 from web interface


1) Create a Site column. eg: a field 'Position' as choice field with 0-6 values. You could create a new grouping or use existing.
2) Create a Content Type (a table with all the fields/columns created in the first step. You could name it with template prefix. You could create a new grouping or use existing. You could add from the newly created site column or use existing one.

For both of the above option->Site Actions->Site Settings->Modify all->Galleries. sdsd

3) Create a site (a table derived from the content type. If you cannot find an option go to advanced settings and enable it)

Site Actions->site content and structure->Selected your site right click -> new ->List->custom List.
Settings->List Settings
Can you see a Content Type section?
If not General Settings ->advanced settings->Allow Management of Content Type->Yes
If you can see the Content Type section then 'Add from existing Content Types' and select your previously created content type.
 
 
 
 
 
 

Wednesday, April 25, 2012

Sharepoint Object Model vs Asp.Net Object Model

Microsoft SharePoint Foundation offers a highly structured server-side object model . Here are some comparisons


The objects in the object hierarchy include SPFarm, SPService, SPWebApplication, SPSite, SPWeb, SPList, and SPListItem

 
Location difference
-----------
asp.net: wwwroot/webapp/web.config
sharepoint:wwwroot/wss/virtualdirectries/5555/web.config

 
Major Differences
Sharepoint modiefies the pipeline
loading resource from DB
non asp.net related contenet
no compile mode
control restriction on page

 

 
Sharepoint :

  • Farm-SPFarm:
    Farm consists of one or more web Services and Web applications. Contains a global static object SPFarm.Local (Microsoft.SharePoint.Administration.dll ).  SPFarm objects are used only when you are creating administrative applications like upgrade backup restore etc. not for sites or list items.
SPService (base class for services) is also used in this context for Services for administration.
  • Web Application-SPWebApplication(traditional ISS web site equivalent with SP configured)
This is equivalent to web server in ASP.Net
eg: http://sp2010:2120 . This is server url in asp.net. But this is a web application in SharePoint.
For a .Net web developer, 'Web application' used to be the template you add in a VS solution.
When you create a Web application by using the SharePoint Central Administration application, an IIS Web site is automatically created. You can verify whether the IIS Web site has been created by looking in IIS Manager, where you can see its structure, Web.config file, and virtual directory mappings. Information workers/end users do not browse to SPWebApplication. They actually browse to SharePoint Sites, which are SPWeb objects(explained later).
As a developer, it is also possible to create Web applications by adding SPWebApplication objects to the WebApplications collection of a SPWebService object,. But only to replace the SharePoint Central Administration application. Usually you will work with an existing SPWebApplication to access its collection of SPSite objects, or to control application-wide settings(alert config).you might write code to add or modify Web.config settings for a Web application by using the SPWebConfigModification class.
  • Site Collection- SPSite 
           Objects with largest scope and has rootweb property (SPWeb) representing the URL the enduser might browse. SpSite is a security boundary and a container for Users and groups and also for SPWeb and SPList objects. As a developer, you will typically access SPSite objects in code to reference the Webs that they contain, or to administer security programmatically. However, also be aware that you can target development projects that are scoped at the site collection level(site-level features and solutions)
Instantiating SPSite Objects: You can work with SPSite objects in a very flexible way. For example, you can instantiate SPSite objects by doing any of the following:

    • Passing in a Url to its constructor.
    • Referencing a member of the Sites collection of a SPWebApplication
    • Referencing the current context site

  • SPWeb:
          
SPWeb objects are effectively a broad unit of storage, as they expose SPListCollection objects that contain pages libraries, lists, and document libraries. An important concept is that one SPWeb object can also contain other SPWeb objects to represent sites and sub-sites from the information worker's perspective. SPWeb represents a website from a end user experience. It is the container for items like lists and pages and so forth

Instantiating SPWeb Objects
    • As the RootWeb property of an SPSite object.
    • As a member of the AllWebs collection of an SPSite object.
    • As the return value of the OpenWeb method of an SPSite object.
    • By referencing the current context Web. 
  • Lists(SPList,also SPFile for documents)
       SPList objects are the primary container for SharePoint data, such as SPListItem objects. SPListItem objects lookups to other list data and may contain native SharePoint Server 2010 data, documents, site pages, images and other media. As a developer, you can reference SPList objects as members of the Lists collection from a SPWeb, and you can create SPList objects by adding to the Lists collection. Other properties include visibility, content type etc.

SPWebservice-represents a service contaning one or more Web applications
----
Disposal
SPSite - wrap in 'using '
            automatically disposes SPWeb(those that gets lazily initialised)
SPWeb-if you are creating it then you dispose.
SPContext
      Do not dispose as (Sharepoint handles)
Tip: check intelisense for a dispose method . if it has then dispose it
for more on disposal

----------start working
To create a SharePoint site programmatically, you add an SPWeb object to an SPWebCollection object. Existing sites expose a Webs property of type SPWebCollection, so you can use the Add method of this Webs property to create a subsite.
 
 
[to be continued]

Thursday, March 29, 2012

Master Page replaced

Master Page disappeared after feature activation

After installing a usercontrol/webpart as feature, my custom Master page got changed with another one (with the new user control in it).There is only .wsp and .dll(no source code) so don't know what is happening with the activation. How could I bring back my old master page ? As well as have the master page contain the new installed control.(I used sharepoint 2010 but should apply to other versions as well).

1) Find how the user control is embedded in the new Master Page
        search for the user control and you could find an entry like
<SharePoint:DelegateControl ID="DelegateControl1" runat="server" ControlId="UserControlName" Version="4"/> 

2) Change the master page back to the previous one (the one you had before)
          from sharepoint site settings / Sharepoint Designer(set as default option)
     We get back our master page but with out the newly installed control

3) Add the user control entry you found in step 1 to your master page.

Rememeber that sharepoint designer fixes will be gone if you deploy the sharepoint solution through code next time(next update)
Tip:
The reason why I used only the controld(ControlId="UserControlName") is because the controlId is bound to user control when deployed, in Elements.xml (\..\Web Server Extensions\14\TEMPLATE\FEATURES\UserControlNameFeature\UserControl\Elements.xml)

<Control Id="UserControlName" Sequence="10" ControlSrc="~/_controltemplates/User_Control_WebPart/UserControl.ascx">
</Control>


proceed yourself based on what you find in step 1

And the reason why the master page got changed when I activated the user control was because of the following code in the user control/web part.(found from reverse engineering)

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite parent = (SPSite) properties.Feature.Parent;
SPWeb rootWeb = parent.RootWeb;
Uri uri = new Uri(rootWeb.Url + "/_catalogs/masterpage/CoolMaster.master");
rootWeb.MasterUrl = uri.AbsolutePath;
rootWeb.CustomMasterUrl = uri.AbsolutePath;
rootWeb.Update();
}

---End--comment your thoughts please