Friday, May 6, 2011

"Save library as template" link is missing in SharePoint site

Some of the document libraries and list, "Save library as template" link is hidden by default. If you go to  "View All Site Content" and have a look at the description next to each library/list, the description that says "This system library was created by the Publishing feature.." will have the "Save library as template" link hidden.

This behaviour is by default, however we have a workaround for this. Go to the "Document Library Settings" page. You should see the URL address like this ".../listedit.aspx?List={GUID}", change the "listedit" to "savetmpl" and the URL look like this "../savetmpl.aspx?List={GUID}", now you will be able to save the library as a template.

This method is not recommended, but it works. If you have any workflow bound to the library then you may have some issues,but works fine if you just want to create a template for document settings, Columns and views.

Thursday, May 5, 2011

To prevent users from creating folders in SharePoint document libraries

Using SharePoint 2007;

The OOB method to remove the "New Folder" menu will prevent users only creating folder from the standard view and users are still be able to upload/create folders from explorer view. Below is the feature code used to prevent users from creating folders in document library even in explorer view.

Feature.xml

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="62b28298-e3fc-4ccc-a2ea-3f92b7e9a21e"
          Title="Disable Folders"
          Description="Feature to disable creating new folders in document libraries in the site"
          Version="12.0.0.0"
          Hidden="FALSE"
          Scope="Web"
    ActivateOnDefault="FALSE"
          DefaultResourceFile="core"
          xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
  </ElementManifests>
</Feature>


Elements.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <Receivers ListTemplateId="101">
  <Receiver>
   <Name>AddingEventHandler</Name>
   <Type>ItemAdding</Type>
   <SequenceNumber>10000</SequenceNumber>
   <Assembly>AAAA.BBB.AllUsers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5</Assembly>
   <Class>AAAA.BBB.AllUsers.DisableFoldersInLib</Class>
   <Data></Data>
   <Filter></Filter>
  </Receiver>
 </Receivers>
</Elements>

Code:
 public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
            //If the new created file type is "folder" then the following conditions will be true
            if ((properties.BeforeUrl != properties.AfterUrl &&
                properties.ListItem == null &&
                properties.ListItemId == 0) ||
                properties.AfterProperties["ContentType"].ToString() == "Folder")
            {
                properties.Cancel = true;
                properties.ErrorMessage = "You are not allowed to create new Folders in this document library. Please tag the files with Metadata instead of creating folders.";
            }
        }

The source code of this feature is available at Technet Gallery

Thursday, April 14, 2011

Parent child relationship for lists in SharePoint

If you are looking for a project/child relationship for a Projects and Tasks list.  You can try using the
Budgeting and Tracking Multiple Projects Template which is part of the SharePoint "Fantastic 40" Site Templates. Basically this template allows you to track all your projects and tasks. When you view the project item, you also get a Related tasks, Related issues and Related milestones data views on the same page.Any tasks, issues or milestones you add on this page will be associated with that particular project and will rollup onto a nice looking dashboard.

Refer to the following URL to download the template.
http://www.microsoft.com/downloads/en/details.aspx?FamilyId=04FDA604-BAB0-4E43-8B88-38101DFE121A&displaylang=en

Refer to the following site which is created using this template.
http://demo.sharesquared.com/PTPM/BTMP/default.aspx


In case if you want any extra customization, you can customize this site and save as a template to reuse it.

Thursday, March 31, 2011

Move SharePoint Site Collection as a Subsite

Environment: SharePoint 2007/2010/2013

Requirement: To move a site collection as a subsite to another site collection, we can make use of STSADM or Powershell import/export command.

Following are the steps to achieve this

Assume that, we need to move the site collection http://sitecollection1/sites/asite to another site collection http://sitecollection2/sites/bsite as a subsite.


Steps

1. Export the site collection (http://sitecollection1/sites/asite) using STSADM command line tool

using stsadm command
stsadm.exe -o export -url http://sitecollection1/sites/asite -filename c:\backups\sc_asite.bak –includeusersecurity –nofilecompression

using powershell
Export-SPWeb -Identity http://sitecollection1/sites/asite -Path C:\backups\sc_asite.bak -IncludeUserSecurity -NoFileCompression

2. Create a new site with Blank Site template in the other site collection (http://sitecollection2/sites/bsite). Assume the blank site name is csite

3. Import the backed up site collection in c:\mybckup\sc_asite.bak

using stsadm command
stsadm.exe -o import -url http://sitecollection2/sites/bsite/csite -filename c:\backups\sc_asite.bak 
-includeusersecurity -nofilecompression

using powershell
Import-SPWeb http://sitecollection2/sites/bsite/csite  -Path c:\backups\sc_asite.bak -IncludeUserSecurity -NoFileCompression


After migration, the site collection 1 will be available under the following URL as a subsite http://sitecollection2/sites/bsite/csite



Tuesday, March 29, 2011

Unable to cast object of type 'XXXXXXXX' to type 'Microsoft.SharePoint.SPFeatureReceiver'

I got the following error on deployment
"Unable to cast object of type  XXXX.YYYYY' to type 'Microsoft.SharePoint.SPFeatureReceiver'

Resolution:
Removed the following entries ReceiverAssembly & ReceiverClass from feature.xml and the issue is resolved

ReceiverAssembly="XXXX.YYYYY' , Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"
ReceiverClass="XXXX.YYYYY.ZZZZZ"

Friday, March 25, 2011

To provision a file in Pages document library

Below is the feature file that is used to upload a file in to Pages document library on feature activation

Feature.xml

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="21a53317-2fd7-4f21-b5c4-efc018b88154"
          Title="Add Site Users List Template "
          Description="Upload the 'All Site Users' list template to site collection"
          Version="12.0.0.0"
          Hidden="FALSE"
          Scope="Site"
    ActivateOnDefault="FALSE"
          DefaultResourceFile="core"
          ReceiverAssembly="xxxx.yyy.ListAllUsers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"
          ReceiverClass="xxxx.yyy.ListAllUsers.AddGetUsersList"       
          xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
   <ElementFile Location="webpartpage.aspx"/>
  </ElementManifests>
</Feature>

Elements.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Pages" Path="" Url="Pages">
<File Name="webpartpage.aspx" Url="webpartpage.aspx" IgnoreIfAlreadyExists="FALSE"/>
</Module>
</Elements>

Once the feature is activated the file is uploaded to the document library, however I cannot view the file in default view but able to view in the Explorer view, currently working on that