Posts Tagged ‘SPF’
SP 2010: Web Application settings (web.config) modifications in SharePoint 2010 via code
September 7th, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
I’ve been getting some questions lately about modifications to web.config files and SharePoint 2010 – is it possible to automate so that the administrator don’t have to manually edit those files on each WFE?
Yes, that’s the easy answer. This was possible in SharePoint 2007 as well.
In this article I’ll quickly demonstrate how you (using a Web Application feature) can make modifications to web.config automatically.
Please note that this is just a getting-started point which you’ll have to work deeper into to tweak it to your likings for updates and removals from the web.config file.
Automatic web.config changes using a SharePoint 2010 feature
Basically, if you want to get some type of change into the web.config, it oftentimes has to do with adding custom settings or values that you’ll later reference in your applications.
In this scenario, we’ll add the following key into web.config using a Feature Receiver, so we don’t have to do it manually after/before deploying our solutions:
<add key= "isAwesome " value= "1 " />
So, in order to achieve this programmatically without actually editing the web.config by hand – you could utilize the class called SPWebConfigModification something like this:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
var value = 1; // We want to set the key isAwesome to the value "1"
var webApp = properties.Feature.Parent as SPWebApplication ;
var mySetting = new SPWebConfigModification
{
Path = "configuration/appSettings",
Name = string.Format("add [@key='isAwesome'] [@value='{0}']", value),
Sequence = 0,
Owner = "Zimmergren.SP2010.WebConfigModifications.Awesomeness",
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
Value = string.Format("<add key='isAwesome' value='{0}' />", value)
};
webApp.WebConfigModifications.Add(mySetting);
webApp.Update();
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
By executing this cute snippet of code you will actually add the setting called isAwesome to the web.config of your web application. (This will be persisted to all the WFE’s of course).
Please note: You will need to tweak your code quite a lot to make the sweet SPWebConfigModification class behave the way you want on activation/deactivation of the feature. This should at least give you a starting point
Summary
In this short introductory article about web.config modifications I’ve talked a bit about how you can automate the process of altering your web.config files without actually opening them on the file system.
Nothing fancy, but a good starting point for those of you who requested some info on the topic.
Enjoy!
- Posted in Technical
- 12 Comments
- Tags: SharePoint, SharePoint 2010, SPF, SPS, Web Config Modification
SP 2010: Find error messages with a Correlation ID token in SharePoint 2010
September 3rd, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
In SharePoint 2010, you’ve got some new capabilities for error reporting and logs. One of the most noted features for me as a developer is that whenever you bump into an error message – you’ll be presented with a correlation ID token.
In this article I will try to explain how you can fetch that token from SharePoint, and also provide a small snippet of code to be able to build your own “Log Searcher Web Part” for your administrators.
Correlation ID, what’s that?
In SharePoint 2010, you get a Correlation ID (which is a GUID) attached to your logs/error messages when something happens. This ID can then be used to lookup that specific error from the logs.
This Correlation ID is used per request-session in SharePoint 2010, and if you are in the process of requesting some information from SharePoint and bump into some problems along the way – your Correlation ID will be the best starting point for searching for what went wrong along that request!
You might get an error message like this in SharePoint 2010 (don’t worry, if you haven’t seen one like this one yet – just hang in there, sooner or later you will..
)
Search for the log messages based on the Correlation ID token
So if you’ve gotten such an error message and want to find out more information about the actual error and don’t have the time to go around poking in the logs and searching – there’s a few methods you can do this rather easily, as described below.
Using PowerShell to lookup a log message based on Correlation ID token
One of the quick-n-awesome ways to do this is to simply hook up a PowerShell console (SharePoint 2010 Management Shell) and then just write the following command (replace the <GUID> with the Correlation Id):
get-splogevent | ?{$_Correlation -eq "<GUID>" }
This will give you the details about your specific error like this in the console:
You might want to be more precise and get more specific details out of your query, then you can try something like this:
get-splogevent | ?{$_.Correlation -eq "<GUID>"} | select Area, Category, Level, EventID, Message | Format-List
This will give you the details about your specific error like this with some juicy details:
Finally if you would want these messages to be put into a text or log file instead, you could just add the classic “> C:Awesome.log” after the command like this:
get-splogevent | ?{$_.Correlation -eq "<GUID>"} | select Area, Category, Level, EventID, Message | Format-List > C:Awesome.log
On MSDN they have an overvoew of using SP-GetLogEvent which I would recommend!
Using SQL queries to find log message based on Correlation ID token
You can utilize the SQL logs database to fetch the specific error message based on Correlation id as well. In your logging DB (usually called WSS_Logging, but can be called something else if you’ve changed it) there is a view called ULSTraceLog which you can query with a simple SQL query and fetch the results.
I’ve created a query to fetch the items from the logging database like this:
select [RowCreatedTime], [ProcessName], [Area],
[Category], EventID, [Message]
from [WSS_UsageApplication].[dbo].[ULSTraceLog]
where CorrelationId=< pre>'B4BBAC41-27C7-4B3A-AE33-4192B6C1E2C5'
This will render your results in the SQL Query window like this:
This can of course be implemented in a Web Part for your convenience as well (I’ve created a bunch of diag. and logging web parts that I’ve got deployed to Central Admin) that could look like this (this way you don’t need physical access to the ULS logs all the time, but can do a quick lookup from the web part):
Get the current Correlation ID by using code
I got this piece of code from my good friend Wictor’s blog post. Thanks Wictor – this made my Logging-project more satisfying!
With the following code you can fetch the current Correlation Id of a request.
Create a method (in my case called GetCurrentCorrelationToken()) to wrap up the functionality of returning the current token like this:
public class CorrelationId
{
[DllImport ("advapi32.dll")]
public static extern uint EventActivityIdControl(uint controlCode,ref Guid activityId);
public const uint EVENT_ACTIVITY_CTRL_GET_ID = 1;
public static Guid GetCurrentCorrelationToken()
{
Guid g = Guid .Empty;
EventActivityIdControl(EVENT_ACTIVITY_CTRL_GET_ID, ref g);
return g;
}
}
Then from wherever in your code you can simply call it by using this approach:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = CorrelationId .GetCurrentCorrelationToken().ToString();
}
(Normally you might want this in a try/catch statement or something like that)
Summary
This article should give you (administrator and developer) an insight in how you easily can track the specific errors your users encounter in their/your application(s). If a user gets an error message in SharePoint 2010, they’ll also see the Correlation ID.
If you can train your users to write down that Correlation ID along with a few simple steps on how the error might have been occurring, you’re going to have a much easier way to find the details about that specific error than ever before.
Enjoy!
- Posted in Technical
- 13 Comments
- Tags: Correlation ID, Debugging, Logging, SharePoint, SharePoint 2010, SPF, SPS, ULS
SP 2010: Certification exam details for SharePoint 2010 published
March 28th, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
Microsoft has published the two developer-oriented certifications for SharePoint 2010 on Microsoft Learning.
Personally, I think there is a huge improvement now as we’re not only getting the MCTS-credit but can now also become an MCPD (Microsoft Certified Professional Developer) on the SharePoint platform. Something I’ve been waiting for a long time
SharePoint 2010 exams
For us developers/solution architects there are two certifications of interest (of course you should do the IT-pro tracks as well, but let’s start here with the developer ones):
- 70-573: TS: Microsoft SharePoint 2010, Application Development
- 70-576: PRO: Designing and Developing Microsoft SharePoint 2010 Applications
SharePoint 2007 Exams
Way back in 2007 I wrote about passing all 4 certifications for SharePoint 2007 (link here). For SharePoint 2007 there is four certifications for the 2007 product-line:
- 70-541 – TS: Microsoft Windows SharePoint Services 3.0 – Application Development
- 70-542 – TS: Microsoft Office SharePoint Server 2007 – Application Development
- 70-630 – TS: Microsoft Office SharePoint Server 2007, Configuring
- 70-631 – TS: Microsoft Windows SharePoint Services 3.0, Configuring
Summary
So, keep an eye out on those two new certifications and be well prepared when they arrive – should be a fun ride
- Posted in Technical
- 3 Comments
- Tags: Certification, SharePoint, SharePoint 2010, SPF, SPS
SP 2010: Dynamically displaying messages to your users with the Notification and Status bar areas in SharePoint 2010
March 17th, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
With the new version of SharePoint comes a full set of new and awesome features that you’ll have to indulge and learn. One of the small things that makes my day much more fun is to display messages to your users in the Status- and Notification areas.
Example of a message in the Status bar area:
Example of a message in the Notification area:
How do we make this magic happen?
In order to display these messages, you really (really) don’t need a lot of code. I’ll lay out the simple code I used to display the messages you saw in my screenshots.
It’s all JavaScript based, so get ready to dig out those old JS skills you know you’ve got lying around somewhere
Oh wait, you don’t need skills to do this, it’s just that easy!
Show me a Status bar!
JavaScript:
function ShowStatusBarMessage(title, message)
{
var statusId = SP.UI.Status.addStatus(title, message, true);
SP.UI.Status.setStatusPriColor(statusId, ‘yellow’); /* Set a status-color */
}HTML, call the JS method:
<a onclick="ShowStatusBarMessage(‘Title’!',’Awesome message!’)">
Display Status Bar message!
</a>
Show me a Notification popup!
JavaScript:
function ShowNotificationMessage(tooltip, message, sticky)
{
SP.UI.Notify.addNotification(message, sticky, tooltip, null);
}HTML, call the JS method:
<a onclick="ShowNotificationMessage(‘I am cool!’,'This is a cool message’,false)">
Display Notification!
</a>
Summary
Actually, there’s no need for a summary. It’s way too easy.
Enjoy!
- Posted in Technical
- 6 Comments
- Tags: SharePoint, SharePoint 2010, SPF, SPS, UI
SP 2010: LINQ to SharePoint – What CAML lies behind my query?
February 19th, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
The two following questions are quite popular in my SharePoint 2010 developer training classes, so I ought to answer them right here.
- "What does LINQ to SharePoint really do?"
- "Can I see the CAML query generated by the LINQ to SharePoint query?"
The answer is simple: Yes, you can see the results of your generated LINQ query by using the Log property of your DataContext object.
What CAML lied behind my LINQ to SharePoint query?
In order to fetch the CAML query that lies behind your LINQ query, all you need is to work with the .Log object of your DataContext.
See this simple example, which simply outputs the CAML query to an XML-file for easy reading:
This will essentially generate the following content in the file C:MyEntitiesDataContextQuery.xml:
As you can see, the LINQ to SharePoint query is automatically turned into a CAML Query.
Summary
Yep, all you need is the .Log property to fetch the CAML query from your LINQ statement. In my sample I’m outputting it to a file called C:MyEntitiesDataContextQuery.xml.
You could of course output it in any other way you want – not just a physical file on the file system. The Log property is of the type TextWriter.
Enjoy!
- Posted in Technical
- No Comments
- Tags: CAML, LINQ, Queries, SharePoint, SharePoint 2010, SPF, SPQuery, SPS
SP 2010: Getting started with LINQ to SharePoint in SharePoint 2010
February 19th, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
In SharePoint 2010 you now have the ability to use LINQ syntax to fetch items from your lists instead of using the "traditional" approach of CAML queries. (Including SPSiteDataQuery and SPQuery objects)
In this article I will give you a brief introduction to how you can get started using LINQ queries in SharePoint, also known as LINQ to SharePoint.
Basics of LINQ?
As a prerequisite to this article, I’m going to imply that you know what LINQ is and how to write basic LINQ queries in any .NET application already. I’m not going to dive into the details about LINQ or the syntax itself here – please see MSDN for that!
LINQ to SharePoint!
In order to work with LINQ in SharePoint 2010, we need use a tool called SPMetal.exe which resides in the 14bin folder. This tool is used to generate some entity classes which Visual Studio 2010 can use to get IntelliSense, and allows for LINQ-based queries to be performed on your lists.
Noteworthy:
- LINQ to SharePoint queries are translated to proper CAML queries
- CAML queries are in turn later translated to SQL queries
SPMetal.exe
Using the tool called SPMetal, we generate our entity-classes that are needed to perform these object oriented queries toward our SharePoint server.
These are the required steps to get hooked up:
- Launch a cmd-window and navigate to C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14bin
- Run the following command to utilize the SPMetal.exe tool with the following syntax:
- Now navigate to C: (or wherever you chose to output your file) and make sure the file has been generated:
- Open up the file and take a look at the content that SPMetal now have provided us with:
Note that the class name is now MyEntitiesDataContext. It’s based on the name you specify as your code file in the SPMetal.exe command line tool.If you were to use /code:C:Awesome.cs instead, it would generate a class called AwesomeDataContext.
With that done – all we need to do is import it to one of our projects and use it!
Visual Studio 2010 – Let’s create a sample Web Part that utilizes LINQ to SharePoint
In this sample I will create a simple Web Part that will use LINQ to SharePoint syntax to fetch some information from the Announcements list. A basic sample I use in my training classes as well, and should be fairly easy to grasp!
- Create a new project (I’m going to create a new Visual Web Part project)
- Import your DataContext-file by choosing your Project -> Add -> Existing Item:
- Specify your file (mine is called MyEntities.cs):
- Make sure it’s properly placed in your project structure – then we’re good to go:
Alright – that’s easy enough. Thus far we have created an entity file using SPMetal.exe and now we have successfully imported it into our project.
Add proper references
Now in order to use LINQ to SharePoint, you also need to reference the Microsoft.SharePoint.Linq assembly. Point to references, right-click and choose "Add Reference" and select the Microsoft.SharePoint.Linq.dll file:
In your code, reference the assemblies:
Ready to code?
What you should’ve done up until now is this:
- Generate your entities using the SPMetal.exe tool
- Reference the newly created file from your SharePoint project
- Make sure you’re using the proper references for System.Linq and Microsoft.SharePoint.Linq
- Be ready to code
Code!
In my example I will have a Visual Web Part that will use LINQ to SharePoint to fetch all Announcements from my Announcement-list and work with those results. If you want to see the entire project, look at the bottom of this article where you can download it.
IntelliSense!
While you code your queries using LINQ to SharePoint, you will now have access to IntelliSense, which you did not have with CAML queries:
I’m going to leave it at that – very (very) easy to get started with LINQ to SharePoint, and all you really need to know is to start using the SPMetal tool to generate your entity classes and hook’em up with Visual Studio to start coding.
Summary & Download
As you can see, there’s not a lot of things you need to do in order to work with LINQ in your SharePoint applications with your SharePoint-data.
I’ve been pinged plenty of times on how you can get started with this, and there you have it. More in-depth articles to come later – this is just to get your wagon rolling!
To download the sample project, click here: [Download]
Enjoy!
- Posted in Technical
- 36 Comments
- Tags: How-To, LINQ, SharePoint, SharePoint 2010, SPF, SPS
SP 2010: Programmatically work with External Lists (BCS) using the Client Object Model
January 21st, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
Article 3 in the small BCS-series:
1. SP 2010: Getting started with the Business Connectivity Services (BCS)
2. SP 2010: Programmatically work with External Lists (BCS) in SharePoint 2010
3. SP 2010: Programmatically work with External Lists (BCS) using the Client Object Model
In my previous article in the series, I talked about how easy it is to fetch information using the standard SharePoint server API-approach. In this article I will talk about how you can access data in your BCS data source, by utilizing the Client Object Model.
Client Object Model code to read from the external list
Just like I described in my previous article, you now have the awesome ability to work with data in your External Lists (connected to a data source using BCS) – namely, you can use the standard SharePoint APIs.
Since I’ve shown you how you can do this using the Server Object Model, I thought I could take another spin at it and show you the code for doing basically the same with the Client Object Model.
The underlying data
As with my previous article, I’m still using the same data source as I set up in my first article – the "ProductList" table in my SQL Server database called "Zimmergren_DB"
As seen in the SQL Server Management Studio: ![]()
Let’s fetch the data using a Windows Forms application that utilizes the Client Object Model!
I’ve designed a Windows Forms application to utilize the .NET Client Object model (in contrary to using the Silverlight client object model or JavaScript client object model).
When you click the fancy button called "Get External Data", it will use the Client Object Model to fetch the records from the external list (from the SQL server) and display them in a DataGridView. Nothing fancy.
The code!
With no further delays or chit-chat, here’s the simple code!
// Define the Client Context (as defined in your textbox)
SP.ClientContext context = new SP.ClientContext(tbSite.Text);
SP.Web site = context.Web;var ProductList = site.Lists.GetByTitle(tbList.Text);
SP.CamlQuery camlQueryAwesomeness = new SP.CamlQuery();
IQueryable<SP.ListItem> productItems =
ProductList.GetItems(camlQueryAwesomeness);IEnumerable<SP.ListItem> externalList =
context.LoadQuery(productItems);// This is where we actually execute the request against the server!
context.ExecuteQuery();// Retrieve the products from the product list using some fancy LINQ
var productListData = from product in externalList
select new
{
// We’re never pointing to the field at the 0-index
// because it’s used by the BDC Identity itself. Hence our elements start at 1.
ProductID = product.FieldValues.ElementAt(1).Value.ToString(),
ProductName = product.FieldValues.ElementAt(2).Value.ToString(),
ProductDescription = product.FieldValues.ElementAt(3).Value.ToString()
};// Simply clear the rows and columns of the GridView
gvProducts.Rows.Clear();
gvProducts.Columns.Clear();// Add the columns we need (ProductID, Name, Description)
gvProducts.Columns.Add("ProductID", "ProductID");
gvProducts.Columns.Add("Name", "Product Name");
gvProducts.Columns.Add("Description", "Product Description");
foreach (var product in productListData)
{
// For each product in the list, add a new row to the GridView
gvProducts.Rows.Add(
product.ProductID,
product.ProductName,
product.ProductDescription
);
}
References and recommended reading
- Getting Started with the Client Object Model in SharePoint 2010
- Getting Started with Business Connectivity Services in SharePoint 2010
Summary & Download
At this point, I’ve showed you three short articles in which I describe how you can set up a Business Connectivity Services data source – then utilize the Server OM or Client OM to fetch information from that external data storage.
Worth to note is that this is still a Beta product, which of course means that it may differ in functionality and performance in comparison with the final (RTM) version of SharePoint 2010.
Download the complete Visual Studio 2010 project here: [ Zimmergren.SP2010.ClientOM.BCS.zip ]
- Posted in Technical
- 6 Comments
- Tags: BCS, Client Object Model, SharePoint, SharePoint 2010, SPF, SPS
SP 2010: Programmatically work with External Lists (BCS) in SharePoint 2010
January 19th, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
Article 2 in the small BCS-series:
1. SP 2010: Getting started with the Business Connectivity Services (BCS)
2. SP 2010: Programmatically work with External Lists (BCS) in SharePoint 2010
3. SP 2010: Programmatically work with External Lists (BCS) using the Client Object Model
In my previous article I talked about how you can set up a simple BCS configuration to fetch and work with external data in SharePoint 2010. In this article I will talk about how you can utilize the SharePoint 2010 object model to work with that external data, directly from the SharePoint API. It’s all really simple!
Working with data in an External List using the SharePoint Object Model
The code in this sample doesn’t really differ from the way you fetch information from any other list in SharePoint (2007 or 2010). This – of course – is very welcomed news, as we do not need to learn any new frameworks or tools to work with the data in our external lists. It simply works as any other SPList, basically.
Retrieving external data, made simple:
When fetching items from an external list, you can simply do that by utilizing the good-old SPList object. We do not need to work with any other types of namespaces or frameworks in order to do this.
In my SQL Server I’ve got a table called “ProductList“.
This list is filled with the following data:
![]()
Fetching some items from the external list, and displaying them in a console app:
// Product List is my external list, that is working with data in the SQL Server!
SPList list = web.Lists["Product List"];SPQuery q = new SPQuery();
q.Query =
“<Where><IsNotNull><FieldRef Name=’ProductID’ /></IsNotNull></Where>”;
q.RowLimit = 100;SPListItemCollection col = list.GetItems(q);
foreach (SPListItem item in col)
Console.WriteLine(item["Name"].ToString());
This will render the following result (fetched from the database):
The things you see in the console windows is fetched straight from the SQL Server (using a BCS connection through the External List).
Writing data to the External List (hence, writing to the SQL Server)
Seriously, this is way too easy as well…
// Get the external list
SPList list = web.Lists["Product List"];// Use the traditional approach to create SPListItems and hook it up with the list
SPListItem item = list.Items.Add();
item["Name"] = “Sample Product Wohoo“;
item["Description"] = “Sample Description Wohoo“;
item.Update();
Upon running this code in your SharePoint application, it will create the SPListItem object and add a Name and Description. When you hit .Update() it will push this data through the data source connection, to your SQL server.
Here’s what the updated data looks like:
We’re running a Beta-product!
As you can imagine, there’s a ton of new cool things to work with in SharePoint 2010 – where the BCS is one. This article discuss the very basics of how you can retrieve information from these lists using the normal API-approach.
At the time of this writing (during Public Beta) there isn’t any measures on performance and what impact it has on the server in comparison to alternative ways to fetch and work with the data.
As time goes on, there will be probably be some new information on this – I’ll keep you posted when I know more.
Summary
As you can see, working with external data from the SharePoint API isn’t very hard to do. What you need to make sure is to have an external list set up somewhere (see this article for how you can do that) and then you can simply use the normal SPList object from the SharePoint object model to work with the external list and it’s external data from the SQL server (in my case).
So if you haven’t already: Get on the SharePoint 2010 wagon and enjoy the ride!
- Posted in Technical
- 28 Comments
- Tags: BCS, External List, SharePoint, SharePoint 2010, SPF, SPS
SP 2010: Getting started with Business Connectivity Services (BCS) in SharePoint 2010
January 18th, 2010 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
Article 1 in the small BCS-series:
1. SP 2010: Getting started with the Business Connectivity Services (BCS)
2. SP 2010: Programmatically work with External Lists (BCS) in SharePoint 2010
3. SP 2010: Programmatically work with External Lists (BCS) using the Client Object Model
BCS in SharePoint 2010 is an awesome refinement of the Business Data Catalog from MOSS 2007. With BCS – or Business Connectivity Services – you get the possibility to connect external data and work with it from SharePoint.
In this article I will not cover the basics of what BCS is all about (MSDN/TechNet does this very well) – I will rather give you a walkthrough of how you can setup a BCS connection to an external database, and then work with this information directly from a SharePoint list – without the user actually knowing anything about the connection to the database.
BCS Poster: Business Connectivity Services Poster
BCS Team Blog: http://blogs.msdn.com/bcs/
A sample SQL database
I’ll just show you how my sample database is set up – simply create a new database in your SQL Server and have it filled with some example data. In my case, this is the data in my SQL database, called Zimmergren_DB:
In this sample database, I’ve added a table called ProductList which in theory will represent some products in this database, like this:
I’m filling the database with some sample data, so we will be familiar with this data when we later watch this information from SharePoint:
Alright – we have some sample data in our SQL Server. Nothing fancy, just some very simple data. Great, let’s get going with the fun stuff!
Creating an external content type
The most effective and easy way to set up a simple BCS connection, is to use SharePoint Designer 2010. You heard me, we can now get up and running with BCS by using SPD instead of modeling complex ADF files and things like that.
In order to do this, we need to create a new External Content Type!
Here’s how do create our External Content Type and hook it up with our database, step by step:
- Open the site you want to work with using SharePoint Designer 2010
- Select "External Content Types" in the left hand navigation:
Loading this page might take some time, be patient! - Click to create a new External Content Type like this:
- Click the link that reads: "Click here to discover external data sources and define operations":
- Click "Add Connection"
- Select "SQL Server" as your Data Source Type:
- Enter the details about your connection to your SQL Server:
- When the connection is made, your Data Source Explorer will be filled with the database you have specified. Now choose the table you want to work with, and right-click and select "Create All Operations":
You’ll be presented with a wizard-like dialog where you can specify the operations, elements and other properties for your BCS connection.
- Click "Next" to get to the Parameters page
- Select the field that you want to act as an Identifier. In my case I’ve selected my ProductID just to get on with it:
- Click "Finish"
- You’ll be presented with a list of operations that your External Content Type can do, like this:
That’s it. A few points, a few clicks – and you’re done. Let’s create an external list (using the Browser to show how simple it is..) and hook up our external content type with it!
Creating an external list
There’s a few ways to create an external list in SharePoint 2010. We will create it using the Browser UI to show you how simple it can be.
- Open your site and choose Site Actions - More Options…
- Select the External List template, and click Create
- Enter a name for your list, e.g. Product List
- You’ll see a field in this list called External Content Type, click the browse-button beside it:
What is really awesome here, is that you’re now presented with a dialog where you simply can choose the data source for this list. That means, you’ll select the data source you’ve created (mine is called Zimmergren_DB). Then your list will automatically work against the SQL database, but still have the look and feel of a SharePoint 2010 list.
- Select your data source and click OK:
- Now simply click the button called Create:
Would you look at that! You’re now working with external data, from your (what looks to be) normal SharePoint list! This is brilliant!
You now have the ability to create new items, update existing items, delete items and do all your normal CRUD-operations (CRUD = Create, Read, Update, Delete) straight from the SharePoint 2010 list.
Proof of concept – Adding a new product
Let’s just for the fun of it add a new product called "Awesome Product 1.0" like the following screenshot:
Now go to your SQL Server and see the changes take effect immediately. The data is NOT stored in SharePoint, it’s stored in your SQL Database.
This is what my table now looks like in the SQL Server, after adding a new item in the SharePoint list:
Summary
With a few points, followed by a few clicks – you’ve set up your external data connection. Basically it’s that simple.
Of course there’s a lot of things to consider when doing these configurations – and you might not want to auto-generate the CRUD-operations, but rather create them one by one and specify more fine-grained permissions etc.
This is merely a sample to show you how easy it is to actually get up and running with the SharePoint 2010 Business Connectivity Services (BCS) and work with external data!
Enjoy
- Posted in Technical
- 17 Comments
- Tags: BCS, How-To, SharePoint, SharePoint 2010, SPF, SPS
SP 2010: Presentations from SharePoint & Exchange Forum in Sweden
December 4th, 2009 by Tobias Zimmergren
Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren
Introduction
At the SEF 2009 Conference in Sweden I delivered a session about SharePoint 2010 development. The sessions from SEF are now available for download from the SEF web site.
Unfortunately the presentation I did was required to be in Swedish, and I haven’t done any translation to English for this particular presentation.
Download sessions from SEF
My session on SharePoint 2010 Development Introduction:
Tobias Zimmergren – SharePoint 2010 Development Introduction
Download all other presentations from http://www.seforum.se/Pages/200910362748747.aspx, including great speakers like:
- Eric Schupps
- Göran Husman
- Joel Oleson
- Penny Coventry
- Steve Smith
- Todd Klindt
- Wictor Wilén
- and more…
Enjoy!
- Posted in Misc
- No Comments
- Tags: Conference, Downloads, SEF, SharePoint, SharePoint 2010, SPF, SPS

