Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

Archive for April, 2013

SharePoint 2013 Apps Explored

Posted by JP on April 23, 2013

An overview of SharePoint 2013 Office Store Apps is posted @ SharePointCTO!

You can visit using the link below.

http://www.sharepointcto.com/View.aspx?id=20

image

Advertisements

Posted in C# | Leave a Comment »

SharePoint 2013 New Features

Posted by JP on April 21, 2013

I have created a PowerPoint Slide (PPT) describing features of SharePoint 2013.

It could be useful in refreshing for interviews, demonstrating to clients, deciding on upgrade etc.

Please click the link below to read..

image

Please let me know your comments here..

Note: Existing subscribers can register in site SharePointCTO for SharePoint 2013 articles.

Posted in C# | Leave a Comment »

How to get SharePoint Solutions through Code?

Posted by JP on April 21, 2013

In this article we can explore how to get SharePoint Solutions through code. We are using Server Object Model to retrieve the solutions.

As you know there are 2 types of Solutions in SharePoint:

1. Sandboxed Solutions

2. Farm Solutions

Are Sandboxed & Farm Solutions retrieved differently?

Yes! They both are deployed through different methods & they are retrieved through different object models.

clip_image002

Sandboxed Solution is represented by SPUserSolution class & Farm Solution is represented by SPFarmSolution class.

How to get Sandboxed Solutions?

Sandboxed Solutions are deployed in the Site Collection level. (Feature Activation is different where we activate both for Site Collection & Site levels)

Following is the property to get User Solutions.

site.Solutions

Following is the code to retrieve all User Solutions in a Site Collection:

using (SPSite site = new SPSite("http://localhost"))

{

foreach (SPUserSolution solution in site.Solutions)

{

Console.WriteLine(solution.Name);

Console.WriteLine(solution.SolutionId);

Console.WriteLine(solution.Status);

}

}

How to get Farm Solutions?

Farm Solutions exists in the Farm level. Following is the property to get Farm Solutions.

SPFarm.Local.Solutions

Following is the code to retrieve all Farm Solutions.

foreach (SPSolution solution in SPFarm.Local.Solutions)

{

Console.WriteLine(solution.Name);

Console.WriteLine(solution.SolutionId);

Console.WriteLine(solution.Status);

}

Now let us see installing solutions through the Server Object Model.

Install Sandboxed Solution

Installation of a Solution is a 2 step process consisting of:

1. Adding Solution to Gallery

2. Activating Solution

Following is the code to add solution to gallery:

using (SPSite site = new SPSite("http://localhost"))

{

SPDocumentLibrary gallery

=(SPDocumentLibrary)site.GetCatalog(SPListTemplateType.SolutionCatalog);

SPFile file = gallery.RootFolder.Files.Add("SandboxedSolution.wsp",

File.ReadAllBytes("SandboxedSolution.wsp"));

SPUserSolution solution = site.Solutions.Add(file.Item.ID);

}

Remove Sandboxed Solution

For removing a solution & deactivating its features, following code can be used:

using (SPSite site = new SPSite("http://localhost"))

{

SPUserSolution solution = site.Solutions.Cast<SPUserSolution>().

Where(s => s.Name == "Your Solution").First();

site.Solutions.Remove(solution);

}



Install Farm Solution

For installing Farm Solution, following code can be used:

private static void InstallFarmSolution()

{

SPSolution solution = SPFarm.Local.Solutions.Add("File Path here");

solution.Deploy(DateTime.Now, true, GetAllWebApplications(), true);

}

We need to specify the solution path for the above method. The solution will be installed to all web applications as per the above code. The body of GetAllWebApplications() method is given below.

public static Collection<SPWebApplication> GetAllWebApplications()

{

Collection<SPWebApplication> result = new Collection<SPWebApplication>();

SPServiceCollection services = SPFarm.Local.Services;

foreach (SPService s in services)

{

if (s is SPWebService)

{

SPWebService webService = (SPWebService)s;

foreach (SPWebApplication webApp in webService.WebApplications)

{

result.Add(webApp);

}

}

}

return result;

}

Remove Farm Solution

Removing Farm Solution is termed as Retract Solution. You can find the appropriate method in:

private void RetractFarmSolution(SPSolution solution)

{

solution.Retract(DateTime.Now);

}

A timer job will be created to Retract the solution. You can specify the time to start retraction.

For removing solution only from a specified web applications, there is an overloaded method.

private void RetractFarmSolution(SPSolution solution, Collection<SPWebApplication> webApplications)

{

solution.Retract(DateTime.Now, webApplications);

}



References

http://msdn.microsoft.com/en-us/library/ee361616.aspx

http://msdn.microsoft.com/en-us/library/hh528516(v=office.14).aspx

Summary

In this article we have explored how to use the Server Object Model to retrieve Sandboxed & Farm Solutions through code.

For reference please note that:

1. Sandboxed Solution is represented as SPUserSolution

2. Farm Solution is represented as SPFarmSolution

Posted in C# | Leave a Comment »

SharePoint 2010 – How Alerts works?

Posted by JP on April 12, 2013

In this article we can explore the underlying infrastructure of SharePoint Alerts. Let us analyze step by step what is happening in the background when we create an alert, alert is triggered, email is sent etc.

What are Alerts?

SharePoint provides an excellent feature which notifies the users on changes of item/library.

Uses can set alerts on:

· Library / List

· Document / Item

You can set alerts through the SharePoint user interface as shown below:

clip_image002

In order to see the above button, you need to set your Email Server in Central Administration > System Settings > Configure outgoing e-mail settings.

clip_image004

clip_image006

For receiving the emails triggered you can use an SharePoint Email Notification Tool like smtp4dev.

Create Alert

Now you are ready to create an alert & we can examine what happens in the database.

clip_image008

Open the database & you can see the following recode in ImmedSubscriptions table.

clip_image010

You can see that the ListId column is assigned with List GUID.

The table structure follows:

clip_image011

clip_image006[1]

You can see database server & name through Central Administration > Manage content databases link.

If you have created a Summary Alert (daily or weekly) you can see the record was created inside SchedSubscriptions table.

The structure of SchedSubscriptions table.

clip_image012


Timer Job

Timer Jobs are responsible for building the Alert using template & sending the Emails. We can see the timer job status through Central Administration > Monitoring > Check job status link.

clip_image014

Scrolling down, you can see the Timer Job for Immediate Alert.

clip_image016

You can see the Status of last execution there. In my case it is succeeded. Click on the link to see the settings as shown below:

clip_image018

In the above case the Timer Job is scheduled to run every 5 minutes. You can try clicking the Run Now button to trigger execution.

Alert Templates

Timer Job creates the email content of through Alert Template file. We can modify the file, but copying & modifying is recommended. We can define template in the list & library level.

The Alert template can be found in 14 hive > TEMPLATE > XML folder.

clip_image020

By default there are 2 templates – one for email & other for sms. The alerttemplates.xml file contains around 10 thousand lines.

We can change the alert template through PowerShell & STSADM commands.

References

http://bit.ly/10uiVpB

Summary

In this article we have explored the activities & tables involved while working with SharePoint Alerts.

Posted in C# | Leave a Comment »

What is Ensure User?

Posted by JP on April 8, 2013

In this article we can explore a new command associated with Squadron > Explorer add-in.

What is Ensure User?

Ensure User is the command that invokes EnsureUser() method for the SPWeb objects specified.

Why we need to call it?

For each new user in a web site, a user record is added to the User Info table. For new SharePoint installations, when the users login to the site first time, there will be simultaneous addition of records to the above table & might result in SQL Server Throttling error.

A wise advice for the problem is to add the user explicitly to each web site before the opening SharePoint to public.

image

Squadron is a Free SharePoint Administration tool available at www.sharepointcto.com.

image

How to perform Ensure User?

Please download & Install the latest version of Squadron. After executing it in Farm Account mode you will receive the following screen.

image

Enter the URL in the top pane & click the Explorer item from left pane. In the appearing SharePoint Web Application view, select you web item.

image

Click on the Ensure User button visible in the screen. In the appearing dialog enter the user names in the format DOMAIN\User:

image

After entering the user names, click the Execute button in the bottom to continue. You will get the following message box after operation is completed.

image

This makes sure that the user is available in the UserInfo table for the particular web site. This will prevent the possible SQL Server Errors happening in SharePoint Installations with hundreds of users.

image

You can also invoke the Ensure User within the Web Application & Site Collection level. The same button will be enabled for those commands.

For Web Application item selection:

image

For Site Collection item selection:

image

On invoking the Ensure User command, all the Web items will be enumerated in the selection dialog. You can select the web items to be processed for.

image

Following is the code that performs the EnsureUser() method invoking.

foreach (string user in UsersText.Lines)
            {   
                if (string.IsNullOrEmpty(user))
                    continue;

                foreach (int i in WebList.CheckedIndices)
                {
                    SPWeb web = WebList.Items[i] as SPWeb;
                   
                    try
                    {
                        web.EnsureUser(user.Trim());

                        SquadronContext.WriteMessage("Success: " + web.ToString() + " " + user);
                    }
                    catch (Exception ex)
                    {
                        SquadronContext.WriteMessage("Failure: " + web.ToString() + " " + user + " " + ex.ToString());
                    }
                }
            }

References

http://bit.ly/10uiVpB

Summary

In this article we have explore the Ensure User command. There are more commands associated with the Explorer Add-in of Squadron – plus, they are context sensitive based on Site / Web / List / Item types.

Posted in C# | Leave a Comment »

Squadron – Invalid URL Exception & Solutions

Posted by JP on April 1, 2013

While working with the Explorer Add-in, you might receive the following error:

Invalid URL!

image

Problem

The Web Application object cannot be created using the URL specified.

Solution

You can try the following solutions:

1. Open Central Administration & Ensure the URL is correct

Open Central Administration > Manage web applications link

image

2. Execute the application from a Machine within Farm Environment & using the Farm Account.

In the Farm Machine, you an use CMD.EXE > RUNAS command to start Squadron in Farm Account context.

image

You can also try the http://localhost url within the farm environment.

Example: runas /user:DOMAIN\USER Application.exe (You will be prompted for Password)

 

clip_image002

Squadron is a Free SharePoint Administration tool available at http://www.sharepointcto.com.

clip_image004

Posted in C# | Leave a Comment »