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

Posts Tagged ‘sharepoint’

Available Now at Amazon!

Posted by JP on November 5, 2012

Black Page - Yellow Title

Book provides Basics to Advanced Topics coverage & Real World Scenarios to bet on your confidence!

Working on the commitment to make Best Resources available for SharePoint!

The Book is available at Amazon for Purchase.

I have made sure to set the minimum rate for the maximum quality &  quantity.

Advertisements

Posted in C#, SharePoint | Tagged: , , | 37 Comments »

Error Scenario :: Server Error – No available sandboxed code execution server could be found.

Posted by JP on October 15, 2012

While working with SharePoint 2010, I encountered the following error: No available sandboxed code execution server could be found.

image

Solution

Start the SharePoint 2010 User Code Host windows service

Steps

1. Run services.msc from the run window

image

 

2. Locate the service and click the Start button

image

Hope your problem is fixed!

Posted in SharePoint | Tagged: , , , , | Leave a Comment »

Configuring Email for Development Server

Posted by JP on October 14, 2012

In this article we can explore how to configure Email for Development Server. In real world development scenarios you need to work with Email enabled lists / workflows / code.

Email

Scenario

Your customer reported a problem with Email sending from a web part you have developed. You need to ensure the piece of code works fine in your development machine. As there is no email server configured in your machine – How to test this code?

Solution

We can set up a Development Server with emailing enabled. Setting up Email for the Development Server along with a Receiver tool you can ensure that emailing code is working perfect.

Steps

Following are the steps involved:

1. Configure outgoing SMTP server

2. Set Email property for User Profiles

3. Install smtp4dev tool

4. Test Email Code

Please note that I am using a Windows 7 64-bit machine for working with this. The same configurations should work for Windows Server development machine.


Configure outgoing SMTP server

Open Central Administration and click on the System Settings category from the left.

image

In the appearing page click on the Configure outgoing e-mail settings link highlighted above. You should get the page given below.

image

Enter the Outbound SMTP server as your machine name. Please enter a name instead of IP Address or localhost.

Enter the From and Reply-To address.

Click the OK button to save the changes.


Set Email property for User Profiles

As the next step we need to set the user profile property E-mail for testing the feature. You can set this through:

1. My Profile of each user

2. Central Administration for all users

Let us use the Central Administration way as we can set for multiple users. Open Central Administration > Manage service applications > Select User Profile Service Application > Click Manage button from toolbar.
image

In the appearing page click on the Manage User Profiles link as highlighted below:

image

In the appearing page search for user and from the result choose Edit menu item.
image

In the Edit profile page set the Work-email property and save changes.

image

Install smtp4dev tool

Now we can try installing the smtp4dev tool (a wonderful tool) that captures the Port 25 of your machine. You can download the tool from following location:

http://smtp4dev.codeplex.com/

Click the Download button on the appearing page.

image

Run the downloaded file and you should see the following screen.

image

By default the tool started to listen on Port 25. You can minimize the tool and it is available in the system tray.

Note Running another instance of the smtp4dev tool cannot listen to the same port 25. You need to invoke the previous copy of the tool from system tray to view any email messages.

Test Email Code

Now we are ready to test the email code. Start a new SharePoint Console application, change the project properties to .Net Framework 3.5 and replace the Program class content with following code.

using System.Collections.Specialized;

class Program

{

static void Main(string[] args)

{

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

{

StringDictionary messageHeaders = new StringDictionary();

messageHeaders.Add("to", "to@server.com");

messageHeaders.Add("cc", "cc@server.com");

messageHeaders.Add("from", "from@server.com");

messageHeaders.Add("subject", "Email Subject");

messageHeaders.Add("content-type", "text/html");

SPUtility.SendEmail(site.OpenWeb(), messageHeaders, "Email Body");

}

}

}

For the time being we are using dummy email address. Try executing the code. You can see the email being captured by smtp4dev tool.

image

References

http://tinyurl.com/sp2010-confemail

Summary

In this article we have explored how to configure email server for a development machine and use smtp4dev tool to capture the emails generated from the machine. You can use the same configuration to test other emails through Workflows, Web Parts etc. that are generated through SharePoint.

Please note that here we are setting up a development machine email server and for configuring the actual email service you need to check the link from References section.

Posted in SharePoint | Tagged: , , , , , | 6 Comments »

Error Scenario – Workflow History list not found!

Posted by JP on October 2, 2012

In this article we can explore a common scenario associated with creating Workflows in Visual Studio 2010.

Scenario

You are creating a workflow through Visual Studio 2010. The SharePoint 2010 templates are installed and while selecting Workflow template and entering site url you receive the following error:

The SharePoint site at URL is missing a target, task, or history list. Each of these lists is required to associate a workflow template. Please create a list and then launch this wizard.

clip_image001[5]

Root Cause

Workflow requires the following lists for its working:

· Workflow History of Template 140

· Workflow Tasks of Template 107

Solution

There are many solutions to the above problem like:

1. Create a new site from a site template that includes Workflow History & Task list

2. Create the 2 lists Programmatically

3. Create the 2 lists using PowerShell

Here I would apply the second solution, using C# code to create the 2 lists.

 

Implementation

Create a new SharePoint Console Application and change the project properties as:

· Target Framework to 3.5

Add the following code to the Main() method. Please change your url accordingly.

class Program

{

private static string URL = “http://yourblanksite”;

static void Main(string[] args)

{

using (SPSite site = new SPSite(URL))

{

using (SPWeb web = site.OpenWeb())

{

web.Lists.Add(“Workflow History”, string.Empty, SPListTemplateType.WorkflowHistory);

web.Lists.Add(“Workflow Task”, string.Empty, SPListTemplateType.Tasks);

}

}

}

}

Execute the above code and if it completed without errors, your problem is solved. Try creating the workflow again and you should not see the error.

Verification

Inside SharePoint you can verify our new lists as shown below.

clip_image003[6]

Template Enumeration Reference

You can refer the Template Enumeration (SPListTemplateType) here.

Name Description
InvalidType Not used. Value = -1.
NoListTemplate unspecified list type. Value = 0
GenericList Custom list. Value = 100.
DocumentLibrary Document library. Value = 101.
Survey Survey. Value = 102.
Links Links. Value = 103.
Announcements Announcements. Value = 104.
Contacts Contacts. Value = 105.
Events Calendar. Value = 106.
Tasks Tasks. Value = 107.
DiscussionBoard Discussion board. Value = 108.
PictureLibrary Picture library. Value = 109.
DataSources Data sources for a site. Value = 110.
WebTemplateCatalog Site template gallery. Value = 111.
UserInformation User Information. Value = 112.
WebPartCatalog Web Part gallery. Value = 113.
ListTemplateCatalog List Template gallery. Value = 114.
XMLForm XML Form library. Value = 115.
MasterPageCatalog Master Page gallery. Value = 116.
NoCodeWorkflows No Code Workflows. Value = 117.
WorkflowProcess Custom Workflow Process. Value = 118.
WebPageLibrary Wiki Page Library. Value = 119.
CustomGrid Custom grid for a list. Value = 120.
SolutionCatalog Solutions. Value = 121
NoCodePublic No Code Public Workflow. Value = 122
ThemeCatalog Themes. Value = 123
DataConnectionLibrary Data connection library for sharing information about external data connections. Value = 130.
WorkflowHistory Workflow History. Value = 140.
GanttTasks Project Tasks. Value = 150.
Meetings Meeting Series (Meeting). Value = 200.
Agenda Agenda (Meeting). Value = 201.
MeetingUser Attendees (Meeting). Value = 202.
Decision Decisions (Meeting). Value = 204.
MeetingObjective Objectives (Meeting). Value = 207.
TextBox Text Box (Meeting). Value = 210.
ThingsToBring Things To Bring (Meeting). Value = 211.
HomePageLibrary Workspace Pages (Meeting). Value = 212.
Posts Posts (Blog). Value = 301.
Comments Comments (Blog). Value = 302.
Categories Categories (Blog). Value = 303.
Facility Facility. Value = 402
Whereabouts Whereabouts. Value = 403
CallTrack Call Track. Value = 404
Circulation Circulation. Value = 405
Timecard Timecard. Value = 420
Holidays Holidays. Value = 421
IMEDic IME (Input Method Editor) Dictionary. Value = 499
ExternalList External. Value = 600
IssueTracking Issue tracking. Value = 1100.
AdminTasks Administrator Tasks. Value = 1200.
HealthRules Health Rules. Value = 1220
HealthReports Health Reports. Value = 1221

The link is added in the References section too.

References

http://tinyurl.com/sp2010-lsttmpref

Summary

In this article we have explored a common error scenario associated with workflow creation and a solution for it.

Posted in SharePoint | Tagged: , , , , , | 4 Comments »

CAML Query Builder

Posted by JP on September 11, 2012

In this article we can explore the SharePoint 2010 free tool CAML Query Builder.

What is CAML?

CAML represents Collaborative Markup Language which is an XML based language for querying and updating SharePoint objects. 

What are the Advantages of this Tool?

We can see following are the advantages of using this Tool:

1.      As CAML is non-typed and error prone during development the CAML Query Builder provides advantage of writing and validating the CAML queries.

2.      An Intuitive User Interface is provided by the application for more easier Query building

3.      Above all the Tool is Free

Download

You can download the tool from following location:

            http://www.u2u.be/res/tools/camlquerybuilder.aspx

Please make sure you download the 2007 version which is working well with SharePoint 2010.

image

Download the tool and extract the zip file to a temporary folder.  Execute the setup.exe inside it and follow the wizard to install the tool.

Note: The SharePoint binaries are required for working with this tool.


 

Starting with the Tool

After the installation execute the tool from Start Menu or Desktop.  The tool is available on Start Menu > U2U > CAML Builder > CAML Builder as shown below.

image

On execution you can see the following screen.

image

Enter the following details as shown above:

·         Url of the site

·         Connect through SharePoint Web Services

·         User Credentials

After entering the details click the Connect button.

Note: As the tool is for SharePoint 2007, the Connect via Object Model option cannot be used. 

Inside the Tool

On connecting successfully you will get the following screen.

image

You can see that the above screen displays your existing Lists and Libraries.  Additionally it displays the Lists & Libraries which are hidden in the Quick Launch too.

Create a Contacts List

To start with create a Contacts list of Contacts template inside your SharePoint site.  Insert the following test data into it and refresh the CAML Query Builder Tool.

image

Building your first CAML Query

Now we can try building our first query using the CAML Query Builder Tool.

Here we are trying to find the list items for which First Name contains ‘1’.

Step 1: Start the New Query pane

Right click on the Contacts list from the left side pane and choose the New Query menu.

image

You can also use the New Query button from the tool bar.

Step 2: Specify the Column Parameters

From the pane on the right side, choose the Filter Column > First Name using the second drop down list as shown below.

image

Now choose the option Contains from the third drop down list.  Enter the text 1 in the textbox. 

Note: Following are the drop down lists shown above and the purpose:

·         The first drop down list contains the options Filter, And, Or. 

·         The second drop down list contains the Column Names of the selected list. 

·         The third drop down list contains the conditions like Equal, Not Equal, Contains etc.

Step 3: View the CAML Query

On performing the above steps you can see that the CAML Query is generated for the above condition.  You can see the CAML Query in the bottom pane as shown below.

image

Step 4: Executing the CAML Query

Now you are ready with the CAML Query but it is not Tested yet.  For testing the query use the Execute query button from the top toolbar as shown below.

image

You should be getting the results as shown above.

So now you are ready with the CAML Query which is tested and can be copied to your application.


 

Step 5: Adding OR Condition

Now we can play a little bit more by adding an OR Condition to list all the Contacts items which contains ‘1’ or ‘2’ in the First Name column.

For achieving this select the Or option from the Filter drop down list.

image

You can see that a new filter row is getting added to the query pane.  Enter the new parameters in the new row as shown below.

image

Step 6: Execute the New Query

Now you can try executing the above query and this time the result should show both the records from the Contacts list.

image

 

Add Order By Element

Now we can try using the Add Order By element button.  This option allows us to add the Order By CAML tags.  You can specify a column and the order (ascending  or descending)

Create a new Query and click on the Add Order by element button from the toolbar.

Choose the ID column and order as Descending.

image

On executing the query you can see the following result.

image

Please note that the items are now shown in the Descending order of ID values.

Multiple Order By Columns

We can have multiple Order By columns.  Use the same button again to add a new Order By CAML tag as shown below.

image

This time we are having 2 Order by columns.  The Created By column with Ascending sorting.

More Options in CAML Query Builder Tool

You can explore more options in building CAML Queries using the tool like:

1.      Creating Queries for Date Columns

2.      Trying with And operator

3.      Filtering with Equal To, Lower Than, Greater Than conditions

4.      Using the Copy Query button to copy the query to clipboard

References

http://tinyurl.com/sp2010-camlqb

Summary

In this article we have explored the tool CAML Query Builder.  In real life scenarios this tool should give time, cost & efficiency advantages.

 

Posted in SharePoint | Tagged: , | 2 Comments »

ULS Log Viewer

Posted by JP on September 11, 2012

In this article we can explore the SharePoint 2010 free tool ULS Log Viewer.  This is a tool from Microsoft and we are free to use it, but there is no customer support for any issues or queries.

What is Logging?

Eventually in the life cycle of a SharePoint deployment the Administrator and Developer need to look into the log information of SharePoint.  There are basically 3 kinds of log information to look for.

1.      SharePoint 14 hive LOGS folder where the SharePoint log information is kept.

2.      IIS web application log files inside INETPUB LOGS folder

3.      Windows Event log where Service Application log information are kept.

What is ULS?

The ULS represents Unified Logging Service and it captures the following:

·         Exceptions of SharePoint

·         Logs by Applications

The unified logging is stored in .log files in 14 HIVE > LOGS folder.  The unified view helps in understanding the problem in the order of activities.

Note: SPDiagnosticsBase class in namespace Microsoft.SharePoint.Administration enables writing Trace Log in SharePoint 2010.  This is the preferred way for SharePoint 2010 and it includes WriteTrace() and WriteEvent()  methods to be overridden.

Who is the Intended Audience?

This tool can be used by following type of audience:

1.      SharePoint Administrators

2.      Developers

3.      Architects

Download

You can download the tool from following location:

            http://archive.msdn.microsoft.com/ULSViewer

On opening the above link you should get the following page:

image

Click on the Downloads tab and download the file shown.

image

 

How to view the LOGS files?

We are actually interested in the first option of looking into the SharePoint 14 hive LOGS folder.  You can open the folder and see that there are a number of log files as shown below.

·         C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

image

The latest log file (sorted by date) should contain the latest log information as shown below:

image

So there involves a bit of clumsy tasks to view the log information of SharePoint. 


 

What are the Advantages of this Tool?

The ULS Log Viewer tool provides the following advantage:

1.      A better user interface to view the Log Information

2.      Filtering of log levels based on Basic, High, Verbose etc.

3.      Formatting of log information

4.      Real time Log Information Viewing

5.      Exporting of Log Information to CSV files

6.      Multiple Machine Log viewing

7.      It is Free

Starting with the Tool

After downloading you can execute the tool.  The main screen looks like as shown below.

image

Viewing a Log file

You can use the File > Open from > File menu to open a log file from the 14 hive LOGS folder.
image

As you can see there are Time, Server, Process, Product, Category, Level information for each rows listed.

Filtering the Rows

You can filter the rows using the tool bar buttons:

image

 The rows will be filtered accordingly.

 

Real time Tracing

Another advantage of the tool is Real Time Tracing.  We can see the real time log messages by watching the tool.

For monitoring a folder for real time log messages, use the File > Open From > ULS menu item.

image

On enabling ULS monitoring, the Notifications List contains the source log file which contains the new log entries.  Please note that the specified folder can contain multiple log files.

Click on the Notifications List to see the source file which contains new log entries.

Command Line

The real time mode can be started using command line too:

            ULSLogViewer.exe realtime:FolderPath


Exporting to File

We can also export the selected lines to a File using the context menu.

image

Smart Highlight

The Smart Highlight button on the toolbar enables highlighting the contents of similar texts.  For example placing the mouse over Medium should highlight all the entries of type Medium.

image

You need to click the Smart Highlight button to enable this view.

References

http://tinyurl.com/sp2010-ulsdoc

Summary

In this article we have explored the ULS Log Viewer tool.  In real life scenarios this tool should give time, cost & convenience advantages.

Posted in SharePoint | Tagged: , | Leave a Comment »

Error: No User Profile Application available to service the request. Contact your farm administrator.

Posted by JP on September 10, 2012

I was getting this error while using the code:

using (SPSite site = new SPSite("http://localhost"))
{
                UserProfileManager manager = new UserProfileManager(ServerContext.GetContext(site));

                UserProfile profile = manager.GetUserProfile("hp\\hp");
                var personalSite = profile.PersonalSite;

                profile.CreatePersonalSite();
}

Solution

Searching a while I found the solution like, I have to give the user (hp\hp) Full Control Permission.  Following are the steps to achieve this.

Open Central Administration and Select the User Profile Service Application row.

image

Select the Permissions dialog from the ribbon.

image

Enter the user (hp\hp in my case) in the dialog, click the add button, check the Full Control and click OK

Try running the code again and the error should disappear.  Good Luck Ahead!

Posted in SharePoint | Tagged: , | 2 Comments »

Error: Your personal site cannot be created because Self-Service Site Creation is not enabled. Contact your site administrator for more information.

Posted by JP on September 10, 2012

Solution

  1. Open Central Administration as Administrator
  2. Select Manage Web Applications
  3. From the toolbar choose Self Service Site Creation

image

4.  Turn On the feature and click OK button

image

 

Information

Self Service Site Creation is a feature that enables site creation by the user without requiring Administrative privileges.  Users can create their own sites if the Self Service Site Creation is enabled in the web application level.

Posted in SharePoint | Tagged: , | Leave a Comment »

UnauthorizedAccessException :: This site does not host personal sites (try ‘http://hp:80/my’)

Posted by JP on September 9, 2012

Scenario: While calling the method CreatePersonalSite()

using (SPSite site = new SPSite("http://hp"))
{
                UserProfileManager userProfileManager = new UserProfileManager(SPServiceContext.GetContext(site));

                UserProfile profile = userProfileManager.GetUserProfile("hp\\user");
                SPSite personalSite = profile.PersonalSite;

                profile.CreatePersonalSite();
}

Solution

The My Site site collection was missing.  Create a new site collection with My Site template from Central Administration.

Open the Central Administration > Create Site collections link.

image

After entering the details click Ok button to create the site.  The error should disappear now onwards.

Posted in SharePoint | Tagged: , | Leave a Comment »

My Site access :: HTTP 404 Error

Posted by JP on September 9, 2012

I was facing the problem for only one user.  While accessing the My Site HTTP 404 error was displayed.  Other users seems to have the My Site working fine.

Following is the fix which worked for me:

static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://hp"))
            {
                UserProfileManager userProfileManager = new UserProfileManager(SPServiceContext.GetContext(site));

                UserProfile profile = userProfileManager.GetUserProfile("hp\\user");
                SPSite personalSite = profile.PersonalSite;

                profile.CreatePersonalSite();
            }
        }

Posted in SharePoint | Tagged: , | Leave a Comment »