Thursday, December 29, 2011

Hide Create Page in Site Actions for Publishing Sites

Add Hide Custom Action tag in xml file below:
..\14\TEMPLATE\FEATURES\Publishing\SiteActionMenuCustomization.xml
<HideCustomAction
   Id="HideCreatePublishingPage"
   GroupId="SiteActions"
   HideActionId="PublishingSiteActionsMenuCustomizer"
   Location="Microsoft.SharePoint.StandardMenu">
</HideCustomAction>

Activate or deactivate the SocialRibbonControl Feature

After you perform this procedure, users will not see the I Like It or Tags & Notes controls when they browse pages or edit document libraries and lists.
To activate or deactivate the SocialRibbonControl feature by using Central Administration
1. Verify that you have the following administrative credentials:
* You must be a member of the Farm Administrators group, or you must have been assigned permission to administer the User Profile service application that is running in the farm. For more information, see Assign administration of a User Profile service application (SharePoint Server 2010).
2. On the Central Administration Web site, in the System Settings section, click Manage farm features.
3. In the list of features, in the Social Tags and Note Board Ribbon Controls row, do one of the following:
* Click Activate.
* ClickDeactivate, and then click Deactivate this feature.

http://www.learningsharepoint.com/2010/07/07/hide-like-it-tags-and-notes-in-sharepoint-2010/

PowerShell to Delete a List in a Site

To delete a list in a site:Change -Identy URL "Site Collection URL"
Change ["List Name"]

Then copy and paste all below to SharePoint Management Shell (running as administrator).

$assignment = Start-SPAssignment
$web = Get-SPWeb -Identity "http://%3csite/ Collection URL>" -AssignmentCollection $assignment
$list = $web.lists["<List Name>"]
$list.AllowDeletion = $true
$list.Delete() #this will delete the list
Stop-SPAssignment $assignment

Remove Info for Grouping

 If you remove this part from the list view:

In Content editor (hidden on page):

<script>
_spBodyOnLoadFunctionNames.push("HideHeaders");


function HideHeaders()
{
var elements = getElementsByClassName(document, "td", "ms-gb");
var elem;
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.childNodes[elem.childNodes.length-3].childNodes[1].data = "";
elem.childNodes[elem.childNodes.length-2].data=elem.childNodes[elem.childNodes.length-2].data.replace(':','');
}


elements = getElementsByClassName(document, "td", "ms-gb2");


for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.childNodes[elem.childNodes.length-3].childNodes[1].data = "";
elem.childNodes[elem.childNodes.length-2].data=elem.childNodes[elem.childNodes.length-2].data.replace(':','');
}


elements = getElementsByClassName(document, "tr", "ms-viewheadertr");


for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.style.display = "none";
}
}


function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
</script>

Then export Web Part and save as a custom web part that you can reuse.

Redirect Format

To Redirect to another page:
<meta http-equiv="REFRESH" content="0;url=http://google.com">

In SharePoint put this in the Source Editor of the Content Editor Web Part (not the Rich Text Editor).

Redirect Article

Run All Timer Jobs

Stsadm Command to run all timer jobs on all frontend servers in SharePoint Farm:stsadm -o gl-execadmsvcjobs

Doc Link to File

SharePoint Doc Library link to file:<%FilePath%>

SharePoint Remove Workspace Calendar

<script type="text/javascript">
var trs = document.getElementsByTagName("TR");
for (var r in trs) {
var row = (trs[r].innerText || trs[r].textContent)+"";
if (row.match(/^Workspace/)|| row.match(/^All Day Event/)|| row.match(/^Recurrence/)) {
trs[r].style.display = "none";
}
}
</script>

PowerShell Remove Features in SharePoint

Functions:
function Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly)
{
    $db = Get-SPDatabase | where { $_.Name -eq $ContentDb }
    [bool]$report = $false
    if ($ReportOnly) { $report = $true }
   
    $db.Sites | ForEach-Object {
       
        Remove-SPFeature -obj $_ -objName "site collection" -featId $FeatureId -report $report
               
        $_ | Get-SPWeb -Limit all | ForEach-Object {
           
            Remove-SPFeature -obj $_ -objName "site" -featId $FeatureId -report $report
        }
    }
}
function Remove-SPFeature($obj, $objName, $featId, [bool]$report)
{
    $feature = $obj.Features[$featId]
   
    if ($feature -ne $null) {
        if ($report) {
            write-host "Feature found in" $objName ":" $obj.Url -foregroundcolor Red
        }
        else
        {
            try {
                $obj.Features.Remove($feature.DefinitionId, $true)
                write-host "Feature successfully removed from" $objName ":" $obj.Url -foregroundcolor Red
            }
            catch {
                write-host "There has been an error trying to remove the feature:" $_
            }
        }
    }
    else {
        #write-host "Feature ID specified does not exist in" $objName ":" $obj.Url
    }
}

To run only a report (-ReportOnly property):
Remove-SPFeatureFromContentDB -ContentDB "SharePoint_Content_Portal" -FeatureId "e8389ec7-70fd-4179-a1c4-6fcb4342d7a0" –ReportOnly

To remove the feature from all sites, site collections in the db run (no -ReportOnly property):
Remove-SPFeatureFromContentDB -ContentDB "SharePoint_Content_Portal" -FeatureId "8096285f-1463-42c7-82b7-f745e5bacf29"

Powershell Fix for User's Display Name in SharePoint

For Individual Users:
Set-SPUser -Identity 'pmc1\<USERNAME>' -Web http://<SITE COLLECTION URL> -SyncFromAD

For All Users:
Get-SPUser –Web http://<SITE COLLECTION URL> | Set-SPUser –SyncFromAD

Hide Fields in SharePoint Form

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFields");
function findacontrol(FieldName) {
   var arr = document.getElementsByTagName("!");
   // get all comments
   for (var i=0;i < arr.length; i++ )
   {
      // now match the field name
      if (arr[i].innerHTML.indexOf(FieldName) > 0)
      {         return arr[i];      }
   }
}
function hideFields() {
   var control = findacontrol("Closed");
   control.parentNode.parentNode.style.display="none";
}
</script>

Get at dll in GAC

Just type in following path in the Windows RUN box and press enter
%windir%\assembly\gac_msil
You will see all the folder structure in UI

Domain Controller (Audience Fix)

·        Delete the old User Profile Service Application Proxy (click check box for Delete Associated Content when deleting)
·         Perform and iisreset -noforce
·         Create a new User Profile Service Application Proxy
·         Enable import of NetBIOS Domain Names
o              Using the 2010 SharePoint Management Shell:
o              Get-SPServiceApplication
o              <lists the Service Applications and their GUIDs>
o              $UPA = Get-SPServiceApplication –Id <GUID of User Profile Service Application>
o              $UPA.NetBIOSDomainNamesEnabled=1
o              $UPA.Update()
·         Check if NetBIOS Domain Names are enabled
    •           (Get-SPServiceApplication <GUID of User Profile Service Application>).NetBIOSDomainNamesEnabled
      • Need Parenthesis in above command
    •           You'll get back either True or False.  (should be True before continuing)
·         Start the User Profile Synchronization Service (takes a while to start)
·         Once the Service is started Perform an iisreset -noforce
·         Under Configure Synchronization Settings, uncheck BCS
·         Create a new Synchronization Connection
·         Forest = PMC1  (this will change to “adroot.phmic.com” automatically once created)
·         Domain Controller = DC1.adroot.phmic.com
·         Perform an iisreset -noforce
·         Start a Full Synchronization

Clear Config/System Cache

If you experience issues with WSS and MOSS timer jobs failing to complete are receiving errors trying to run psconfig, clearing the configuration cache on the farm is a possible method for resolving the issue. The config cache is where we cache configuration information (stored in the config database) on each server in the farm. Caching the data on each server prevents us from having to make SQL calls to pull this information from the configuration database. Sometime this data can become corrupted and needs to be cleared out and rebuilt. If you only see a single server having issues, only clear the config cache on that server, you do not need to clear the cache on the entire farm. To do a single server, follow the steps below on just the problem server.
To clear the config cache on the farm, follow these steps:

  • Stop the OWSTIMER service on ALL of the MOSS servers in the farm.
  • On the Index server, navigate to:
    Server 2003 location: Drive:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\GUID and delete all the XML files from the directory. Server 2008 location: Drive:\ProgramData\Microsoft\SharePoint\Config\GUID and delete all the XML files from the directory.
  • Delete all the XML file in the directory. NOTE: ONLY THE XML FILES, NOT THE .INI FILE.
  • Open the cache.ini with Notepad and reset the number to 1. Save and close the file.
  • Start the OWSTIMER service on the Index server and wait for XML files to begin to reappear in the directory.
  • After you see XML files appearing on the Index server, repeat steps 2, 3 & 4 on each query server, waiting for XML files to appear before moving to subsequent servers.
  • After all of the query servers have all been cleared and new .xml files have been generated, proceed to the WFE and Application servers in the farm, following steps 2, 3, 4 and 5 for each remaining server.