Friday, May 20, 2011

SharePoint Visual How tos List

WSS 3.0 Visual How tos
http://msdn.microsoft.com/en-us/library/bb931737(v=office.12).aspx


SharePoint 2007 Visual How tos
http://msdn.microsoft.com/en-us/library/bb726436(v=office.12).aspx

SharePoint 2010 Visual How tos
http://msdn.microsoft.com/en-us/library/gg252010.aspx

Wednesday, May 18, 2011

SharePoint 2010 Feature Creation - Element.xml


Important files that we need to have an Idea:

http://msdn.microsoft.com/en-us/library/ms460194.aspx   CustomAction Element
http://msdn.microsoft.com/en-us/library/bb802730.aspx   Default Custom Action Locations and IDs
http://msdn.microsoft.com/en-us/library/ee537543.aspx CommandUIDefinition: Default Server Ribbon Customization Locations
http://msdn.microsoft.com/en-us/library/ms465980.aspx Custom Action Definition Schema
http://msdn.microsoft.com/en-us/library/ff458373.aspx Command UI Definition // Button, Tab, checkBox code ...



<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="NewUIRibbonControl"
    RegistrationType="List"
    RegistrationId="101"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
           Location="Ribbon.Documents.New.Controls._children">
          <Button
             Id="NewUIRibbonControl.ShowHelp"
             Alt="Help"
             Sequence="1981"
             Command="ShowHelp"
             Image32by32="/_layouts/images/helpicon.gif"
             LabelText="Help"
             TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="ShowHelp"
         CommandAction="javascript:window.open('http://msdn.microsoft.com/en-us/library/ee539395%28office.14%29.aspx');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

<CustomAction Id="Ribbon.Library.Actions.ReplacementButton"
    Location="CommandUI.Ribbon"
    RegistrationId="101"
    RegistrationType="List"
    Title="Replace a Ribbon Button">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Library.Actions.ConnectToClient">
          <Button Id="Ribbon.Library.Actions.ConnectToClient.ReplacementButton"
            Command="ReplacementButtonCommand"
            Image16by16="/_layouts/images/actionseditpage16.gif"
            Image32by32="/_layouts/images/actionssettings.gif"
            LabelText="Replaced Button"
            TemplateAlias="o2" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="ReplacementButtonCommand"
          CommandAction="javascript:alert('This button has been replaced.');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>


 <CustomAction
   Id="MyCustomRibbonTab"
   Location="CommandUI.Ribbon.ListView"
   RegistrationId="101"
   RegistrationType="List">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Tabs._children">
          <Tab
            Id="Ribbon.CustomTabExample"
            Title="My Custom Tab"
            Description="This holds my custom commands!"
            Sequence="501">
            <Scaling
              Id="Ribbon.CustomTabExample.Scaling">
              <MaxSize
                Id="Ribbon.CustomTabExample.MaxSize"
                GroupId="Ribbon.CustomTabExample.CustomGroupExample"
                Size="OneLargeTwoMedium"/>
              <Scale
                Id="Ribbon.CustomTabExample.Scaling.CustomTabScaling"
                GroupId="Ribbon.CustomTabExample.CustomGroupExample"
                Size="OneLargeTwoMedium" />
            </Scaling>
            <Groups Id="Ribbon.CustomTabExample.Groups">
              <Group
                Id="Ribbon.CustomTabExample.CustomGroupExample"
                Description="This is a custom group!"
                Title="Custom Group"
                Sequence="52"
                Template="Ribbon.Templates.CustomTemplateExample">
                <Controls Id="Ribbon.CustomTabExample.CustomGroupExample.Controls">
                  <Button
                    Id="Ribbon.CustomTabExample.CustomGroupExample.HelloWorld"
                    Command="CustomTabExample.HelloWorldCommand"
                    Sequence="15"
                    Description="Says hello to the World!"
                    LabelText="Hello, World!"
                    TemplateAlias="cust1"/>
                  <Button
                    Id="Ribbon.CustomTabExample.CustomGroupExample.GoodbyeWorld"
                    Command="CustomTabExample.GoodbyeWorldCommand"
                    Sequence="17"
                    Description="Says good-bye to the World!"
                    LabelText="Good-bye, World!"
                    TemplateAlias="cust2"/>
                  <Button
                    Id="Ribbon.CustomTabExample.CustomGroupExample.LoveWorld"
                    Command="CustomTabExample.LoveWorldCommand"
                    Sequence="19"
                    Description="Says I love the World!"
                    LabelText="I love you, World!"
                    TemplateAlias="cust3"/>
                </Controls>
              </Group>
            </Groups>
          </Tab>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.CustomTemplateExample">
            <Layout
              Title="OneLargeTwoMedium"
              LayoutTitle="OneLargeTwoMedium">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="cust1" />
                </Row>
              </Section>
              <Section Alignment="Top" Type="TwoRow">
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust2" />
                </Row>
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust3" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="CustomTabExample.HelloWorldCommand"
          CommandAction="javascript:alert('Hello, world!');" />
        <CommandUIHandler
          Command="CustomTabExample.GoodbyeWorldCommand"
          CommandAction="javascript:alert('Good-bye, world!');" />
        <CommandUIHandler
          Command="CustomTabExample.LoveWorldCommand"
          CommandAction="javascript:alert('I love you, world!');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>



</Elements>

Tuesday, May 17, 2011

How to add a user to a SharePoint Group & Feature Stapling

How to create a feature with feature stapplingin SharePoint?

1) Open a new sharepoint visual studio 2010 project

2) Make your feature as normal

3) Find the site definition id you want to staple your feature to

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\XML\webtemp*.xml
4) Create a new module, call it "Stapling" or something

5) Insert this into the module file, replacing the site definition template name and feature guid:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <FeatureSiteTemplateAssociation Id="FEATUREGUID" TemplateName="YOURSITETEMPLATE#0" />
</Elements>
6) A new feature should have been created for "Stapling", but if it has not, create it and the Stapling module to it

7) Set the deployment scope to "Farm"

8) You should have 2 features in your project now

9) Package and deploy


--

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.SharePoint;

namespace AddUsers
{
class AddUserClass
{
static void Main(string[] args)
{

SPSite siteCollection = new SPSite(“Site URL”);
SPWeb site = siteCollection.OpenWeb();

SPGroup AddUserGroup = site.Groups["Group Name"];
AddUserGroup.AddUser(“domain/alias”, “email address”, “Name”, “Description”);

OR

SPRoleAssignment MyRoleAssign = new SPRoleAssignment(“domain/alias”, “email address”, “Name”, “Description”);

SPRoleDefinition MyRoleDef = newSubWeb.RoleDefinitions["Contribute"];
MyRoleAssign.RoleDefinitionBindings.Add(MyRoleDef);
site.RoleAssignments.Add(MyRoleAssign);

site.Dispose();
siteCollection.Dispose();
}
}
}

Monday, May 9, 2011

Moving Content Database from One Site to Other Site / One Env to Other Environment


In our source server, let us do the following steps: 


1. In the Command Prompt, let us change to the directory where the STSADM command-line tool is located. By default, it is on C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN. 


2. The next step is to prepare our content database before moving it by setting up the profile and membership synchronization service. It prevents the synchronization service from failing and losing related settings. To do this, let us type the following command, and then press Enter: 


STSADM –o preparetomove –contentdb <content database name>

stsadm -o preparetomove -ContentDB Usildb218-qa:WSS_Content_sales_Prod


3. Now, let us detach our content database by executing the command below. We have to take note, however, that removing the content database simply removes the association of the database with our SharePoint Web application and does not exactly delete the database. 


STSADM -o deletecontentdb –url <URL name> -databasename <database name> -databaseserver <database server name> 


stsadm -o deletecontentdb -url "https://kmqa.ca.com/sales" -databasename WSS_Content_sales_Prod -databaseserver usildb218-qa


4. Let us open our Microsoft SQL Server 2008 Management Studio, and detach the content database. Finally, we will copy the corresponding .mdf and .ldf files to our destination server. 


In our destination server, let us do the following steps: 


NOTE: It is assumed that you have created a corresponding Web site in you destination server and deleted its content database – like what we have did in steps 2 and 3. With this, we are now ready to restore/move the content database of our source server to the destination server. Thanks Amlan for the comment. 


5. Let us open our Microsoft SQL Server 2008 Management Studio, and attach the content database that we transferred in the previous step. 


6. In the Command Prompt, let us change to the directory where the STSADM command-line tool is located. By default, it is on C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN. 


7. Now, to add the content database to our destination server, let us type the following command, and then press Enter: 


STSADM –o addcontentdb –url <URL name> -databasename <database name> -databaseserver <database server name> 






stsadm -o addcontentdb -url "http://kmdev.ca.com/sales" -databasename "WSS_Content_sales_Prod" -databaseserver "usildb218-qa"


8. And finally let us start a full crawl. We must be aware, moreover, that a full crawl will occur the first time even if the next crawling scheduled is set to incremental mode in the content database we have restored.