Sunday, January 30, 2011

Create the Edit Control Block Menu Item

 
The solution that you create in this walkthrough creates a list item context menu entry for Microsoft Word .docx files. When users open the document context menu for a given .docx file, they can click the new entry to initiate the conversion of the document. To modify the ECB menu, you create a new feature and then add a new context menu item.
To create a feature
 
   1.In the Solution Explorer, right-click Features, and then click Add Feature.
   2.Type a title for the feature; for example, Convert Document.
   3.Type a description for the feature; for example, This feature converts Word Open XML documents by using Word Automation Services.
   4.Accept the Web default feature scope, which gives the SharePoint Server 2010 farm administrators the ability to enable or disable the feature on a per-site basis.
 
After you create the feature, add the new context menu item.
To add a context menu item
 
   1.In the Solution Explorer, right-click the project, point to Add, and then click New Item…
   2.In the Add New Item dialog, select Empty Element to create a blank element file in which you can add the XML code that defines the context menu item.
   3.Type a name for the element; for example ContextMenuItem.
   4.Click Add to add the element to the project. The new element appears in the Solution Explorer.
   5.In the Solution Explorer, double-click Elements.xml to open it for editing.
   6.In the XML for the Elements.xml file, add the following XML code in the <Elements> element.
     
 
      <CustomAction Id="ConvertDocument" RegistrationType="FileType" RegistrationId="docx" Location="EditControlBlock" Sequence="106" Title="Convert Document"></CustomAction>
 
      The XML code defines the new document conversion custom action by setting the following attributes:
  • Id specifies an arbitrary unique ID for this action; in this case, ConvertDocument.
  • RegistrationType specifies when this context menu item appears. In this case, you use FileType to specify that the new context menu item is associated with a specific file name extension.
  • RegistrationId specifies the file type to use for this context menu item. In this case, you use docx to limit the menu item to files that have the .docx file name extension.
  • Location specifies where to add the menu item. In this case, you use EditControlBlock to place the action on the list item context menu.
  • Sequence specifies where the item appears relative to the other items in the menu.
  • Title specifies the name of the custom menu item; for example, ConvertDocument.
 7.In the <CustomAction> element, add the following XML code.
     
 
      <UrlAction Url="~site/_layouts/ConvertItem/ConvertItem.aspx?ListId={ListId}&amp;ItemId={ItemId}&amp;ItemUrl={ItemUrl}"/>
 
      The XML code defines a URL to a SharePoint Web page that opens when the user invokes this custom action. The URL starts with ~site/, which resolves to the URL of the current SharePoint Server 2010 site. The URL also specifies three query parameters and their associated tokens:
  • {ListId}, which resolves to the ID of the parent list.
  • {ItemId}, which resolves to the ID of the list item.
  • {ItemUrl}, which resolves to the site-relative URL of the list item.
 
Here is example of Custom Action
<CustomAction
Id="MyId"
RegistrationType="ContentType"
RegistrationId="0x0101[Guid]"
Location="EditControlBlock"
ImageUrl="/_layouts/images/EDIT.GIF"
Sequence="106"
Title="Edit Procedure">
<UrlAction Url="~site/MyList/Forms/EditForm.aspx?ID={ItemId}&amp;List={ListId}"/>
</CustomAction>
 
-----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction  GroupId="SiteCollections" Id="PrintHelloWorld" Sequence="100" Location="Microsoft.SharePoint.Administration.Applications" Title="Print Hello World" RequiredAdmin="Delegated" >
<UrlAction Url="/_layouts/HelloWorld/hello.aspx"/>
</CustomAction>
</Elements>
 
---------------------------------------------
 <CustomAction Id="CampaignOpp.SendToAdministration"
  RegistrationType="ContentType"
  RegistrationId="0x0100474BBA4EC75C724FB75F41D8E6E4E29801"
  ImageUrl="/_layouts/images/32316.GIF"
  Location="EditControlBlock"
  Sequence="240"
  Title="Send to Administration" >
  <UrlAction Url="~site/_layouts/MyFeature/SendToAdministration.aspx?ItemId={ItemId}&amp;ListId={ListId}"/>
 </CustomAction>
 
---------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="ECBViewNewWindow"
RegistrationType="List"
RegistrationId="107"
Location="EditControlBlock"
Sequence="199"
Title="View (new window)"
Description="Open this item in a new window (rather than a modal box)"
ImageUrl="/_layouts/images/LIST.gif">
<UrlAction
Url="javascript:window.open(‘DispForm.aspx?ID={ItemId}');"
/>
</CustomAction>
</Elements>
--------------------------------------------
 

Monday, January 17, 2011

Add Solution / Deploy Solution

Hi,

If you want to install a wsp file in SharePoint, you can use these script to install :

Command # 1 : This command will add the solution in SharePoint (Reference)

"%CommonProgramFiles%\Microsoft Shared\web server extensions\14\BIN\stsadm.exe" -o addsolution -filename C:\Gaurav\SPSolution.TaskListRollup.wsp

Command # 2 : This command will deploy the solution in SharePoint (Reference)

"%CommonProgramFiles%\Microsoft Shared\web server extensions\14\BIN\stsadm.exe" -o deploysolution -name SPSolution. TaskListRollup.wsp -local -allowgacdeployment –allcontenturls

Enjoy !

Sunday, January 16, 2011

Hide Web Part Headers with SharePoint 2010

Hide a web part header in SharePoint 2010.
1.  Add a content editor web part to your page.
2. Edit the Web Part
3. Click in the content area of the web part, click HTML and select “Edit HTML Source”
4. Put the following code in the web part:
   <style>
      TR.ms-viewheadertr > TH.ms-vh2 {
      DISPLAY: none
      }
   </style>
5. Click “OK”
6. Expand “Appearance” (on the right side of the page)
7. Set the chrome type to “None”
8. Click “OK” and then save and check in your page.
The headers of your web part should now be hidden.  This can be extremely helpful when your page contains a web part using “boxed” for your style when creating a list view.  The only downside to this approach is if you have multiple web parts on a single page, it will hide the headers for all the web parts on your site.

Tuesday, January 11, 2011

Add custom menu actions programmatically in SharePoint 2010

using (SPSite site = new SPSite("http://moss.dev.com"))
{ 
        using (SPWeb web = site.OpenWeb())
        {
            SPContentType contentType = web.ContentTypes["Curriculum Vitae"];

            SPUserCustomAction action = web.UserCustomActions.Add();
            action.RegistrationType = SPUserCustomActionRegistrationType.ContentType;
            action.RegistrationId = contentType.Id.ToString();
            action.Location = "EditControlBlock";
            action.Sequence = 450;
            action.Title = "Test";
            action.Rights = SPBasePermissions.EditListItems;
            action.Url = "http://www.google.com";

            action.Update();
        }
}

Sunday, January 2, 2011

Add favicon icon to site

Add favicon icon to site

In SharePoint if you need to add favicon, you can do so easily by using SharePoint Out-of-box control SPShortcutIcon. The following code snippet shows how you can set the favicon:
<SharePoint:SPShortcutIcon runat=”server” IconUrl=”YourIconUrl”/>

Saturday, January 1, 2011

Steps to set Form based authentication (FBA) for SharePoint 2010

1.       DOWNLOAD FBA User Management Tool

          Go to “C:\Windows\Microsoft.NET\Framework\v2.0.50727”.

2.       Open file “aspnet_regsql.exe” (with Run as Administrator).

                                I.            You will get an installation form. Hit “Next” button.


                              II.            Click on “Configure SQL Server for application services” then hit “Next” button.


                            III.            Now provide server name to connect & install new database for Membership. Now hit “Next” button.

                            IV.            Now you get a summary page on which you will get server name & its new database name called “aspnetdb”. Click on “Next” button.


                              V.            Now database has been created. Click on “Finish” button.


3.       Install FBA tool.
4.       Create a new Site collection (suppose we called it “A”).
5.       Extend this site (Suppose we called it “B”).
                                I.            Open Central Administration.
                              II.            Click on Application Management.
                            III.            Click on Manage Web application.


                            IV.            Click on “Site A” & then hit Extend button on ribbon.


1.       Click on Create a new IIS web site.
2.       Provide name & port number (optional).
3.       Provide host header (optional)
4.       Select Anonymous Access to –No
5.       Use Secured Socket layer – No

6.       Check on Enable Windows Authentication. Check On Integrated windows authentication & select “NTLM”.

7.       Check Enable Forms Based Authentication.  In “ASP.NET Membership provider name” put “SqlMember” & in ASP.NET Role manager name put “SqlRole”.

8.       Select – Default Sign in Page.
9.       Select Zone.
10.   Click OK.

11.   After creating this site, Test this site.

6.       Make changes in web.config files.
                                I.            Open inetmgr.
                              II.            Explore Site A & take back up of web.config file.
1.       Open web.config file.
2.       Put this connection string just after  configSections>
<connectionStrings>
    <clear />
    <add name="AspNetSqlMembershipProvider" connectionString="data source=test-share3\sharepoint;Integrated Security=SSPI;Initial Catalog=aspnetdb" providerName="System.Data.SqlClient" />
  connectionStrings>
3.        Search for entry <PeoplePickerWildcards> & put this entry within this tag.
<add key="SqlMember" value="%" />
               <add key="SqlRole" value="%" />
4.       Search for entry <membership> & < roleManager> replace whole entry with :



<membership defaultProvider="i" userIsOnlineTimeWindow="15" hashAlgorithmType="">
      <providers>
        <clear />
        <add connectionStringName="AspNetSqlMemberShipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" passwordAttemptWindow="10" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" name="SqlMember" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, &#xD;&#xA;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      </providers>
    </membership>
    <roleManager enabled="true" cacheRolesInCookie="false" cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" defaultProvider="c" createPersistentCookie="false" maxCachedResults="25">
      <providers>
        <clear />
        <add connectionStringName="AspNetSqlMemberShipProvider" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add applicationName="/" name="SqlRole" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, &#xD;&#xA;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      </providers>
    </roleManager>

 
5.       Now save & close this web.config file.

                            III.            Explore Site B (Extended new site) & take back up of web.config file.
1.       Open web.config file.
2.       Put this connection string just after  configSections>
<connectionStrings>
    <clear />
    <add name="AspNetSqlMembershipProvider" connectionString="data source=test-share3\sharepoint;Integrated Security=SSPI;Initial Catalog=aspnetdb" providerName="System.Data.SqlClient" />
  connectionStrings>
3.        Search for entry <PeoplePickerWildcards> & put this entry within this tag.
<add key="SqlMember" value="%" />
               <add key="SqlRole" value="%" />
4.       Search for entry <membership> & < roleManager> replace whole entry with :
<membership defaultProvider="i" userIsOnlineTimeWindow="15" hashAlgorithmType="">
      <providers>
        <clear />
        <add connectionStringName="AspNetSqlMemberShipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" passwordAttemptWindow="10" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" name="SqlMember" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, &#xD;&#xA;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      </providers>
    </membership>
    <roleManager enabled="true" cacheRolesInCookie="false" cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" defaultProvider="c" createPersistentCookie="false" maxCachedResults="25">
      <providers>
        <clear />
        <add connectionStringName="AspNetSqlMemberShipProvider" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add applicationName="/" name="SqlRole" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, &#xD;&#xA;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      </providers>
    </roleManager>
5.       Now save & close this web.config file.
                            IV.            Explore Central Administration Site & take back up of web.config file.
1.       Open web.config file.
2.       Put this connection string just after  configSections>
<connectionStrings>
    <clear />
    <add name="AspNetSqlMembershipProvider" connectionString="data source=test-share3\sharepoint;Integrated Security=SSPI;Initial Catalog=aspnetdb" providerName="System.Data.SqlClient" />
  connectionStrings>
3.        Search for entry <PeoplePickerWildcards> & put this entry within this tag.
<add key="SqlMember" value="%" />
               <add key="SqlRole" value="%" />
4.       Search for entry <membership> & < roleManager> replace whole entry with :
     
   <membership defaultProvider="i" userIsOnlineTimeWindow="15" hashAlgorithmType="">
      <providers>
        <clear />
        <add connectionStringName="AspNetSqlMemberShipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" passwordAttemptWindow="10" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" name="SqlMember" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, &#xD;&#xA;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      </providers>
    </membership>
    <roleManager enabled="true" cacheRolesInCookie="false" cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" defaultProvider="c" createPersistentCookie="false" maxCachedResults="25">
      <providers>
        <clear />
        <add connectionStringName="AspNetSqlMemberShipProvider" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add applicationName="/" name="SqlRole" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, &#xD;&#xA;Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, &#xD;&#xA;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      </providers>
    </roleManager>  
     
   
5.       Now save & close this web.config file.

                              V.            Now click on “SharePoint web services” & then click on “SecurityTokenServiceApplication” and explore it.


1.       Search for tag system.net> & paste this just after system.net> tag
<connectionStrings>
            <clear />
            <add name="AspNetSqlMembershipProvider" connectionString="data source=test-share3\sharepoint;Integrated Security=SSPI;Initial Catalog=aspnetdb" providerName="System.Data.SqlClient" />
      connectionStrings>
      <system.web>
            <membership defaultProvider="SqlMember">
                  <providers>
                        <add connectionStringName="AspNetSqlMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" passwordAttemptWindow="10" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" name="SqlMember" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0,      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                  providers>
            membership>

            <roleManager defaultProvider="SqlRole" enabled="true">
                  <providers>
                        <add connectionStringName="AspNetSqlMembershipProvider" applicationName="/" name="SqlRole" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                  providers>
            roleManager>
      system.web>
2.       Now Save & Close this. Web.config file.

7.       Go to Center Administration, Click on Manage Web Application.
8.       Select Site “A” & Click on User Policy.
                                I.            You will get a dialog box


                              II.            Click on “Add Users”, you will see the below dialog box, which will ask you to select the zone for which you want to add the users. Select zone and click next


                            III.            In the next window, “Choose Users” then “Choose Permission” for those users and click Finish.



Important Note:  Don’t forget to grant “dbOwner” access to NT/AUTHORITY user on aspnetdb database.

-----------------------------------------------------------------------------------
DOWNLOAD FBA User Management Tool
-----------------------------------------------------------------------------------