0

Before You Start With SharePoint 2013 Apps

Where are apps for SharePoint hosted?

 There are several options for hosting apps for SharePoint.
  • Provider-hosted

  • Hosted in a SharePoint environment

  • Combinations of these options.

 

How are apps for SharePoint and SharePoint sites related?

Site owners can add apps for SharePoint to their sites. If an app contains SharePoint components, those components are stored in a subweb of the site that is automatically created when you install the app. Apps have their own, isolated URLs, which are separate from the URL for the site that contains the app. If the app is Provider-hosted the app components are stored in those locations.
 
What is the URL for an app for SharePoint?

By default, apps are deployed to their own web site in a special, isolated domain name, instead of in the same domain name as your farm. Processes run under that domain name and do not affect the SharePoint sites. This difference in domain names provides a layer of isolation for the apps. The use of a different domain name from the SharePoint sites prevents cross-site scripting between the apps and sites and unauthorized access to users’ data.

Each installation of an app has a unique URL in your environment. You determine the template for that URL (by specifying a domain name and an app prefix), and then app URLs are automatically generated based on that template. Paths for the apps are based on the URL for the site where they are installed. When you install an app to a site, a subweb of that site is created to host the app content. The subweb for the app is hierarchically below the site collection, but has an isolated unique host header instead of being under the site’s URL

prerequisites and permissions:

  • Before a user can add an app for SharePoint, a member of the Farm Administrators group must configure the environment to support apps for SharePoint. For more information, see Configure an environment for apps for SharePoint (SharePoint 2013).

  • A user must have the Manage Web site and Create Subsites permissions to add an app for SharePoint. By default, these permissions are available only to users who have the Full Control permission level or who are in the site Owners group.

  • When a user adds an app for SharePoint, the app requests permissions that it needs to function (for example, access to Search, or to create a list). Users who do not have those permissions are informed that they do not have sufficient permissions and the app cannot be added. The user can contact a site or farm administrator to see if the administrator can add the app.

  • A user logged in to a site as the system account cannot install an app. The system account cannot import app licenses because that could result in performance problems.

 

Add apps for SharePoint to SharePoint sites

Site owners can add apps for SharePoint from the following sources to their sites:
  • from the list of apps already available for a site (default apps, such as standard lists and libraries, and apps that have been purchased already).

  • from the App Catalog.

  • from the SharePoint Store.

    Verify that the user account that is performing this procedure is a member of the site Owners group. But Should not be a system account

 

Configure an environment for apps for SharePoint (SharePoint 2013)

  •  You must purchase a domain name from a domain name provider for your apps, for example, ContosoApps.com.
  • You must be a member of the Farm Administrators group to perform the steps in this article. For some steps, you must also be a local administrator on the domain controller.

  • Confirm that the SharePoint Administration (spadmin) and SharePoint Timer (sptimer) services are running.

Reference:

http://technet.microsoft.com/en-us/library/fp161232(v=office.15).aspx

0

Windows Server 2012 Editions

Windows server 2012 can switch between Server Core and Server with GUI.
Server core is command line interface only and its recommanded. OS uses Metro UI i.e. Windows 8 look its need to install in core mode.

EDITIONS

Edition Ideal for… High Level Feature Comparison Licensing Model Pricing Open NL(US$)
Datacenter Highly virtualized private & hybrid cloud environments Full Windows Server functionality with unlimited virtual instances Processor + CAL*                 $4,809**             
Standard Low density or non-virtualized environments Full Windows Server functionality with two virtual instances                 Processor + CAL*                              $882**             
Essentials Small business environments Simpler interface, pre-configured connectivity to cloud based services; no virtualization rights                 Server (25 User Account Limit)                              $501**             
Foundation Economical general purpose server General purpose Server functionality with no virtualization rights                 Server (15 User Account Limit)                              OEM Only             
 
0

Taking care of List View Threshold

By default SharePoint have a fixed count of items to be displayed in the list view to avoid performance issues. One should always take care not to reach this item limit. This can be done by creating custom views and defining proper sorting and filtering methods.

 

However In some of the cases we need to ‘adjust’ with site performance in order to get the desired Items in the view.

To increase the List View threshold follow the below steps-

 

 

1. Open Central Admin click on Manage Web Application under Application Management.

2. Select your application and click on General Setting -> Resource Throttling

3. Change value here. Do not exceed too much value else performance will be affected badly.

 Image

0

Site Level Authentication & Permissions

Site Level Authentication & Permissions

clip_image002

In above scenario user A has read access to root site but for one site he has full permission and for other it’s only read and write. To create this scenario in the SharePoint 2010 follow below steps.

Let’s start with creating role first. We will create three different roles here.

1. READER

2. READWRITE

3. READWRITEDELETE

Root Site –

1. Site Settings -> Site Permissions -> Permission Levels (as shown below)

 

clip_image003

 

2. On New Permission level page click on Add Permission Level, this will open new page for adding new permissions.

3. Give the first permission level as READER, and select only view permission from available permission lists as shown below.

 

clip_image004

 

4. Follow step 2 and 3 and create two new permission levels for READWRITE and READWRITEDELETE.

Now we have three permission levels defined at root site.

 

clip_image005

 

5. Now either we can go ahead and use the USER A or else we will create a group which will contain the USER A, creating group will be helpful because, tomorrow we might require to give the same permission to some other user that will not require you to go through above steps, just add that new user in this group.

6. Site Settings -> Site Permission and select the icon Create Group and name it as TypeAUserGroup.

 

clip_image006

 

7. On the same page you can find the permissions role we created above in step 1, 2 and 3. As we are on the root site and as per diagram we need to give read permission for root site. Select Reader and click Ok.

8. When the group gets created add the USERA in this group.

9. Now go to Site A.

10. Site Settings -> Site permissions

11. First and most important thing we need to do here is Stop Inheriting the permission from the root site.

 

clip_image007

 

12. Select the group TypeAusergroup and click on Edit User Permission icon as shown below

 

clip_image008

 

13. Now for Site A we need to assign the READ WRITE and DELETE permission, so unselect the READER permission and select READWRITEDELTE permission here.

14. Follow the steps 9 to 13 to assign READWRITE permission to site B.

You are done here. Now if user A logs in he will be having the rights defined in above tree.

1

SharePoint Batch Job Troubleshooting

SharePoint Batch Job Troubleshooting

The most convenience way to work on huge items in SharePoint is, using the batch job. Developer gets stuck in foreach loop to do the operation on multiple items in the list and libraries.

Well whenever working on large number of items whether its list or library using the foreach loop or any other loop in code will occupy high memory and of course this could affect your complete site performance.

Batch job is xml query which is used to process huge number of list and library items. Have you tried deleting 100 items from the lists? Well try it and then use the batch job to do the same. You will see the results. Normal coding will take 2 to 5 sec to delete these no of items whereas batch job will done within second. Surprised? yaw that’s the reason to go for the batch job. J

Below is the simple code to use the batch job, and below that I described the issues you might get.

Deleting Items from the Lists-

Use this standard function in your code, pass the spquery and list name and it will delete the specified items from the list.

 

                StringBuilder strBuilerBatchCMD = BatchJobDelete(SPQuery spquery, SPList splist)

                   spweb.AllowUnsafeUpdates = true;

                     string strBatchJobOutPut = spsite.RootWeb.ProcessBatchData(strBuilerBatchCMD.ToString());

                     spweb.AllowUnsafeUpdates = false;

                     spweb.Close();

                     spsite.Dispose();

 

public StringBuilder BatchJobDelete(SPQuery spquery, SPList splist)

        {

            try

            {

                SPListItemCollection items = splist.GetItems(spquery);

 

                StringBuilder sb = new StringBuilder();

                sb.Append(“<?xml version=\”1.0\” encoding=\”UTF-8\”?><Batch>”);

  string batchCommand = “<Method><SetList Scope=\”Request\”>” + splist.ID + “</SetList><SetVar Name=\”ID\”>{0}</SetVar><SetVar  

Name=\”Cmd\”>Delete</SetVar></Method>”;

 

                foreach (SPListItem item in items)

                {

                    sb.Append(string.Format(batchCommand, item.ID.ToString()));

                }

                sb.Append(“</Batch>”);             

            }

            catch (Exception ex)

            {

                //WRITE ERROR TO LOG FILE

                logError(ex);

                return null;

            }

            finally

            {

                //RELEASE OBJECTS HERE

            }

        }

 

Well above code will help you to delete the items from the SharePoint List.

 

Deleting Items from the Document Library –

Below is the batch script for to delete the times from the SharePoint Document library.

sb.Append(“<?xml version=\”1.0\” encoding=\”UTF-8\”?><Batch>”);

string batchCommand = “<Method><SetList Scope=\”Request\”>” + splist.ID + “</SetList><SetVar Name=\”ID\”>{0}</SetVar><SetVar

Name=\”Cmd\”>Delete</SetVar><SetVar Name=\”owsfileref\”>{1}</SetVar></Method>”;

 

                foreach (SPListItem item in items)

                {

                   sb.AppendFormat(batchCommand, item.ID.ToString(), item.File.ServerRelativeUrl);

                }

                sb.Append(“</Batch>”);

 

TroubleShooting-

When you execute the above code it will work perfectly, however there might be scenario where you will come across issue that the process batch job is successfully applied however items are not affected.

The reason behind is batch command. I tried below syntax which failed  

 

Failed Case 1 (Delete is in capital case)

sb.Append(“<?xml version=\”1.0\” encoding=\”UTF-8\”?><Batch>”);

string batchCommand = “<Method><SetList Scope=\”Request\”>” + splist.ID + “</SetList><SetVar Name=\”ID\”>{0}</SetVar><SetVar

Name=\”Cmd\”>DELETE</SetVar><SetVar Name=\”owsfileref\”>{1}</SetVar></Method>”;

                foreach (SPListItem item in items)

                {

                   sb.AppendFormat(batchCommand, item.ID.ToString(), item.File.ServerRelativeUrl);

                }

                sb.Append(“</Batch>”);

 

Failed Case 2 (command is in small caps)

 

sb.Append(“<?xml version=\”1.0\” encoding=\”UTF-8\”?><Batch>”);

string batchCommand = “<method><setlist scope=\”Request\”>” + splist.ID + “</setList><setvar name=\”ID\”>{0}</setvar><setvar

name=\”Cmd\”>Delete</setvar><setvar name=\”owsfileref\”>{1}</setvar></method>”;

                foreach (SPListItem item in items)

                {

                   sb.AppendFormat(batchCommand, item.ID.ToString(), item.File.ServerRelativeUrl);

                }

                sb.Append(“</Batch>”);

 

Failed Case 3 (Batch is capital)

sb.Append(“<?xml version=\”1.0\” encoding=\”UTF-8\”?><BATCH>”);

string batchCommand = “<method><setlist scope=\”Request\”>” + splist.ID + “</setList><setvar name=\”ID\”>{0}</setvar><setvar

name=\”Cmd\”>Delete</setvar><setvar name=\”owsfileref\”>{1}</setvar></method>”;

                foreach (SPListItem item in items)

                {

                   sb.AppendFormat(batchCommand, item.ID.ToString(), item.File.ServerRelativeUrl);

                }

                sb.Append(“</BATCH>”);

 

Inorder to get it work you should try using the command which is specified above under section – Deleting Items from the Document Library

Also what I realised is if use same case for Batch and Delete then small case command will also work.

 

For successfully execution the processbatchjob method returns the xml as

 

<Result ID=”” Code=”0″></Result>

<Result ID=”” Code=”0″></Result>

 

For failed process batch execution it returns the xml format as

 

<method><setlist scope=”Request”>53361993-4390-4947-887a-199251d24c69</setlist><setvar name=”ID”>4899</setvar><setvar name=”Cmd”>Delete</setvar><setvar name=”owsfileref”>/Directory/005.xlsx</setvar></method>

<method><setlist scope=”Request”>53361993-4390-4947-887a-199251d24c69</setlist><setvar name=”ID”>4900</setvar><setvar name=”Cmd”>Delete</setvar><setvar name=”owsfileref”>/Directory/007.xlsx</setvar></method>

 

If you realized any mistake or mismatch here please comment it.

0

Working with Person & Group column in SharePoint‏

Get Username and Groups from SharePoint ‘Person & Group’ Column –

Or

Apply item level permission from ‘Person & Group’ column –

 

 

We usually come across situations where we need to work with ‘Person and Group’ column, either to read the values or to add or to apply it.

Below is the sample code which demonstrates how to get the values from the ‘Person and Group’ column and how to apply it for item level permission.

 

 

//Apply permission to new uploaded file

                       newItem.BreakRoleInheritance(false);

                        SPFieldUser userField = (SPFieldUser)spList.List.Fields.GetField(“ColumnNameA”); 

                       SPFieldUserValueCollection fieldValuecollection = (SPFieldUserValueCollection)userField.GetFieldValue(item[“ColumnNameA”].ToString());

                        foreach (SPFieldUserValue fieldValue in fieldValuecollection)

                       {

                           SPRoleDefinition roleDefinitionNmUser = spWeb.RoleDefinitions[“Read”];

                           SPRoleAssignment roleAssignmentNmUser = null;

         if (fieldValue.User != null)

                          {

                               roleAssignmentNmUser = new SPRoleAssignment(spWeb.EnsureUser(fieldValue.User.LoginName));

                           }

                           else

                           {

                               roleAssignmentNmUser = new SPRoleAssignment(spWeb.SiteGroups[fieldValue.LookupValue]);

                           }

                           roleAssignmentNmUser.RoleDefinitionBindings.Add(roleDefinitionNmUser);

                           newItem.RoleAssignments.Add(roleAssignmentNmUser);

                       }

                        newItem.BreakRoleInheritance(true);

 

 

Enjoy Coding…

 

0

SQL Backup Job Last 7 Days backup.

Create the job with two below script 1. backup the db and 2. call the sp to delete backups older than 7 days.

detail stored procedure is mentioned below.

 

/*******BACKUP THE DB*******************/
DECLARE @DBPath AS NVARCHAR(1000) = N’D:\Backup\’+convert(varchar, getdate(), 112)+’.bak’
BACKUP DATABASE WSS_CONTENT_DB
TO  DISK =  @DBPath

/*******CALL THE PROC WHICH WILL DELETE BACKUPS OLDER THAN 7 DAYS*******************/

USE [WSS_Content_DB]
GO
EXEC [dbo].[usp_DeleteOldBackupFiles]
@path = N’D:\Backup\’,
@extention = N’bak’,
@age_hrs = 168
GO

/*******SP TO DELETE FILES OLDER THAN 7 DAYS*******************/

USE [WSS_Content_DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_DeleteOldBackupFiles]
@path nvarchar(256),
@extention nvarchar(10),
@age_hrs int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @DeleteDate nvarchar(50)
DECLARE @DeleteDateTime datetime
SET @DeleteDateTime = DateAdd(hh, -@age_hrs, GetDate())
SET @DeleteDate = (Select Replace(Convert(nvarchar, @DeleteDateTime, 111), ‘/’, ‘-‘) + ‘T’ + Convert(nvarchar, @DeleteDateTime, 108))
EXECUTE master.dbo.xp_delete_file 0, @path, @extention, @DeleteDate, 1
END
0

Get SharePoint site details

 
Below script will help to get the design time information of the SharePoint server, such as 
Total Sub site Count and address
Users and User group
Roles and Content DB
Deployed solutions and timer jobs
etc.

copy the below text in notepad and save it as a .bat.
Enjoy.

echo =====LOG GENERATED ON mossserver:8081=======================================> mossserver.txt
date >> mossserver.txt
echo =========================================================== >> mossserver.txt
echo ================ENUM Users================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumusers -url "http://mossserver:8081" >> mossserver.txt
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM Groups================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumgroups -url "http://mossserver:8081" >> mossserver.txt
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM Roles================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumroles -url "http://mossserver:8081" >> mossserver.txt
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM ContentDBs================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumcontentdbs -url "http://mossserver:8081" >> mossserver.txt
echo >> mossserver.txt


echo =========================================================== >> mossserver.txt
echo ================ENUM Services================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumservices >> mossserver.txt
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM Sites================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumsites -url "http://mossserver:8081" >> mossserver.txt
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM Solutions================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumsolutions >> mossserver.txt
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM Ssp================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumssp -title <SSP name> [-default | -parent | -all]
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM TimerJobs================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumssptimerjobs -title <SSP Name>
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM Subwebs================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumsubwebs -url "http://mossserver:8081" >> mossserver.txt
echo >> mossserver.txt

echo =========================================================== >> mossserver.txt
echo ================ENUM Templates================================== >> mossserver.txt
echo =========================================================== >> mossserver.txt
stsadm -o enumtemplates [-lcid <language>] >> mossserver.txt
echo >> mossserver.txt

0

SharePoint WebParts Deployments

Reference From –

http://www.cmswire.com/cms/tips-tricks/how-to-deploy-sharepoint-webparts-000618.php  and

http://blog.concurrency.com/sharepoint/how-to-deploy-a-sharepoint-wsp/

http://www.fewlines4biju.com/2011/05/deploy-wsp-file-in-sharepoint-2010.html

Method 1 – manual

    • Copy assembly DLL to either
      – /bin directory for a given IIS virtual server (e.g., c:\inetpub\wwwroot\bin)
      – Global Assembly Cache (e.g., c:\windows\assembly)
    • Copy DWP file to C:\Inetpub\wwwroot\wpcatalog
    • Copy resources to
      – For GAC-registered parts, C:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources
      – For Web Parts in the /bin directory, C:\Inetpub\wwwroot\wpresources
  • Adjust web.config
    – Register as SafeControl
    – Select Code Access Security settings

Method 2: CAB File

    • CAB file should contain
      -Assembly DLL
      -DWP file(s)
      -Manifest.XML
      -Resource files (if needed)
    • CAB won’t contain
      – Code Access Security settings
    • Server-side object model has methods for deploying such a CAB file
  • Deploy with STSADM.EXE
    Located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\BIN
    Add it to your path
    Stsadm -o addwppack -filename filename [-globalinstall] [-force]

Method 3: MSI File via WPPackager

    • All of the features of CAB file deployment, but with
      – Code Access Security support
      – Ability to uninstall via Control Panel
    • Add additional files to project for use by WPPackager
  • Run WPPackager after project is built

Using SharePoint 2010

Steps to generate the wsp file:
Right click on the project/solution in Visual Studio 2010 then choose package. If you are building the

project/solution in debug mode then you will get the .wsp file inside the Bin\Debug folder and if you are building the project in release mode then you will get the .wsp file inside the Bin\Release folder. This wsp file is needed to deploy in the production environment.

This is the best way to create the wsp file in visual studio 2010.

There are different ways you can deploy the .wsp file
Using browser:
Go to the Central Administration -> Site Actions ->Site Settings -> Galleries –> click on Solutions. After this the below page will open as shown in the figure.
 
Click on Upload solution and then browse to the wsp file as shown below in the figure.
 
Once you will click Ok then activation window will appear like below figure.
 
Then you can use the solution.
Using PowerShell:
To add a solution using PowerShell:
Open the SharePoint 2010 Management Shell. You can get to this by going to Start > All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell.
Add-SPSolution {path of wsp file}
To deploy the solution using power shell
Install-SPSolution –Identity {path of wsp file}.wsp –WebApplication http:// -GACDeployment
To update solution
Update-SPSolution –Identity {path of wsp file}.wsp –LiteralPath {local path of wsp file}wsp –GACDeployment
To uninstall solution
Uninstall-SPSolution –Identity {path of wsp file}.wsp –WebApplication http://
Remove solution
Remove-SPSolution –Identity {path of wsp file}.wsp
Using Stsadm:
Add the solution
stsadm -o addsolution -filename {path of wsp file}
Deploy the solution
stsadm -o deploysolution -name {path of wsp file} -url {URL}
Retract solution:
stsadm.exe -o retractsolution -name {path of wsp file}.wsp –URL
Delete Solution
stsadm.exe -o deletesolution -name {path of wsp file}.wsp