Thursday, October 27, 2011

SharePoint Features & Elements

This is just an effort to put some ready xml code stubs to reuse quickly.

Just think how many times did we copy and pasted the feature and elements files.  This post is of no use rather than serving a ready reference for these kind of xmls.

1.       Feature with Activation Dependencies:

<?xml version="1.0" encoding="utf-8"?>

<Feature Id="{xxxxxxxx-91B7-xxxx-xxxx-2BA7000Dxxxx}"

         Title="SiteCollectionFeatures"

         Scope="Site"

         Version="1.0.0.0"

         Hidden="FALSE"

         DefaultResourceFile="core"

         ReceiverAssembly="SharePoint.Request, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11192xxxx355xxxx"    

ReceiverClass="SharePoint.Request.ManageSiteCollectionFeatures"

         xmlns="http://schemas.microsoft.com/sharepoint/">

  <ActivationDependencies>

    <!-- Site Column feature-->

    <ActivationDependency FeatureId="91111153-73DD-xxxx-xxxx-Bx5xxxxFDFE"/>

    <!-- Content Type feature-->

    <ActivationDependency FeatureId="E5147C60-xxxx-4dxx-89xx-53Yxxxxxxxx"/>

    <!-- Custom Action feature-->

    <ActivationDependency FeatureId="2DERFT56-C968-454a-B9FB-07ExxxxxDA1"/>

    <!-- Workflow feature-->

    <ActivationDependency FeatureId="62SWERc1-0446-4xxx-9xxa-axxxxxxxxxx"/>

  </ActivationDependencies>

</Feature>

 

2.       Feature to deploy Site Pages:

<?xml version="1.0" encoding="utf-8"?>

<Feature  Id="{xxxx4B02-A4B8-xxxx-8F15-B8Dxxxxxxxx3}"

          Title="PP.My Projects Site Page1"

          Description="Creates Custom Site Page in Pages Library"

          Version="1.0.0.0"

          Hidden="FALSE"

          Scope="Web"

          DefaultResourceFile="core"

          ImageUrl="menuprofile.gif"

          ReceiverAssembly="MySPCustomSitePages1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7bae1560a7da1eb0" ReceiverClass="MySPCustomSitePages1.SPCustomSitePageFR"

          xmlns="http://schemas.microsoft.com/sharepoint/" >

  <ElementManifests>

    <ElementManifest Location="elements.xml"/>

    <ElementFile Location="pages/default.aspx"/>

  </ElementManifests>

</Feature>

  

3.       Elements to Propagate Site Pages: [Module – >File]

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Module Name="MySitePage" Url="Pages" Path="Pages">

    <File Url="default.aspx" Name="MySitePage.aspx" Type="GhostableInLibrary" >

      <Property Name="Title" Value="MySitePage" />

      <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/BlankWebPartPage.aspx, Blank Web Part Page" />

      <Property Name="ContentType" Value="Welcome Page" />

    </File>

  </Module>

</Elements>

  

4.       Elements to create ECB Menu:

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <CustomAction Title="My Menu"

  Description = " My Menu"

  Location = "EditControlBlock"

  RegistrationId = "0x0100C2XXXXXXXXXXXXXXXXXXXXXXXXXX9D" (list content type id)

  RegistrationType = "ContentType"

  Sequence = "11"

  ShowInLists = "TRUE"

  ShowInReadOnlyContentTypes = "TRUE"

  ShowInSealedContentTypes = "TRUE"

  Rights="ApplyStyleSheets">

    <UrlAction Url="~site/_layouts/MY/Pages/MYPAGE.aspx?List={ListId}&amp;ID={ItemId}"/>

  </CustomAction>

</Elements>

 

5.       Feature to with Feature Receiver Code:

<?xml version="1.0" encoding="utf-8"?>

<Feature Id="{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}"

         Title="Test Me"

         Scope="Site"

         Version="1.0.0.0"

         Hidden="FALSE"

         ImageUrl="VWDISC.GIF"

         DefaultResourceFile="core"

         ReceiverAssembly="ME.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx"

         ReceiverClass="ME.Test.Manage"

         xmlns="http://schemas.microsoft.com/sharepoint/">

</Feature>

 

6.       Log Exception to ULS Log CODE:

public static void LogException(Exception ex)

        {

            //PortalLog.LogString("Exception Occured in - Control :" + ex.Message);

         Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception Occured in - Control :" + ex.Message);

        }

 

7.        

8.       D

9.       D

10.   D

11.   d

I will keep on adding these stubs in feature as well. Thanks for reading. If you have some other explanation – please post a comment… I’ll be happy to hear.

...HaPpY CoDiNg

Partha (Aurum)

References:

Monday, October 24, 2011

SharePoint FAQi (Frequently Asked Questions in Interviews )

Winking smile  - Why this….. heck.. you know why…

There are some typical interview questions which we face almost in any SharePoint interview.. thus I thought to put them in one place such that I can go thru all of them once night before… Party smile

Q: When should you dispose SPWeb and SPSite objects? And even more important, when not?

 

A: You should always dispose them if you created them yourself, but not otherwise. You should never dispose SPContext.Current.Web/Site and you should normally not dispose SPWeb if IsRootWeb is true. More tricky constructs are things along the line of SPList.ParentWeb.

Reference:

http://blogs.msdn.com/b/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx

Q. In brief, the key feature areas of MOSS include the following:
A:

Collaboration — Document libraries/tasks/calendars, blogs, wikis, e - mail integration, project management “ lite, ” Office Outlook 2007 integration, offline documents, and lists.
Portal — Enterprise portal template, site directory, my sites, social networking, and privacy control .
Search — Enterprise scalability, contextual relevance, rich people and business data search .
Content Management — Integrated document management, records management, WCM with policies and workflow .
Business Forms — Rich and Web - forms - based front ends, line of business (LOB) actions, pluggable single sign - on (SSO) .
Business Intelligence — Server - based Office Excel 2007 spreadsheets and data visualization, report center, BI Web Parts, key performance indicators (KPIs)/dashboards .

I will keep on adding question from SharePoint, .Net, SQL etc., and would request you all to post yours as well.

This is in continuation to my earlier post on Site Pages. In this post………

Thanks for reading.. Please post the questions you faced and which you think is important also.

...HaPpY CoDiNg

Partha (Aurum)

Creating Custom SharePoint Site Pages by Object Model (Code only)

This is in continuation to my earlier post on Site Pages. In this post I have only used the object model to create and put a Site page again in pages library. A very simple piece of code which creates a stream and writes it to the file location in SharePoint. I know this approach will never be used in any project, though.  I have created this in a windows program and thus it is in a shape of method stub. One way to implement would be to put this in a feature receiver to work on feature activation.

private void DoFileStreamWriteFile()

        {

            ////Site url

            string strUrl = "http://myserver0111:7000/";

            using (SPSite oSite = new SPSite(strUrl))

            {

                using (SPWeb oWeb = oSite.OpenWeb())

                {

                    MemoryStream fileStream = new MemoryStream();

                    StreamWriter fileWriter = new StreamWriter(fileStream);

                    ////write the source of the page (include meta:progid so SharePoint Designer understands this file)

                    fileWriter.WriteLine("<%@ Page MasterPageFile=\"~masterurl/default.master\" meta:progid=\"SharePoint.WebPartPage.Document\" %> ");

                    fileWriter.WriteLine("<asp:Content runat=\"server\" ContentPlaceHolderID=\"PlaceHolderMain\" > ");

                    fileWriter.WriteLine("<h1> Hello World </h1>");

                    fileWriter.WriteLine("</asp:Content>");

                    fileWriter.Flush();

                    //// save the file to SharePoint

                    oWeb.Files.Add(oWeb.Url+"/Pages/"+"MyApiGeneratedPage.aspx", fileStream);

                    //// cleanup

                    fileWriter.Close();

                    fileWriter.Dispose();

                    fileStream.Close();

                    fileStream.Dispose();

                }

            } 

        }

 

Now  build and deploy to see the magic happening yourself again.... J

Thanks for reading. If you have some other explanation – please post a comment… I’ll be happy to hear.

...HaPpY CoDiNg

Partha (Aurum)