Posts

Showing posts from July, 2015

PowerShell Command List used in SharePoint 2010

PowerShell Command which are common in use for a SharePoint Developer.

Backup
Backup-SPSite http://oldsite -Path C:\backup\sitename.bak

Restore
Restore-SPSite http://newsite -Path C:\backup\sitename.bak

Add WSP
Add-SPsolution "C:\File1.wsp"

Update WSP
Update-SpSolution -Identity File1.wsp -LiteralPath "C:\File1.wsp" -GACDeployment

Install WSP
Install-SPSolution -Identity "File.wsp"  -WebApplication "http://siteurl"

EnableFeature
Enable-SPFeature -identity "MyFeature" -URL "http://siteurl"

Disable Feature
Disable-SPFeature -identity "MyFeature" -URL "http://siteurl"

InstallFeature
Install-SPFeature -path "MySPFeature1"

Uninstall Feature
Uninstall-SPFeature -Identity "MySPFeature1"

Get Farm ID
(Get-SPFarm).Id



How to create a secure webservice in asp.net

Web service is a way to communicate between 2 machines via HTTP, those 2 machines can be on the different platform.
See more about web service at this URL: http://www.sharepointcafe.net/2015/05/all-about-web-service-soap-rest.html

Throttling and Indexing in SharePoint List

Throttling and Indexing in SharePoint List

In SharePoint, List is like a table with rows and columns.Similar to SQL tables SharePoint List need indexing if contains heavy amount of data else it will degrade the performance of SharePoint application.

Resource Throttling Setting unable to open, Error message is Updates are currently disallowed on GET requests.

Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.

I searched on google and found the solution.
You need to update webapplication throttle setting through powershell command

$w = get-spwebapplication http://mysite:2015
$w.HttpThrottleSettings
$w.Update()

List Threshold setting page should open now.

What is QueryThrottleMode in SPQuery Class?

As per MSDN definition, QueryThrottleMode is a property of SPQuery class which gets or sets value that indicate the throttling mode to be applied to the query.

As we know that List Throttling is a new option available in SharePoint 2010. List Throttling limits the list data that will be fetched in a single request.
Beyond the limit, request will not be allowed.

 ListView Threshold limit can be set through Central Admin and is applicable for web application that will be selected.


QueryThrottleMode property can be used with SPQuery and SPSiteDataQuery  object as shown in below code.


SPList spList = spWeb.Lists["mylist"];
                SPQuery spQuery = new SPQuery(spList .DefaultView);
                spQuery.QueryThrottleMode = SPQueryThrottleOption.Override;

QueryThrottleMode has 3 enum values:
Default - 0
Override - 1
Strict - 2

Logging to ULS in SharePoint 2010.

ULS stands for Unified Logging Service
ULS helps developer to avoid debugging code again and again to find out bugs.
ULS clearly specifies the error in details.
Generally SharePoint logs can be found at hive folder i.e. \14\LOGS
But this log file is not an easy task to read and understand.

To make it easy you should use tools like ULS viewer.
Download ULS viewer to read logs.

To write log in ULS need to write below code.

Please add 2 namespace:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                using (SPSite site = new SPSite("http://myspsite:1985"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["mylist1"];
                        SPListItemCollection items = list.GetItems();
                        web.AllowUnsafeUpdates = true;
                    …

What is delegate control in SharePoint? Why to use it?

Delegate control in SharePoint allows developers to manage control on a master page without touching or editing master page.

Actually, delegate control is associated with a feature. Whenever that feature is active delegate control will be visible and if an associated feature is de-active delegate control will not be visible to users.

The method "GetItems" of the type "List" with id "{Guid}" is blocked by the administrator on the server.

I was working on SharePoint Client Context, and i was writing a piece of code to fetch items from SharePoint list.

I got this error at this line:
objContext.ExecuteQuery(); 

I solved this issue by executing powershell command.
Open SharePoint Powershell  and type below command one by one.

$webapp = Get-SPWebApplication "http://spserver"$webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], "GetItems")$webapp.Update()Open SharePoint Powershell  and type below command one by one.Now run your code, you can now access SharePoint List Data.

Powershell Command to add a file to root of SharePoint

This blog will explain about adding a file to SharePoint root.
Generally sharepoint structure is http://server/pages/page1.html
Suppose you need to add a file in root which should access by http://server/page1.html

This can be done by powershell command.


Write-Host "Powershell started....."
Add-PSSnapIn Microsoft.SharePoint.PowerShell
$fileBytes = [system.io.file]::ReadAllBytes("C:\myfolder\page1.html");
$site = Get-SPSite "http://server";
$site.RootWeb.Files.Add("page1.html", $fileBytes, $true);
Write-Host "Done..."

Create SharePoint List with Code and CAML

CAML is an XML based language used for access SharePoint objects like List, Library, Content-Type, Site Columns.

To know more about CAML Query, please visit my another blog post Learn CAML Query step by Step
CAML comes under declarative and the code that we write using SharePoint server object model comes under imperative programming.

Linq in C# Programming

Before using LINQ in C#, please read my earlier blog to get some basic idea about what is LINQ?

LINQ can be used in C# in different ways :

One way is to use with Lambda Expression
Another way is to use Anonymous function


Below code will return string of length less than 5.

string[] countryArr = { "India", "USA", "UK", "China", "Japan", "Germany", "Australia" }; var data = countryArr.Where(a => a.Length < 5).Select(a => a); foreach (string sdata in data)             { Console.WriteLine(sdata);
            }
O/P : - USA, UK

Above code can be written using Anonymous function

Write below function

Func<string, bool> wh = delegate (string s)         { return s.Length < 5; }; Func<string, string> sel = delegate (string s)         { return s; };
Below function to implement the LINQ

privatevoid PrintData()         { string[] countryArr = { "India", "USA", "UK", "China", "Ja…