Friday, March 25, 2011

Adding content type programatically

Scenario:
You want to add Content Type programatically

Solution:
SharePoint Object Model

Code:
  1. using (SPSite site = new SPSite("http://localhost")) {   
  2.   
  3. using (SPWeb web = site.OpenWeb()) {   
  4.   
  5. SPContentType baseType = web.AvailableContentTypes["Document"];  
  6.   
  7.  SPContentType proposal = new SPContentType( baseType, web.ContentTypes, "Project Proposal");   
  8.   
  9. proposal.FieldLinks.Add(new SPFieldLink(web.AvailableFields["Author"]));   
  10.   
  11. web.ContentTypes.Add(proposal);   
  12.   
  13. }  
  14. }  

Public Token key for the assembly

Scenario:
Sharepoint require most of the assemblies to be strongly named and referenced using 4 part name of the assembly.

Solution:
You can use sn.exe utility to get the public token key for your assembly

Code:
     "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -T MyAssembly.dll  

or  
  
     "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe" -T MyAssembly.dll  

Increasing Site Template maximum size limit

Scenario:
   You are not able to save a site template (.stp ) file because its size is bigger than 10MB.
Solution:
    STSADM allow you to change it.

Code:
    stsadm -o setproperty -pn max-template-document-size -pv 40000000  

Thursday, March 17, 2011

SharePoint Development and Programming FAQ

http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/5834679b-482b-4924-b881-fa2146840d05

SharePoint Job – SPJobLockType – which one should you use ?

Please refer the following blog
http://manomangaldas.blogspot.com/search?updated-min=2011-01-01T00%3A00%3A00-08%3A00&updated-max=2012-01-01T00%3A00%3A00-08%3A00&max-results=1

SharePoint Interview Questions

Please refer this blog
http://manomangaldas.blogspot.com/search/label/Interview

http://manomangaldas.blogspot.com/search?updated-min=2010-01-01T00%3A00%3A00-08%3A00&updated-max=2011-01-01T00%3A00%3A00-08%3A00&max-results=6

Add a custom menu in List Toolbar

Using a Feature XML file, you can add a custom menu in a List Toolbar. The following image is a sample of the custom feature.There are couple of steps to create the List custom menu bar.
  1. Create a XML file, give a name to this file, e.g. "Test.xml".
  2. Add a "CustomAction" XML Element in this file.
  3. Add following attributes to this element: "
    RegistrationType="List" RegistrationId="100" Location="ViewToolbar"
    Sequence="1000" Title="Submit to Manager" Description="Custom List Action"
  4. Reference "Test.xml" file in "feature.xml"file using "ElementManifest Location='Test.xml' " XML schema.
  5. Install and activate this feature.
  6. Create a custom list from the site. You will see the custom menu "Submit to Manager" displaying on the List Toolbar.

Wednesday, March 16, 2011

Stsadm Commands for add/depoly solution

Addsolution :
stsadm.exe –o addsolution –filename “C:\abc.wsp”
Deploy Solution:
stsadm.exe –o deploysolution –name abc.wsp –local –allowgacdeployment
or
stsadm –o deploysolution –name "abc.wsp” –immediate –allowgacdeployment -force
or
stsadm –o deploysolution –name "abc.wsp” –url http://localhost/ravi  –immediate –allowgacdeployment

Upgrade Solution:
stsadm.exe –o upgradesolution –name abc.wsp –filename “C:\abc.wsp” –immediate –allowgacdeployment

Retract Solution:
stsadm -o retractsolution -name abc.wsp -immediate
The retractsolution operation removes files from the front-end Web server
Remove Solution:
stsadm -o deletesolution -name ab.wsp
stsadm -o execadmsvcjobs : By using the STSADM operation execadmsvcjobs, we can force the timer job to execute immediately.This helps us when we donot want to wait until the scheduled time is reached

Activate Feature:
stsadm –o activatefeature –name <<YourfeatureName>> –url “http://localhost/ravi” -force
Deactivate Feature:
stsadm -o deactivatefeature -name <<featurename>> -url "http://localhost/ravi"  -force


Tuesday, March 15, 2011

Custom Site Definition in SharePoint

Steps to create custom Site Definition
1. Log on as an administrator
2. Browse to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates.
Copy STS folder-> Paste it at same place -> Rename it as TIGER.
3. Open the folder Tiger
4. Search for default.aspx
5. Open default.aspx in notepad.
6. Modify code. Here we need to add code for site definition.

Default.aspx
<%@ Page language="C#" MasterPageFile="~masterurl/default.master"   
Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
          <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,multipages_homelink_text%>" 
EncodeMethod="HtmlEncode"/> - <SharePoint:ProjectProperty Property="Title" runat="server"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageImage" runat="server"><IMG 
SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
                    <label class="ms-hidden"><SharePoint:ProjectProperty Property="Title" 
runat="server"/></label>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderId="PlaceHolderTitleBreadcrumb" runat="server"/>
<asp:Content ID="Content5" ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server">
<style type="text/css">
TD.ms-titleareaframe, .ms-pagetitleareaframe {
          height: 10px;
}
Div.ms-titleareaframe {
          height: 100%;
}
.ms-pagetitleareaframe table {
          background: none;
          height: 10px;
}
</style>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
          <META Name="CollaborationServer" Content="SharePoint Team Web Site">
          <script type="text/javascript">
          var navBarHelpOverrideKey = "wssmain";
          </script>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderId="PlaceHolderSearchArea" runat="server">
          <SharePoint:DelegateControl runat="server"
                   ControlId="SmallSearchInputBox" />
</asp:Content>
<asp:Content ID="Content8" ContentPlaceHolderId="PlaceHolderLeftActions" runat="server">
</asp:Content>
<asp:Content ID="Content9" ContentPlaceHolderId="PlaceHolderPageDescription" runat="server"/>
<asp:Content ID="Content10" ContentPlaceHolderId="PlaceHolderBodyAreaClass" runat="server">
<style type="text/css">
.ms-bodyareaframe {
          padding: 0px;
}
</style>
</asp:Content>
<asp:Content ID="Content11" ContentPlaceHolderId="PlaceHolderMain" runat="server">
          <table cellspacing="0" border="0" width="100%">
            <tr>
             <td class="ms-pagebreadcrumb">
                   <asp:SiteMapPath SiteMapProvider="SPContentMapProvider" id="ContentMap" SkipLinkText="" 
NodeStyle-CssClass="ms-sitemapdirectional" runat="server"/>
             </td>
            </tr>
            <tr>
             <td class="ms-webpartpagedescription"><SharePoint:ProjectProperty Property="Description" 
runat="server"/></td>
            </tr>
            <tr>
                   <td>
                    <table width="100%" cellpadding=0 cellspacing=0 style="padding: 5px 10px 10px 10px;">
<tr>
<td valign="top" width="100%" colspan="3">
<WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Top" Title="loc:Top" />
</td>
</tr>
                     <tr>
                      <td valign="top" width="70%">
                                <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Left" 
Title="loc:Left" />
                                &nbsp;
                      </td>
                      <td>&nbsp;</td>
                      <td valign="top" width="30%">
                                <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Right" 
Title="loc:Right" />
                                &nbsp;
                      </td>
                      <td>&nbsp;</td>
                     </tr>
                    </table>
                   </td>
            </tr>
              <tr>
              <td valign=”top” width=”100%” colspan=”3”>
                 <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Bottom" 
Title="loc:Bottom" />  
              </td>
              </tr>
          </table>
</asp:Content>
7. Register new site definition to SharePoint.
8. Open the folder
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML
9. Copy the file WEBTEMP.XML and save it as WEBTEMPTIGER.xml. here make a note that , we need to append name of folder which we created in step 2 ( in this case it is tiger) to WEBTEMP. So here name would be WEBTEMPTIGER.xml
10. Open WEBTEMPTIGER.XML in notepad and replace it with following content.
<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="1033" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->
<Templates xmlns:ows="Microsoft SharePoint">

  <Template Name="TIGER" ID="10009">

    <Configuration ID="1" Title="Tiger Definition" Hidden="FALSE" ImageUrl="/_layouts/images/Eye.GIF" Description="Tiger Site." DisplayCategory="Custom" AllowGlobalFeatureAssociations="False" >    </Configuration>

  </Template>
</Templates>
Make sure here ID should be greater than 10000. It must not collide with id of any other Site Definition.
11. Restart IIS. Go to Start->Run->IISRESET
12. Now you would be able to see this Site Definition inside Custom category.