Pages

Sunday 25 November 2012

How to manage multiple remote desktop sessions

If you are sysadmin or anyone who needs to manage multiple remote desktop sessions, then this free tool is a must. It's called Remote Desktop Connection Manager, free from Micorsoft.

http://www.microsoft.com/en-us/download/details.aspx?id=21101

Tuesday 20 November 2012

How to log the output to a text file for a powershell script

Problem

Some times when performing bulk operations you would want to log the output of a powershell script to a text file, so you can examine the results and perhaps even investigate what went wrong.

Solution:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\Admin\SiteFeaturesoutput.txt -append


.
.
Your script goes here
.
.
Stop-Transcript

Sunday 11 November 2012

How to get crawled properties for a document using Powershell in SharePoint 2010


(This is an exact copy from this site: I have created this post for my Personal Reference)


In order to get the crawled properties for a document copy the powershell command, this information can be used to create Managed Properties for search.



Function Get-CrawledPropertyNames([string]$DocURL){  
$DocURL = $DocURL.Replace("%20"," "$webfound = $false 
$weburl = $DocURL 
 
while ($webfound -eq $false) { 
    if ($weburl.Contains("/")){ 
    $weburl = $weburl.Substring(0,$weburl.LastIndexOf("/")) 
    $web = get-spweb -identity $weburl -ea 0 
    if ($web -ne $null){ 
        $webfound = $true 
    } 
    }else{ 
    Write-Host -ForegroundColor Red "The Web could not be found" 
    return -1 
    } 
     
} 
$web.GetFile($DocURL).item.xml.Replace("' ""' `n").Replace("`" ", "`" `n") 
} 


#To use enter the url of a file within a doucment library 
Get-CrawledPropertyNames "http://sites/doc/file.pdf" 
 
The output: 




Thursday 1 November 2012

How to ensure the field value is the same in a repeating section in an InfoPath form hosted in SharePoint 2010 Forms library

Scenario:
Consider this: You have a information request form at a school. When someone (who is an authorised requester) requests information for a student. The admin staff use this form to record the information sent to the requester for legal reasons. The admin staff are allowed to add multiple students for the same request however, the students need to be from the same school.

When the admin staff login, their details are populated automatically from GetUserProfileByName web service.


`Figure 1

The form has a repeating control as seen in Figure 2 (People Picker Control + Label (Field Name is ChildSchool)) in an InfoPath form which is published to a Form Library in SharePoint 2010


Figure 2
Problem:
Since it is a repeating section, you cannot control or know the number of instances of the control. A user can add many by clicking the insert link.

Solution:
Add another control (text) to form called AllSchoolNames, it does not have to be visible on the form it is just used to calculate the total number of schools
Figure 3

Click properties of the AllSchoolNames field and add this to the Value field under Default Value Section
eval(eval(NameOfChilds, 'concat(../my:childSchool, substring(";", 1, string-length(../my:childSchool)))'), "..")




Click on "fx" and click on "Edit XPath (advanced)" - Ensure your values look similar to this:

xdMath:Eval(xdMath:Eval(../my:NameOfChild/my:NameOfChilds, 'concat(../my:childSchool, substring(";", 1, string-length(../my:childSchool)))'), "..")

This will return either o (false) or 1 (true)

That's it. Based on the return value you can include Rules to perform an action.

Hope it helps:
References:

http://www.infopathdev.com/forums/p/7124/75545.aspx

Thursday 25 October 2012

Adding and Deploying solutions in SharePoint 2010

*** When a wsp is available ***

Adding a solution to the Solution Store

Add-SPSolution -LiteralPath <SolutionPath>

Deploy a solution

Install-SPSolution -Identity <SolutionName> -WebApplication <URLname>

To deploy a solution package to all Web applications

Install-SPSolution -Identity <SolutionName> -AllWebApplications -time <TimeToDeploy> -GACDeployment -CASPolicies


To upgrade an existing wsp solution file

Update-SPSolution –Identity mySolution.wsp –LiteralPath c:\mySolution.wspGACDeployment

To uninstall a solution

Uninstall-SPSolution –Identity mySolution.wsp –WebApplication http://webapp

To remove a solution

Remove-SPSolution –Identity mySolution.wsp

Extract a solution from the Content DB: SharePoint 2010

In order to gain access to a copy of a wsp file from the Config DB, follow these steps:

Powershell:

$farm = Get-SPFarm
$file = $farm.Solutions.Item("mySolution.wsp").SolutionFile
$file.SaveAs("c:\temp\mySolution.wsp")

To Get all solutions within a farm:
(Get-SPFarm).Solutions | ForEach-Object{$var = (Get-Location).Path + "\" + $_.Name; $_.SolutionFile.SaveAs($var)}

 

C#

using Microsoft.SharePoint
using Microsoft.SharePoint.Administration

namespace GetWSPFile
{
   class GetFile
   {
      static void Main(string[] args)
      {
           SPSolutionCollection AllSolutions = SPFarm.Local.Solutions;
           foreach (SPSolution solution in AllSolutions)
           {
              if(solution.Name =="mySolution.wsp")
              {
                     SPPersistedFile wspFile = solution.SolutionFile;
                     wspFile.SaveAs("C:\" + Solution.Name);
              }
           }
       }
    }
}

Installing a Feature when you only have access to the Feature Folder on the Server: SharePoint 2010

*** When you only have access to
the Feature folder ***
  • First, Copy the folder to the web front end / Central Admin server
Install to the farm:
Install-SPFeature FeatureFolderName

Enable at a site collection
Enable-SPFeature FeatureFolderName -Url http://server/site/subsite

Uninstall a featrure based on a folder:

Uninstall-SPFeature FeatureFolderName
Disable a feature for a site collection
Disable-SPFeature FeatureFolderName -Url http://server/site/subsite

Wednesday 24 October 2012

How to customise the New form for a document library in SharePoint 2010.

How to customise the New form for a document library in SharePoint 2010.


Note: This is not supported by Microsoft and it just a work around.

In order to create a custom New Form for a document library we will follow these simple steps:


  1. Create a list with exact content type (List settings > Advanced settings > Allow management of content types)
  2. Then click on the Customise Form (Infopath Icon)
  3. The form will open in Infopath
  4. Once the form is open select File > Publish > Export Source Files and save it in a desired location
  5. Edit the mainfest.xsf File in a text editor (I use Notepad++)
  6. Scroll down to bottom section where you should see this:



  7. We want to change the content type ID and the relativeUrl values here to point to the document library that we want to customise the new form for:
  8. In order to get the content type ID follow this post
  9. Change the Content type ID and Relative URL (for a document library just replace ../../ with the library name does not require a prefix library either)
  10. Save the mainfest.xsf
  11. Right click and select Design, now the form will point to the library, save and publish.

On a side note:
I have only tested this with a single content type




How to get the list ID and Content type ID in sharePoint 2010

To get the List ID:
  1. Navigate to list settings and copy List={ENCODED GUID}

    In my case it was this List=%7B2E5002B0-EDC3-4541-A0ED-2A81797B459C%7D
  2.  Decode the GUID here or here
  3. It should return a value similar to this: List={2E5002B0-EDC3-4541-A0ED-2A81797B459C}
That's it :)

To get the Content type ID currently associated with a list or library:

(Assuming allow management of content types is set to Yes (Under list settings > advanced settings))
  1. Navigate to list/library settings
  2. Under content types > select the content type
  3. From the URL copy this part:
    ctype=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B
  4. This the Content type ID