Monday, February 27, 2012

How to make Dataview Web Part Portable?

When working with SharePoint DataView Customizations, by default you can not just copy paste the data view pages into new environment or even restore them from backup. This is because: The Data View Web Part uses List ID instead of List Name.

So, How to make the Dataview Portable from one environment to another? Simple! Replace the ListID to ListName and provide the List name in the place of GUID.

Important:
Please note, These changes must be done once you complete all the customizations to the dataview webpart. You will not be able to make changes using Design view in SharePoint designer after making these changes, because SharePoint designer uses ListID parameter, which we are going to replace!
 
As always, Take a Backup!

Detailed steps:
    1. Open the site & Web part page in SharePoint Designer.

    2. Search and Replace ListID with ListName
How to make Dataview Portable
   3. Replace the DefaultValue="GUID" with  DefaultValue="Your List Name"

That's All!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Building Branding Solution with Feature Stapler for SharePoint 2007

Feature Staplers are the best way to build branding solutions in SharePoint. Once deployed branding will be automatically applied based on Site definition.

Overall Steps: Create a WSP Project and add 2 features in it.
  • One for actual Branding with Feature handler code - Applies Branding on activated
  • and another one for Stapling the feature - Binds the feature with site with Site definitions.
 Lets get started.

1. Create a WSP Project in Visual Studio:
SharePoint 2007 Branding Solution with WSP Builder
2. Right click the Project and choose "Add > New Item" to the Project
Create Branding Feature SharePoint
3. Under "WSPBuilder" choose "Feature with Receiver", Enter the Name for the feature.

4. Set the scope for the Feature as "Web" meaning sub-site.
SharePoint Branding Scope

5. Now, add the feature for FeatureStaple: Add New Item, and this time choose "Blank Feature"
SharePoint Branding Feature Stapler

6. Set the scope for FeatureStapler as "WebApplication"
SharePoint Branding Stapler Scope

7.Add your own Master Page,  CSS, Site Map files, Custom Navigation Provider, etc. to the solution.
Overall Project Structure:
branding moss 2007

Update the Feature.xml with additional entries like Title, Icon, as below code.
Feature.xml on Portal.Branding:
<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="4b4b1479-2d1e-4e4d-a04a-a5f34c96309b"
          Title=" Portal Branding"
          Description="Branding Solution for  Portal"
          Version="12.0.0.0"
          Hidden="FALSE"
          Scope="Web"
          ImageUrl="bpCorp\feature-icon.png"
          DefaultResourceFile="core"
          ReceiverAssembly="Portal.Branding, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb1f1034da9a39ca"
          ReceiverClass="Portal.Branding.Branding"
          xmlns="http://schemas.microsoft.com/sharepoint/">
   <ElementManifests>
    <ElementManifest Location="elements.xml"/>
   </ElementManifests>
 <Properties>
     <Property Key="SiteLogoUrl" Value="/_layouts/images/BPCorp/bp-logo.png"/>
  </Properties>
</Feature>

Element.xml on Portal.Branding
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="MasterPagesModule"  List="116" Url="_catalogs/masterpage" Path="MasterPage">
        <File Url="BPCorp.master" Type="GhostableInLibrary" />
    </Module>
 </Elements>

Feature.xml on Portal.Branding.FeatureStapler
<Feature
 Id="247385FE-1A70-4cfc-980C-5517B7609D58"
  Title=" Branding Stapler"
  Scope="WebApplication"
  xmlns="http://schemas.microsoft.com/sharepoint/" >
  <ElementManifests>
    <ElementManifest Location="elements.xml" />
  </ElementManifests>
</Feature>

 
Element.xml on Portal.Branding.FeatureStapler
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <!-- staple all site defitions to Branding -->
  <FeatureSiteTemplateAssociation
    Id="4b4b1479-2d1e-4e4d-a04a-a5f34c96309b"
    TemplateName="GLOBAL" />
  
</Elements>

and Finally, our feature activation code goes here:

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

namespace Portal.Branding
{
    class Branding : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            //Set the Customized Master page as Default & Cutom Master page
            SPWeb rootWeb = properties.Feature.Parent as SPWeb;
            
            // Calculate relative path to site from Web Application root.
            string WebAppRelativePath = rootWeb.ServerRelativeUrl;
            if (!WebAppRelativePath.EndsWith("/"))
            {
            WebAppRelativePath += "/";
            }

            rootWeb.MasterUrl = WebAppRelativePath + "_catalogs/masterpage/BPCorp.master";
            rootWeb.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/BPCorp.master";
            rootWeb.AlternateCssUrl = WebAppRelativePath + "_layouts/1033/styles/BPCorp.css";

            //Set the Logo
           rootWeb.SiteLogoUrl = properties.Feature.Properties["SiteLogoUrl"].Value; 

            rootWeb.Update();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            //Revert the Master page to "default.master"
            SPWeb rootWeb = properties.Feature.Parent as SPWeb;

            // Calculate relative path to site from Web Application root.
            string WebAppRelativePath = rootWeb.ServerRelativeUrl;
            if (!WebAppRelativePath.EndsWith("/"))
            {
                WebAppRelativePath += "/";
            }

            rootWeb.MasterUrl = WebAppRelativePath + "_catalogs/masterpage/default.master";
            rootWeb.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/default.master";
            rootWeb.AlternateCssUrl = "";

            //Set the Logo
            rootWeb.SiteLogoUrl = "/_layouts/images/titlegraphic.gif"; 

            rootWeb.Update();
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            //throw new Exception("The method or operation is not implemented.");
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            //throw new Exception("The method or operation is not implemented.");
        }
    }
}
Now, our solution is ready! Build the WSP, Install the solution, Activate the FeatureStapler Feature at web application level. Activate the Branding Feature for existing sites.
Important: Since we used Feature Stapling, new sites will get this branding automatically on their create event. How about existing sites? well, for existing sites, we need to activate this feature manually in order to get the branding applied!

MSDN post on building Feature for Master page:http://msdn.microsoft.com/en-us/library/ms441170.aspx

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, February 26, 2012

Workflows Inventory Report for SharePoint

Requirement from my CIO: Salaudeen, Get me a SharePoint Workflows Report with Total No. of workflows wherever its running, for our intranet SharePoint site with Site Name, List Name, Workflow Name, and No. of Instances, etc.

Solution: As usual dive into the object model code (This can be achieved with PowerShell as well). Here it is.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Workflow;
using System.IO;

namespace GetWorkflowReport
{
    class GetWorkflowsReport
    {
        static void Main(string[] args)
        {
            string site;

            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Enter the Web Application URL:");
                    site = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                }

                SPSite tmpRoot = new SPSite(site);
                SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;

                //objects for the CSV file generation
                StreamWriter SW;
                SW = File.AppendText("c:\\WorkflowReport.csv");

                //Write the CSV Header
                SW.WriteLine("Site Collection Name, Site Name, Site URL, List Name, List URL, Workflow Name, Running Instances");

                //Enumerate through each site collection
                foreach (SPSite tmpSite in tmpRootColl)
                {
                    //Enumerate through each sub-site
                    foreach (SPWeb tmpWeb in tmpSite.AllWebs)
                    {
                         //Enumerate through each List
                        foreach (SPList tmpList in tmpWeb.Lists)
                        {
                             
                            //Enumerate through associated workflows
                            foreach(SPWorkflowAssociation tmpSPWorkflowAssociation in tmpList.WorkflowAssociations)
                            {
                               // If you want to Limit to SPD workflows: check tmpSPWorkflowAssociation.BaseTemplate == null
                           //Skip the Previous versons of workflows
                                if(!tmpSPWorkflowAssociation.Name.Contains("Previous Version"))
                                {
                                    
                                //Remove the , in Site Name, document names and write them into the CSV file
                                    SW.WriteLine(tmpSite.RootWeb.Title.Replace(",", " ") + "," + tmpWeb.Title.Replace(",", " ") + "," + tmpWeb.Url + "," + tmpList.Title.Replace(",", " ") + "," + tmpWeb.Url + "/" + tmpList.RootFolder.Url + "," + tmpSPWorkflowAssociation.Name.Replace(",", " ") + "," + tmpSPWorkflowAssociation.RunningInstances);
                                }

                            }
                        }
                    }
                     
                                                      
                }

                //Close the CSV file object 
                SW.Close();
                //Dispose of the Root Site Object
                tmpRoot.Dispose();
                Console.WriteLine(@"Report Generated Successfull at c:\WorkflowReport.csv. Press ""Enter"" key to Exit");

                //Just to Pause
                Console.ReadLine();
            }

            catch (Exception ex)
            {
                //Log the exception to event log
                System.Diagnostics.EventLog.WriteEntry("Get Workflow Report", ex.Message);
            }
        }
    }
}
and the output goes like this:



Update:
Another workflow Report:
This time the requirement is: Get me the workflows for all the lists and Libraries with No. of workflows completed, In Progress, Terminated, Cancelled.

Alright, I changed the code slightly:
class GetWorkflowsReport
    {
        static void Main(string[] args)
        {
            string site;

            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Enter the Web Application URL:");
                    site = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                }

                SPSite tmpRoot = new SPSite(site);
                SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;

                //objects for the CSV file generation
                StreamWriter SW;
                SW = File.AppendText("c:\\WorkflowReportEx.csv");

                //Write the CSV Header
                SW.WriteLine("Site Collection Name, Site Name, Site URL, List Name, List URL,  Cancelled,Completed, Faulting,Running,Terminated");

                //Enumerate through each site collection
                foreach (SPSite tmpSite in tmpRootColl)
                {
                    //Enumerate through each sub-site
                    foreach (SPWeb tmpWeb in tmpSite.AllWebs)
                    {
                         //Enumerate through each List
                        foreach (SPList tmpList in tmpWeb.Lists)
                        {
                            //Initialise the variables
                            int Cancelled=0;
                            int Completed=0;
                            int Faulting=0;
                            int Running=0;
                            int Terminated=0;

                            if (tmpList.WorkflowAssociations.Count > 0)  //IF the List has any workflows associated
                            {
                                foreach (SPListItem oSPListItem in tmpList.Items)
                                {
                                    foreach (SPWorkflow oSPWorkflow in oSPListItem.Workflows)
                                    {
                                        //Get the state of the workflow, Whether completed, Terminated, etc
                                        switch (oSPWorkflow.InternalState)
                                        {
                                            case SPWorkflowState.Cancelled:
                                                Cancelled++; ;
                                                break;

                                            case SPWorkflowState.Completed:
                                                Completed++;
                                                break;

                                            case SPWorkflowState.Faulting:
                                                Faulting++;
                                                break;

                                            case SPWorkflowState.Running:
                                                Running++;
                                                break;

                                            case SPWorkflowState.Terminated:
                                                Terminated++;
                                                break;
                                        }
                                   }
                            }
                                //Remove the , in Site Name, etc and write them into the CSV file
                                SW.WriteLine(tmpSite.RootWeb.Title.Replace(",", " ") + "," + tmpWeb.Title.Replace(",", " ") + "," + tmpWeb.Url + "," + tmpList.Title.Replace(",", " ") + "," + tmpWeb.Url + "/" + tmpList.RootFolder.Url + "," +Cancelled + ","  +Completed+ "," + Faulting + ","  + Running+ "," +Terminated);
                            }
                        }
                      }
                    }

                //Close the CSV file object 
                SW.Close();
                //Dispose of the Root Site Object
                tmpRoot.Dispose();
                Console.WriteLine(@"Report Generated Successfull at c:\WorkflowReportEx.csv. Press ""Enter"" key to Exit");

                //Just to Pause
                Console.ReadLine();
            }

            catch (Exception ex)
            {
                //Log the exception to event log
                System.Diagnostics.EventLog.WriteEntry("Get Workflow Report Extended", ex.Message);
            }
        }

and the output :



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, February 24, 2012

What is my SQL Server Version, Service Pack, Edition

Requirement: Wanted to check the installed SQL Server version service pack level.
SELECT @@version ? It didn't give me the Service pack information.

Query to Check SQL Server version, Service pack and Edition:
SELECT SERVERPROPERTY('productversion') [Product Version], 
          SERVERPROPERTY ('productlevel') [Service Pack],
                    SERVERPROPERTY ('edition') [Edition]

sql server version and service pack check

KB Article: http://support.microsoft.com/kb/321185

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, February 23, 2012

Install PowerShell in Windows 2003

Need PowerShell in Windows 2003?  Install "Windows Management Framework core" which includes Windows PowerShell 2.0. You need to have SP2 or later in Windows 2003.
Once installed, you can access PowerShell  from Start > All Programs > Accessories > Windows PowerShell
Install PowerShell in Windows 2003


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, February 19, 2012

Version History Size Report for Entire SharePoint Web Application

Ever wanted to get a report on versioning sizes on SharePoint? Unlimited No. of versions enabled in various document library across web application. As part of regular auditing, wanted to generate report for the entire web application ,with Number of versions, Amount of storage consumed by versions. Of course there are some third-party products like Axceler Control Point with additional capabilities. But How about wring my own code? Sounds good.

Here is my code:
Tested in SharePoint 2010 and MOSS 2007.

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

namespace SharePointReporting
{
    class GetVersioningReport
    {
        static void Main(string[] args)
        {
            string site;
            StreamWriter SW;
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Enter the Web Application URL:");
                    site = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                }

                SPSite tmpRoot = new SPSite(site);
                SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;

                //objects for the CSV file generation
                SW = File.AppendText("c:\\VersioningReport.csv");

                //Write the CSV Header
                SW.WriteLine("Site Name, Library, File Name, File URL, Last Modified, No. of Versions, Latest Version Size -KB,Total Versions Size - MB");

                //Enumerate through each site collection
                foreach (SPSite tmpSite in tmpRootColl)
                {
                    //Enumerate through each sub-site
                    foreach (SPWeb tmpWeb in tmpSite.AllWebs)
                    {
                        //Enumerate through each List
                        foreach (SPList tmpList in tmpWeb.Lists)
                        {
                            //Get only Document Libraries & Exclude specific libraries
                            if (tmpList.BaseType == SPBaseType.DocumentLibrary &  tmpList.Title!="Workflows" & tmpList.Title!= "Master Page Gallery" & tmpList.Title!="Style Library" & tmpList.Title!="Pages")
                            {
                                  foreach (SPListItem tmpSPListItem in tmpList.Items)
                                    {

                                        if (tmpSPListItem.Versions.Count > 5)
                                        {
                                            
                                            SPListItemVersionCollection tmpVerisionCollection = tmpSPListItem.Versions;

                                            //Get the versioning details
                                            foreach (SPListItemVersion tmpVersion in tmpVerisionCollection)
                                             {
                                                int versionID = tmpVersion.VersionId;
                                                string strVersionLabel = tmpVersion.VersionLabel;
                                             }

                                            //Get the versioning Size details
                                            double versionSize = 0;
                                            SPFile tmpFile = tmpWeb.GetFile(tmpWeb.Url + "/" + tmpSPListItem.File.Url);

                                            foreach (SPFileVersion tmpSPFileVersion in tmpFile.Versions)
                                            {
                                                versionSize = versionSize + tmpSPFileVersion.Size;
                                            }
                                            //Convert to MB
                                            versionSize= Math.Round(((versionSize/1024)/1024),2);

                                            string siteName;
                                            if (tmpWeb.IsRootWeb)
                                            {
                                                siteName= tmpWeb.Title +" - Root";
                                            }
                                            else
                                            {
                                                siteName=tmpSite.RootWeb.Title + " - " + tmpWeb.Title;
                                            }

                                            //Log the data to a CSV file where versioning size > 0MB!
                                            if (versionSize > 0)
                                            {
                                                SW.WriteLine(siteName + "," + tmpList.Title + "," + tmpSPListItem.Name + "," + tmpWeb.Url + "/" + tmpSPListItem.Url + "," + tmpSPListItem["Modified"].ToString() + "," + tmpSPListItem.Versions.Count + "," + (tmpSPListItem.File.Length / 1024) + "," + versionSize );
                                            }
                                        }
                                   }
                               }
                          }
                      }
                 }

                //Close the CSV file object 
                SW.Close();

                //Dispose of the Root Site Object
                tmpRoot.Dispose();
                
                //Just to pause
                Console.WriteLine(@"Versioning Report Generated Successfull at c:\VersioningReport.csv. Press ""Enter"" key to Exit");
                Console.ReadLine();
            }

            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("Get Versioning Report", ex.Message);
            }
        }
    }
}

After adding headers and Pivot tables to the CSV file via Excel, it was fantastic Report!! You can get Individual versions ID, Lables, Size information by slightly changing the code.
SharePoint Version History Size Report

   Add a pivot table to make the SharePoint version history report little more meaningful.
sharepoint version history report
I've Created a Project in CodePlex for this utility: http://versioningsizereport.codeplex.com/ .

For PowerShell version of the above code, Refer my another post: SharePoint Document Versions Size Report with PowerShell


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, February 17, 2012

Using owssvr.dll to retrieve List data in XML format

Owssvr.dll is a traditional Remote Procedure Call method to remotely invoke functions in SharePoint. It can be used to retrieve data from SharePoint list as well.

syntax:
http://sharepoint.com/_vti_bin/owssvr.dll?Cmd=Display&List=<<LIST-GUID>>&XMLDATA=TRUE

E.g.
https://intranet.sharepoint.com/_vti_bin/owssvr.dll?Cmd=Display&List={6685db48-013f-4934-8147-b7a6014eccc9}&XMLDATA=TRUE

Other options:
Filter &  View
Append -  FilterField1=<<Field-Internal-Name>>&FilterValue1=<<Value-of-the-field>>
e.g:
FilterField1=Domain&FilterValue1=Sales
View={ViewGuid}


How to get the List GUID?
Go to List settings >> right click "Audience targeting settings" Say "Copy Shortcut". Now you will get something like: https://sharepoint.com/sites/Test/_layouts/ListEnableTargeting.aspx?List={6685db48-013f-4934-8147-b7a6014eccc9}
Highlighted is the GUID.

Output:
Using owssvr.dll to retrieve List data in XML format

Once you get the XML you can use it wherever required.
E.g.:
<script type="text/javascript">
function GetListData()
{
// Get the data from SharePoint List
var reqstring ="http://SharePoint.com/_vti_bin/owssvr.dll?Cmd=Display&List={6685db48-013f-4934-8147-b7a6014eccc9}&XMLDATA=TRUE";
var req = new ActiveXObject("MSXML2.XMLHTTP");
req.open("GET",reqstring,false);
req.send();

//Load response in XML Document
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.loadXML(req.responseText);
 //Traverse inside doc to retrieve values
 alert(data);
}
</script>

More Examples:
http://msdn.microsoft.com/en-us/library/ms478653.aspx
http://msdn.microsoft.com/en-us/library/ms416599.aspx
http://blogs.msdn.com/b/infopath/archive/2007/01/15/populating-form-data-from-sharepoint-list-views.aspx
http://sharepointfordeveloper.blogspot.co.uk/2012/03/sharepoint-rpc-protocols-examples-using.html

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Deploy and Activate Sandboxed Solutions in SharePoint 2010

Sandboxed solutions brings the benefit of deploying solutions to SharePoint Server without affecting any other process outside the sandbox. SharePoint 2010 Sandboxed solution can be deployed by Site collection administrators. Here is the guide on How to Deploy and activate sandboxed solution in SharePoint 2010.

Go to Site Actions >> Site Settings >> Solutions under the Galleries
deploy sandboxed solution sharepoint 2010
In Solutions tab, click Upload Solution button
how to deploy sandboxed solution sharepoint 2010
 Browse and select the WSP File from your sandboxed solution, click on "OK" to complete.
how to activate sandbox solution in sharepoint 2010The solution package is now in the site collection's solution gallery, but it is not yet deployed. In the Activate Solution dialog box, click Activate to activate the solution
activate sandboxed solution sharepoint 2010
 You will see the solution's activation status in the solution Gallery page.
sandbox solution in sharepoint 2010
  Depending on the solution, will see the sandboxed solution in action.
From the solution gallery page, we can deactivate, delete the solution further.
dectivate sandbox solution in sharepoint 2010

Using PowerShell to Deploy and Activate Sandboxed Solutions:

To upload a sandboxed solution to a site collection's Solution Gallery with PowerShell,
Add-SPUserSolution -LiteralPath d:\PrintListPackage.wsp -Site http://sharepoint.crescent.com/sites/dev

To activate the Sandboxed solution use: Install-SPUserSolution cmdlet
Install-SPUserSolution -Identity PrintListPackage.wsp -Site http://sharepoint.crescent.com/sites/dev

To Uninstall the Sandboxed solution:
Uninstall-SPUserSolution -Identity PrintListPackage.wsp -Site http://sharepoint.crescent.com/sites/dev

To Remove the Sandboxed solution:
Remove-SPUserSolution -Identity PrintListPackage.wsp -Site http://sharepoint.crescent.com/sites/dev


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Fix "The site collection containing this sandboxed solution has exceeded its daily resource usage quota."

When trying to activate a sandboxed solution, Got below error message:

"The site collection containing this sandboxed solution has exceeded its daily resource usage quota."

The site collection containing this sandboxed solution has exceeded its daily resource usage quota.
Solution: 
This is because of the Sandbox solution resource limit. To fix this issue, just increase the site collection Sandbox solution resource quota in site collection quotas and locks.

Go to: Central Administration >> Application Management >> Configure quotas and locks >> Pick the target site collection.
Increase the Sandbox solution resource quota
Increased the Sandbox solution resource quota under "Limit maximum usage per day to:   0 points" to 100 points, Problem solved!

In an another case, whey trying to deploy a sandbox solution from visual studio, it reported the same error "Error occurred in deployment step 'Add Solution': The site collection containing this sandboxed solution has exceeded its daily resource usage quota" and the fix is same!

Same thing applies to office 365! Set the "Resource Usage Quota" from  SharePoint Online Administration Center Microsoft released a KB: http://support.microsoft.com/kb/2536051

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, February 16, 2012

Create List Instance Feature for SharePoint 2010 in Visual Studio

Requirement: 
Create a new Link list with pre-populated list items as a feature based solution.

Steps:
1. Lets create a SharePoint 2010 list instance feature with Visual Studio. Create a New Empty SharePoint Project, Give it a name, I've named it as Crescent.Portal.DashboardLinkssharepoint 2010 list instance visual studio

2. In the next dialog box, Select either Farm solution or Sandboxed solution whichever applicable to your requirements. I've selected "Deploy as a Farm Solution"

3. Right click the Project in visual studio solution explorer >> Add >> New Item >> List Instance to  create new SharePoint 2010 list using visual studio
sharepoint 2010 create list instance visual studio
 4. Enter the List Instance settings: Link List Name, List to Instantiate, URL. Click Finish.
sharepoint 2010 create list visual studio

5. Now our project will look like the below screen. Look at the "FeatureId" attribute. This is the Feature ID of the Link List feature. In case, If you want to create a List instance for your own List definition, You can use the Feature ID of the particular List. (You can just get into 14 Hive, Templates and pick the relevant feature folder's Feature.xml file to get the feature Id)
sharepoint 2010 c# create list instance
6. Rename the Feature from "Feature1" to "DashboardLinks" in solution explorer. Get into the Feature designer (Right click the "DashboardLinks" and choose "View Designer"), Give it a meaning full title (Here I've given "Dashboard Links Feature") that will appear on the site features page. Add the DashboardLinks ListInstance Element to the feature.
create a list instance sharepoint 2010
7. Our requirement is to Pre-populate the Dashboard Links list. So, Lets add the <Data> element with values to the Elements.xml as below:
SharePoint 2010 list instance elements.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="Dashboard Links"
                OnQuickLaunch="TRUE"
                TemplateType="103"
                FeatureId="00bfea71-2062-426c-90bf-714c59600103"
                Url="Lists/DashboardLinks"
                Description="">
    <Data>
      <Rows>
        <Row>
          <Field Name="URL">http://Crescent.SharePoint.com/sites/PMO/Dashboard, PMO Dashboard</Field>
          <Field Name="Comments">PMO Dashboard Link</Field>
        </Row>
        <Row>
          <Field Name="URL">http://Crescent.SharePoint.com/sites/functional/Dashboard, Functional Dashboard</Field>
          <Field Name="Comments">Functional Dashboard Link</Field>
        </Row>
        <Row>
          <Field Name="URL">http://Crescent.SharePoint.com/sites/operations/Dashboard, Operational Dashboard</Field>
          <Field Name="Comments">Operations Dashboard Link</Field>
        </Row>
      </Rows>
    </Data>
    
  </ListInstance>
</Elements>

8. Build and deploy the Project (Just right click the Project in visual studio, choose Build and then choose Deploy)

9. Verify the feature is activated by going to Site actions >> Site settings >> Manage Site features (Under Site actions tab)
 sharepoint 2010 list instance feature

10. See it in action! List created in SharePoint using visual studio 2010 feature.sharepoint 2010 create list instance



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, February 15, 2012

Get the List Settings Page of any List

Problem:
There was a List in a site collection without any tool bars (They were removed purposefully). Had to change some columns in the list. Since the toolbar is disabled, could not get into : List settings from SharePoint Interface.

Solution:
For user created lists, the simplest way is, navigate to: Site actions >> Site Settings >> click on Site libraries and lists under "Site Administration". That will lead to a page from where we can pick a list to get its settings page.

How about SharePoint Server's lists/hidden lists? e.g. User Information List? Lets dig little more. Take a look at a typical list settings URL: http://sharepoint.com/_layouts/listedit.aspx?List={List-GUID} .Why don't we try the same with our List? We know the List Name and its location. But how to get the GUID of the list?

Well, There are many ways: Object Model, PowerShell, or Database Query.

Here, I'm using PowerShell: Say our List name is: "User Information List"
#Set-ExecutionPolicy RemoteSigned
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = New-Object Microsoft.SharePoint.SPSite("http://sharepoint.com")
$web = $site.OpenWeb()
$list=$web.lists["User Information List"]
write-host $list.id

SQL query way:
SELECT tp_ID FROM Lists WITH(NoLock) WHERE tp_Title ='User Information List'


So, we got the GUID of  List, lets hit the URL in browser. In my case it was:
http://sharepoint.com/_layouts/listedit.aspx?List={e8dc6de8-3f1c-4cac-9eb6-02ee80effe13} , Well done, Now I'm in List settings page!.

Tail: 
You can use the same technique for other list features like "Alert Me!". 
E.g. Typical Alert Me URL would be: . Just replace the {List GUID} with the GUID queried above, You can create alert for user information list!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Find Large Lists & Generate Report in SharePoint

Requirement: SharePoint was running with serious performance issues and wanted to get the report, where more than 2000 items stored in List/Library for the entire web application.

When users store large number of items in List or Library, SharePoint will definitely run into serious performance issues. This script will generate the report on List items count for the entire web application.

This code generates the CSV file, with details : List name, Site collection, Site URL, Item count. By this way, we can make sure we control the users activities by generating reports on our site content periodically. we can use this piece of code to generate the report on scheduled basis to get the List item count insights on our environment. It basically loops through all the site collections, Lists and libraries of the given web application, checks whether the items count > 2000, If yes, it logs the details to the CSV file.

Here is the C# code to Find Large Lists & Generate Report in SharePoint
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;

namespace FindLargeLists
{
    class Program
    {
        static void Main(string[] args)
        {
            string site;
            StreamWriter SW;
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Enter the Web Application URL:");
                    site = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                }

                SPSite tmpRoot = new SPSite(site);
                SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;

                //Enumerate through each site collection
                foreach (SPSite tmpSite in tmpRootColl)
                {
                    //Enumerate through each sub-site
                    foreach (SPWeb tmpWeb in tmpSite.AllWebs)
                    {
                        foreach (SPList tmpList in tmpWeb.Lists)
                        {
                            if (tmpList.ItemCount > 2000)
                            {
                                //Log the details to a file
                                SW = File.AppendText("c:\\LargeListsInfo.csv");
                                SW.WriteLine(tmpList.Title + "," + tmpRoot.Url  + tmpList.DefaultViewUrl + "," + tmpList.ItemCount);
                                SW.Close();
                            }
                        }                 
                   
                    }
      
                }

                //Dispose of the Root Site Object
                tmpRoot.Dispose();
            }

            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("Get Largest Lists", ex.Message);
            }
        }
    }
}
For PowerShell version of the Above code: Find Large SharePoint Lists & Generate Report with PowerShell


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, February 14, 2012

Copy Webpart Pages between SharePoint Site Collections

Had a requirement to copy web part pages from one site collection to other. These options failed, I got the page with out any web parts placed:
  • Explorer view copy paste
  • Download a copy and upload
  • SharePoint Designer copy-paste
The worked trick is: Using SharePoint Designer - "New from Existing Page". Steps in Detail:

  1. Open Both the Source and Target sites in SharePoint Designer

 2. Right click the source web part page and then choose "New From Existing Page"
 copy web part pages sharepoint 
 3. This will create a new page with existing page's content. Click on Save button

4. Now, Enter the target site's location in Save dialog box, and then Save the file!
copy a web part page in sharepoint
So Simple trick isn't it?

Another approach if you have server access: You can use SharePoint Deployment Wizard utility to achieve the same. You can use SharePoint Designer workflow's Copy Item action also!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, February 13, 2012

Assembly microsoft.sharepoint.intl.dll security permission grant set is incompatible between appdomains

Suddenly, SharePoint 2003 site gave an error:  "Assembly microsoft.sharepoint.intl.dll security permission grant set is incompatible between appdomains" when trying to add users to the site.
Assembly microsoft.sharepoint.intl.dll security permission grant set is incompatible between appdomains
Fix:  Ran an IISRESET fixed the problem!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Playing Videos in SharePoint using JWPlayer

Requirement:  To play a .MOV video file in SharePoint site.

Solution: Used the JWPlayer in SharePoint. Here are the detailed steps.

Step 1: 
Download the JWPlayer files from http://www.longtailvideo.com/jw/upload/mediaplayer-viral.zip
Extract and open the jwplayer.js file, Search for  /jwplayer/player.swf and then replace this with the location where you are going to upload the files.
E.g. change it to:
https://SharePoint.yourcompany.com/sites/Marketing/brandcenter/Player/player.swf

Step 2:
Create a Document Library and upload the files along with your video file and modified preview.png.
jw player sharepoint

Step 3:
Create a HTM file with the name of "Jwplayer.htm", paste the below code in it, change the File locations accordingly,  and then upload it to the document library you created earlier.
<html>
<head>
<title></title>
</head>
<body>
 <!-- START OF THE PLAYER EMBEDDING TO COPY-PASTE -->
 <div id="mediaplayer">Loading video...</div>
 
 <script type="text/javascript" src="https://SharePoint.com/sites/Marketing/brandcenter/Player/jwplayer.js"></script>
 <script type="text/javascript">
  jwplayer("mediaplayer").setup({
   flashplayer: "https://SharePoint.com/sites/Marketing/brandcenter/Player/player.swf",
   file: "https://SharePoint.com/sites/Marketing/brandcenter/Player/bp.mov",
   image: "https://SharePoint.com/sites/Marketing/brandcenter/Player/preview.png"
  });
 </script>
 <!-- END OF THE PLAYER EMBEDDING -->

</body>
</html>


Step 5: Now add a content editor web part, Edit the CEWP and point it to the HTM file created. Or Place this code:
<iframe name="Iframe" src="https://SharePoint.com/sites/Marketing/brandcenter/Player/Jwplayer.htm" scrolling="no" FRAMEBORDER="0" style="width:100%; border:0;  height:100%; overflow:hidden;">
</iframe>
See it in action!
jwplayer for sharepoint 2010

Look at this post for web based players: http://www.instantshift.com/2010/05/14/21-free-video-players-for-your-website-and-blogs/

we can use the EMBED tag as well!
<div>
<embed src="https:/SharePoint.com/marketing/brandcenter/player/bp.mov" autoplay="true" loop="true" width="400"      height="200">
 </embed>
</div>
The Problem here is: you must have a browser plug-in installed to play the video ( Such as Quick time) also it will prompt for username/password when using Secured sites.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, February 12, 2012

"Alert me" Missing in SharePoint 2010?

In an odd case, received complaints from users "SharePoint alert me missing!". Usually "Alert me" link will be there under documents tab of the SharePoint 2010 Ribbon. End-Users were unable to get "Alert me" link. When I checked, Yes, alert me button missing in SharePoint 2010 site!!alert me missing sharepoint 2010
and some more complaints for getting error messages when trying to setup alerts.
"Alerts have been turned off for this virtual server. For assistance, contact your server administrator."
sharepoint 2010 alert me missing from ribbon

Fix: 
Check whether the Outgoing E-Mail settings are configured in Central Admin.  Go to:Central Administration >> System Settings >>  Outgoing E-Mail Settings >> specify the outbound SMTP server & E-Mail settings.

If already enabled, Then alerts might be disabled. Enable Alert by: 
stsadm -o setproperty -pn alerts-enabled -pv true -url "http://your-web-app-url.com" 

That would fix the issue: alert me is missing in SharePoint 2010! Got the alert me link and we are back to the business!
alert me is missing in sharepoint 2010



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, February 10, 2012

SharePoint Search Scope Force Update

After updating SharePoint Search Scope, it said: wait 14 Minutes to update. How to instantly update the scopes? Do we have to wait for 14 Minutes? Is there a  way to force SharePoint search scope update on-demand?
sharepoint search scope updateDefinitely, Yes! We can force update SharePoint 2010 search scope. Just go back to "Search Administration"
sharepoint 2010 search scope update
There you will find a link "Start Update Now" Click on the link to update Search Scopes on demand!
sharepoint force search scope update
Want to update search scope in SharePoint using powershell?
Sure, Why not! Here you go: SharePoint powershell update search scope
$SearchServiceApp = Get-SPenterpriseSearchServiceApplication  
$SearchServiceApp.StartScopesCompilation() 
This will do SharePoint 2010 force search scope update!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, February 8, 2012

SharePoint Alert Notifications Not Working - Checklist for Troubleshooting

Before proceeding with the checklist, analyze and isolate the issue:
  • Whether E-mail Infrastructure is working on your environment
  • Whether in all SharePoint web applications alerts are not working? SharePoint alerts not working for one site?
  • SharePoint alerts not working after upgrade or migration 
  • Alerts not working after restore or Service pack?
  • Alerts not working all the time? or Stopped working Recently?
  • SharePoint alerts not being sent to All the user? or some users? or distribution groups, ad group members?
  • Whether SharePoint alerts not working for document library? list alerts not working? calendar alerts not working ? or everywhere?
  • Only SharePoint daily alerts not working? etc. 
This will help you to troubleshoot the SharePoint email alerts not working issue, quickly.

Here is the checklist for troubleshooting:
1. Check alerts are enabled for your web application:
How to check? execute this stsadm in your SharePoint Server:
Stsadm.exe -o getproperty -url http://SharePoint-web-App-URL -pn alerts-enabled

This should return <Property Exist="Yes" Value="yes" />

If you don’t get this, Enable alerts by:
stsadm.exe -o setproperty -pn alerts-enabled -pv "true" -url http://SharePoint-web-App-URL

If its already enabled, try turn off and turn on it back.

2. Is your SharePoint Server configured for Out-going E-Mail settings?
Go to Central Administration > Operations > Click on Outgoing e-mail settings Link under Topology and Services, Make sure you have valid settings for these fields. Usually you have to provide your Exchange server's HUB or any valid SMTP server's address.

3. Is your Exchange server allows SharePoint to Send Mails? 
In Exchange Server, If anonymous Relay settings is not enabled, then you must add your WFE/App Servers to the Exchange Server allowed hosts relay list! Make sure your ALL Sharepoint WFE's IPs are added in allowed Relays or Receive connectors in Exchange Server. If you use multiple domains, add all of them.
http://technet.microsoft.com/en-us/library/cc288949.aspx
Watch the  'DROP' folder in the mailroot of the SMTP server.

4. If you are using SMTP Server for E-mail communication, Make sure SharePoint Servers are allowed to Send Mails and Port 25 is open.Go to SMTP Virtual Server Properties >> Setting >> Access TAB >> Select "All except the list below"

5. Verify the Timer Jobs & Properties:

MOSS 2007:  Central Administration > Operations > Timer Job Definitions (under Global Configuration)
In SharePoint 2010: Central Administration > Monitoring > Review Job Definitions 

Check whether the "Immediate Alerts" job is enabled for your web application. check these properties:
  1. job-immediate-alerts
  2. job-daily-alerts 
  3. job-weekly-alerts
stsadm.exe -o getproperty -url "http://Your-SharePoint-web-App-URL" -pn job-immediate-alerts

The expected output is:

<Property Exist="Yes" Value="every 5 minutes between 0 and 59"/>.  

If you don’t get this, run the following command to change its value.

stsadm.exe -o setproperty -pn job-immediate-alerts -pv “every 2 minutes between 0 and 59" -url http://Your-SharePoint-web-App-URL
More info: http://technet.microsoft.com/en-us/library/cc262432.aspx

6. Whether the user account subscribed for alerts has E-mail account associated?
In one of my case, user has two accounts, One normal account and another one for Administrative
purpose. He logged in with Admin account, created alerts, and then complained that he didn't receive
alerts! LOL

7. Try these Resets:
Do stsadm -o execadmsvcjobs. Do restart SharePoint Timer services and IISReset.
Is it happening only to a particular user? try remove/re-add em.

8. Check the Permissions:
The initial alert is not security trimmed. Whether the user has access to the list or not, He will receive the initial alert. If the user is not getting alert for any changes, then check whether the user has at-least Read permission on the list/library.

If item level permission and Read Access to Only their own items is enabled, Alerts wont work!

9. Re-register the alert template:
Try re-registering the alert template:
stsadm -o updatealerttemplates -url http://Your-SharePoint-Web-App-URL -f  "c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\alerttemplates.xml" -LCID 1033

More info: http://technet.microsoft.com/en-us/library/dd278299.aspx

10. Check your Alternate access mapping
Is your Site URL's/AAM entries changed recently? Check the below tables in your content databases, and verify you dont have any old URL in "SiteUrl" column  in these tables, if you find, replace them.

- ImmedSubscriptions (Stores the alerts for emails that are sent immediately when changes occur)
- SchedSubscriptions (Stores daily or weekly scheduled alerts)
- EventLog (This table contains events for which only non-immediate alerts exist)
- EventCache (This table contains a list of site events for which users have requested alerts. WSS inserts events into this table as they occur)

setting up in the Alternate Access Mappings in Central Admin will correct this issue.

11. Clear the SharePoint configuration cache http://support.microsoft.com/kb/939308

12. Migrated or Changed the Site URLs?
Are you migrated from existing versions of SharePoint/ Changed your SharePoint Site URLs?
You have to update your alerts. Have you performed some database restored in your environment from a different server? Follow my article to fix the alerts: Fix Alerts in SharePoint Migration

13. Export-Import, Backup/Restore:
If you conclude alerts are not working for a entire sub-site but works well with another sub-site, then take the export of the sub-site, delete it, restore it again.

14. Is your SharePoint Up-to-Date?
Make sure your SharePoint is updated with latest service packs/patches.

15. Want to send SharePoint alert to distribution list? SharePoint alert email to distribution list not working?
Make sure your group is E-mail enabled and has at-least read-only permission on the site/list where you are creating alerts. It must be Security group and not distribution list. SharePoint can recognize one users and security groups. So, you can create a Mail for the security group.

Go to distribution group properties and un-check "Require that all senders are authenticated" or create a outgoing connector in Exchange, so that exchange server authenticate SharePoint

Same applies, When you send E-mail from SPD Workflow (or any other workflow). Make sure that the group has at least read permission to the site and the group can be viewed by "everyone".


16. Changes to the user profiles happened wont affect immediately. sync it back.

17. Make sure your timer job account has dbo access to SharePoint content databases.

18. If your Task assignment mails are not delivered, toggle the value for "Send e-mail when ownership is assigned".

19. Task Assigned notification e-mail: If the user synchronized the tasks list with Outlook 2007 the e-mail will not be sent and he will receive the notification in his task pane

20. Content database: Try Re-Attaching the content database (stsadm -o deletecontentdb and addcontentdb)


Alternates: you can simply design a SharePoint designer workflow to send E-mails. or you can have a event receiver to do the same!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint Topology for 5000 users - Virtual

Had a requirement to provide SharePoint 2010 Topology for 5000 intranet users. End-users will be using SharePoint 2010's collaboration features, Nintex workflows with SQL Server Reporting services and the Management wants to go for Visualization as it reduces the Cost!

Here goes my recommendation:
SharePoint Topology for 5000 users
Hardware/Software specifications:
Technet article on Topology planning in virtual environment: http://technet.microsoft.com/en-us/library/ff607811.aspx

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, February 7, 2012

"Unable to complete this operation. Please contact your administrator" Error when trying to upload a file in SharePoint

I was troubleshooting an issue with uploading files to SharePoint Site. When I tried uploading a file to the document library, I got this error:
"Unable to complete this operation. Please contact your administrator"
"Unable to complete this operation. Please contact your administrator"

Enabled Stack Trace and Disabled Custom error tags in web.config to reveal the actual error:

Unable to complete this operation.  Please contact your administrator.   at Microsoft.SharePoint.Library.SPRequestInternalClass.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage)
   at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage)


 Solutions:
  • Usually You will see this error when SQL Server is running out of disk space. So take a look at your DB Servers disk space first!
  • Verify that the site collections did not get locked and site quotas are correct
  • Check the database and the data file is on unrestricted growth.
  • In case, You are using SQL Server Express edition - it supports 4GB Max! SQL Server 2008 R2 Express Edition the limit is upped to 10GB
  • Verify that the user have enough permissions to do what they are trying to do. 
  • In my case, the problem was:  Transaction logs were huge because they weren’t being cleared out properly during the backup! Truncated the transaction log as per Truncate and Shrink SharePoint Transaction Logs, Databases and the issue got resolved!
  • Last but not least: Perform the DBCC Checkdb and ensure your content database is in good state.
Generally, Its a good practice to have a Disk-space monitoring system(Such as SCOM or your own script to Monitor the disk space) in place in order to avoid such issues.


    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Find Remaining of Days in XSL

    Scenario:
    I have a List for keeping track of my Outsourced resources with fields: Resource Name, Skills, Contract Start Date, End Date, etc. What I want is: Display the No.of remaining days in a page. So Added a calculated field , applied the formula : =IF(Today>=[End Date],0,INT([To Date]-Today)), So simple, isn't it?

    hmm, The problem here is: since its a calculated field, it wont get update until you update the record! All I wanted is just to display the remaining days.

    Tried the formula:
    <xsl:variable name="DaysDiff" select="ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') - ddwrt:FormatDateTime(string(@EndDate), 1033, 'yyyyMMdd')"/>

    Nope! didn't work, gave me wrong values in some cases.

    After Googling some time, found in Technet forums something works: Custom XSL Template!
    Insert this code in Dataview XSL
    <xsl:template name="DateDiff">
        <xsl:param name="StartDate"></xsl:param>
        <xsl:param name="TodayDate"></xsl:param>
     
        <xsl:variable name="JulianToday">
          <xsl:call-template name="calculate-julian-day">
            <xsl:with-param name="Year" select="substring(ddwrt:FormatDateTime(string($TodayDate), 1033, 'yyyyMMdd'),0,5)"/>
     
            <xsl:with-param name="Month" select="substring(ddwrt:FormatDateTime(string($TodayDate), 1033, 'yyyyMMdd'),5,2)"/>
     
            <xsl:with-param name="Day" select="substring(ddwrt:FormatDateTime(string($TodayDate), 1033, 'yyyyMMdd'),7,2)"/>
        </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="JulianStartDate">
          <xsl:call-template name="calculate-julian-day">
            <xsl:with-param name="Year" select="substring(ddwrt:FormatDateTime(string($StartDate), 1033, 'yyyyMMdd'),0,5)"/>
     
            <xsl:with-param name="Month" select="substring(ddwrt:FormatDateTime(string($StartDate), 1033, 'yyyyMMdd'),5,2)"/>
     
            <xsl:with-param name="Day" select="substring(ddwrt:FormatDateTime(string($StartDate), 1033, 'yyyyMMdd'),7,2)"/>
        </xsl:call-template>
        </xsl:variable>
     
        <xsl:value-of select="$JulianStartDate - $JulianToday"></xsl:value-of>
      </xsl:template>
     
      <xsl:template name="calculate-julian-day">
        <xsl:param name="Year"/>    
        <xsl:param name="Month"/>    
        <xsl:param name="Day"/>    
     
        <xsl:variable name="JulianDay" select="floor((14 - $Month) div 12)"/>    
        <xsl:variable name="JulianYear" select="$Year + 4800 - $JulianDay"/>    
        <xsl:variable name="JulianMonth" select="$Month + 12 * $JulianDay - 3"/>    
     
       
     <xsl:value-of select="$Day + floor((153 * $JulianMonth + 2) div 5) +
     $JulianYear * 365 + floor($JulianYear div 4) - floor($JulianYear div 
    100) + floor($JulianYear div 400) - 32045"/>
      </xsl:template>

    Call the Template with appropriate parameters:
    <!-- get the delta in days between the due date and today -->
          <xsl:variable name="dueDateDelta">
             <xsl:call-template name="DateDiff">
                 <xsl:with-param name="StartDate" select="substring-before(@To_x0020_Date,'T')"/>
                 <xsl:with-param name="TodayDate" select="substring-before(ddwrt:TodayIso(),'T')"/>
               </xsl:call-template>
            </xsl:variable>
            
      <xsl:choose>
              <xsl:when test="$dueDateDelta &gt; 0">
        <xsl:value-of select="$dueDateDelta" />
              </xsl:when>
              <xsl:otherwise>
                 <xsl:value-of select="0" />
             </xsl:otherwise>
      </xsl:choose>        


    Thanks to: http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/aeda905b-9bc6-40c4-bd22-21306c5cb0d2/

    Found another Trick using javascript: http://blog.pathtosharepoint.com/2008/08/25/a-countdown-for-tasks-lists/
    http://blog.metrostarsystems.com/2009/11/13/performing-datetime-calculation-in-dvwp-using-xslt/
    http://sympmarc.com/2009/07/22/date-arithmetic-in-sharepoint-dvwps/

    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Thursday, February 2, 2012

    Unable to upload files or add users. Receiving HTTP 403 Forbidden error

    Users were unable to upload files or add users to SharePoint sites. Moreover they received  HTTP 403 Forbidden error message when trying to upload or add users.
    Unable to upload files or add users. Receiving HTTP 403 Forbidden error
    Fix:
    This is a known issue and needs the hot fix http://support.microsoft.com/kb/934793/ applied on the server!

    In some cases, another possible case is: anonymous access might removed from READ permissions of IIS virtual directories.  Fire IIS console and fix it.

    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    "New" Icon Indicator in SharePoint - Disable, Replace, Set Duration

    Lot of folks asking me on SharePoint "!New" Indicator. By default SharePoint 2007/2010 shows "! New" Indicator for 2 days from the creation of an List item/document. It simply indicates it's newly added content such as document or list item!
    sharepoint new tag
    How to Replace New tag in SharePoint 2010?
    As part of branding, we can replace the New Indicator. Its just an image, new.gif , located at:/_layouts/1033/images/new.gif (\14\template\layouts\1033\IMAGES\new.gif). Behind the scenes ddwrt:IfNew Function determines whether to display this image or not.

    How to change New tag duration in SharePoint?
    You can query the current value of !New indicator by:  
    stsadm -o getproperty -pn days-to-show-new-icon -url <URL-of-web-app>
    If you want to change the days:
    stsadm -o setproperty -pn days-to-show-new-icon -pv <days-to-show> -url <web-app-URL>

    How To Remove/Disable New Tag in SharePoint?
    Want to disable the !New tag indicator? execute the STSADM: stsadm -o setproperty -pn days-to-show-new-icon -pv 0 -url <web-app-URL>
    Here we passed "0" in Property value, which disables the New indicator.

    PowerShell Way to change new tag duration:
    $webApp=Get-SPWebApplication "<web-app-URL>"
    write-host "Current New Indicator Duration:" $webApp.DaysToShowNewIndicator
    # set the Duration to 7 days
    $webApp.DaysToShowNewIndicator = 7
    # Important: If you dont call "update", your changes will not be saved!
    $webApp.Update()
    

    SharePoint 2013/2016 new item icon
    While all of the above procedures are valid for SharePoint 2013, new icon has been changed and moved to a image sprite - "spcommon.png"
    new icon in sharepoint 2013

    MSDN Article & Technet on New tag indicator.

    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    You might also like:

    Related Posts Plugin for WordPress, Blogger...