Archive

Archive for March, 2012

How to Display Presence Indicator in Custom Webparts

March 21, 2012 4 comments

SharePoint Server 2010 gives the ability to identify the status of co-works or site members if they online , busy, or away by integrating with Presence Indicator Information concept.  smart tag appears next to the user name to display the user status .

The key piece of information to make the presence work is the user’s SIP Address which is basically their IM address (This is not always the same as email address). When a users is either added to a site in SharePoint or has their profile imported, the SIP Address will be drawn from Active Directory which is where OCS stores it and placed into the SIP address field in either the user’s profile which will in turn synchronise down to the site’s local ‘User Information’ page.

The pawn is basically an IMG element which has “IMNRC(‘[user’s SIP Address]’)” for the onload function. This will user client-side script that is part of Office to load the presence pawn on the page.

The hyperlink on the user’s name is just a simple A element which redirects to “/_layouts/userdisp.aspx?ID=[User’s local user information list item ID]”. This userdisp.aspx page will then redirect to the user’s main profile page if they have a profile, otherwise it will display the basic information that the user information list item stores.

How to get the SIP Address?

Hopefully you’ll have spotted by now that the presence pawn relies on the user’s SIP Address. To get the SIP address you need to get the user’s User Information list item from the local site’s (SPWeb to be precise) SiteUserInfoList which is basically a hiddenSPList that is in every web.

There is a handy property to get you to this list called ‘SPWeb.SiteUserInfoList’. This will give you an SPList object which represents the User Information list. From here you just need to find the item that represents the user you wish to display. The best way to do this is via their ID (the ID of the list item) by calling SPWeb.SiteUserInfoList.GetItemById([int User’s ID]), however you can also use a variety of other methods which use SPQuery or match a specific field to a value.

In most scenarios, you may be getting the user information from a SPFieldUserValueCollection which is basically the field type that is used for ‘Person’ fields. If this is the case you can use SPFieldUserValue.LookupId to get the ID of the user’s User Information list item.

Putting it all together

This code sample is a method that accepts an SPFieldUserValueCollection and SPSite as inputs and returns back the HTML for displaying each entry in the SPFieldUserValueCollection with the presence pawn and link to their profile. This will be presented exactly as SharePoint presents it by default. This could be extended to use ALT tags in the IMG and A elements.

I then simply add the HTML to an HtmlWriter or in my case a TableCell.Text property to display it on screen.

I’ve take a few extra steps here by adding ID and alt tags and trying to make the code readable, but I’m sure you get the idea:

public string GetPresenceHTMLFromUVC(SPSite thisSite, SPFieldUserValueCollection uvc)
{
StringBuilder html = new StringBuilder(“”);
using (SPWeb thisWeb = thisSite.RootWeb)
{
foreach (SPFieldUserValue uv in uvc)
{
string sipAddress = “”;
//Get the sip address if it exists
SPListItem user = thisWeb.SiteUserInfoList.GetItemById(uv.LookupId);
if (user[“SipAddress”] != null)
{
sipAddress = user[“SipAddress”].ToString();
}
//construct the html for this user and add to overall html
html.Append(String.Concat(
“<div id\”PresenceLink”
, sipAddress
, “\”>”
, “<img border=\”0\” height=\”12\” src=\”/_layouts/images/imnhdr.gif\” onload=\”IMNRC(‘”
, sipAddress
, “‘)\” ShowOfflinePawn=\”1\” style=\”padding-right: 3px;\” id=\”PresencePawn”
, sipAddress
, “\” alt=\”presence pawn for ”
, sipAddress
, “\”/>”
, “<a href=\””
, thisWeb.Url
, “/_layouts/userdisp.aspx?ID=”
, uv.LookupId
, “\” id=\”ProfileLink”
, sipAddress
, “\”>”
, uv.User.Name
, “</a></div>”
));
}
}
return html.ToString();
}

 

references:-

http://blogs.msdn.com/b/uksharepoint/archive/2010/05/07/office-communicator-integration-presence-in-a-custom-webpart-for-sharepoint-2010.aspx

http://blog.sharepointsite.co.uk/2012/02/status-indicator-not-working.html

 

 

SharePoint 2010 : Retrieve User Profile Properties Programmatically

March 17, 2012 Leave a comment

To display the user profile properties that exist on the server Also add references to the following in your Microsoft Visual Studio project:

  • Microsoft.Office.Server
  • Microsoft.Office.Server.UserProfiles
  • Microsoft.SharePoint
  • System.Webhere, in below example, we need to check if  propertyName exits in user profile properties store or not.

    private bool CheckIFPropertyExist(string propertyName, string siteName)
    {
    using (SPSite currentSite = new SPSite(siteName))
    {
    SPServiceContext context = SPServiceContext.GetContext(currentSite);
    ProfileSubtypeManager profileMgr = ProfileSubtypeManager.Get(context);
    ProfileSubtype profileSubType = profileMgr.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
    ProfileSubtypePropertyManager profilePropertyMgr = profileSubType.Properties;

    foreach (ProfileSubtypeProperty profileSubtypeProperty in profilePropertyMgr.PropertiesWithSection)
    {
    if (profileSubtypeProperty.Name != propertyName)
    {
    return false;
    }
    }
    return true;

    }

    }

Changing namespace in Visual Studio 2010 might break a SharePoint 2010 webpart project

March 17, 2012 Leave a comment

I was creating a SharePoint 2010 project in Visual Studio 2010. I’ve selected the Empty Project and then Add New Item and selected the Webpart item (not the Visual Webpart). After doing some coding, for some reason I’ve decided to change the original namespace that Visual Studio had created for me on the webpart class (.cs file). Then I did some more coding and time to test it. I right click on the project name and select Deploy (I love this new feature in VS2010). Everything goes smooth, package is deployed and everything seems fine. So I go to my SharePoint site, Edit the page, Insert a Webpart, select my new custom webpart and when I hit the Add button, for my surprise I got the error below.

And this is the second time around that this happened to me. The first time was a long time ago so I couldn’t remember why. Then it’s time to do some troubleshooting. I’ve verified that the .DLL file was in the GAC, I’ve checked the web.config file to make sure a <SafeControl> entry was created. Everything looks good. Then I check the webpart definintion file in the WebParts gallery and closely looking at the XML I’ve noticed that the namespace was not matching with my webpart class. The original namespace was still showing. So I went back to my Visual Studio project and I’ve opened the .webpart file (see below) that was created for me.

And for my surprise the original namespace was still showing up there. So if you change your namespace after you create a project in VS2010 make sure that in the .webpart file (see below) under the <Metadata> <type> elements, the name attribute has the correct namespace.

 

01 <?xml version="1.0" encoding="utf-8"?>
02 <webParts>
04 <metaData>
05 <type name="SP2010.WebParts.MembesListingWebPart.MembersListingWebPart, $SharePoint.Project.AssemblyFullName$" />
06 <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
07 </metaData>
08 <data>
09 <properties>
10 <property name="Title" type="string">Members Listing WebPart</property>
11 <property name="Description" type="string">This WebPart lists the members of a site</property>
12 </properties>
13 </data>
14 </webPart>
15 </webParts>

 

Another change you have to do and this one is a tricky one is on the Visual Studio 2010 SharePointProjectItem.spdata file. This is a file I believe Visual Studio uses internally to package and deploy the solution. But the catch is that it doesn’t show by default, so you have to click on the “Show All Files” button in the Solution Explorer and this file will show inside your WebPart folder (see below). Edit the file and change the Namespace attributes according to your new namespace.

Also, don’t forget in that if you change the namespace, in your project properties, make sure it’s reflected in the Default Namespace field in the Application tab of your Project properties (right-click your project name and select properties).

Hope this will help some people save some troubleshooting time !

references:-

http://socialsp.com/

How to block search engines from indexing your SharePoint Site

March 15, 2012 4 comments

If you want to block search engines from indexing your site you need to create a robots.txt file and place it in the root of your root site.

What is a Robots.txt

Robots.txt is a text (not html) file placed in the root of your site to tell search robots which pages should and should not be visited/indexed. It is not mandatory for search engines to adhere to the instructions found in the robots.txt but generally search engines obey what they are asked not to do.

It is important to note that a robots.txt does not completely prevent search engines from crawling your site (i.e. it is not a firewall) and the fact that you may have a robots.txt file on your site is something like putting a note “Please, do not enter” on your unlocked front door. Put simply, it will not prevent thieves from coming in but the good guys will not open to door and enter.

It goes without saying therefore, if you have sensitive data, you cannot rely 100% on a robots.txt to protect it from being indexed and displayed in search results.

The location of robots.txt is very important. It must be in the main directory because otherwise user agents (search engines) will not be able to find it. They do not search the whole site for a file named robots.txt. Instead, they look first in the main directory (i.e. http://www.sitename.com/robots.txt) and if they don’t find it there, they simply assume that this site does not have a robots.txt file and therefore they index everything they find along the way. So, if you don’t put robots.txt in the right place, don’t be surprised that search engines index your whole site.

Creating a Robots.txt

  1. Launch Notepad
  2. Put the following in your robots.txt file:

User-agent: *
Disallow: /

  1. Save the file as: robots.txt

Adding a robots.txt file to the root of your public anonymous SharePoint site.

  1. Open up your root site in SharePoint Designer.
  2. Double Click the folder All Files
  3. Drag and drop the newly created robots.txt to the All Files folder.
  4. Exit SharePoint Designer.

Alternatively you can create the robots.txt from within SharePoint Designer itself.

To ensure the file is accessible to search engines go to your site URL adding “/robots.txt” at the end.

Example: http://www.sitename.com/robots.txt

You should see the contents of your robots.txt file displayed in the browser.

refernces:-

http://www.agileit.com/Blog/Lists/Posts/Post.aspx?Id=5

http://sharepointingitout.blogspot.com/2011/06/sharepoint-2010-adding-robotstxt.html

http://blog.drisgill.com/2009/01/adding-robotstxt-to-sharepoint.html

SharePoint 2010 Services

March 14, 2012 Leave a comment

Visio Services and SharePoint 2010

March 13, 2012 1 comment

In SharePoint 2010, Microsoft has taken the Visio Services to the next level by allowing rendering of Visio diagrams and charts within the browser. Users can now use the out of the box Visio web parts to render the Visio diagrams and bring in the seamless integration of business intelligence between Visio, SharePoint and back end data.

Let me show you an example:

Lets create a simple Visio diagram which fetches values from external data:

 

This diagram is using the SupplyChain SQL database and the Suppliers table:

I can now save this as a Visio Web Diagram (.vdw) and upload to a document library in my Business Intelligence site.

Now, I can go to my dashboard and insert the Visio web diagram using the Visio Web Access web part.

This will add the Visio Web Access web part to the dashboard page where you can specify the Visio file to render:

Below is the rendered Visio web diagram in the web part:

 

You can see that the external data is also fetched in the diagram!

Notice there is also an option to enable refresh!

You can pan and also zoom into the diagram using the zooming controls (its very interactive!):

You can configure some of the default behaviour of the web part from its web part options pane:

The Real Deal

Lets go to SQL and change the Assembly Time value for the Bevel Assembly from 45 to 55

Lets go back to our dashboard page and refresh the Visio web diagram:

We now have the updated value!

Configuring Visio Services

The Visio Services is managed by the Visio Graphics Service service application (Central Administration | Application Management | Manage Service Applications)

references :

http://blogs.msdn.com/b/visio/archive/2009/10/20/announcing-sharepoint-2010-and-visio-services.aspx

http://www.chakkaradeep.com/post/SharePoint-2010-Visio-Services.aspx

http://www.wictorwilen.se/Post/Creating-SharePoint-2010-workflows-with-Visio-2010.aspx

Introduction to Client side programming in SharePoint 2010

March 13, 2012 8 comments

SharePoint 2010 provides 3 new client-side object models: Managed, Silverlight and JavaScript. It provides libraries for each and they are located in the below locations.

Managed Object Model
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.ClientRuntime.dll
ISAPI folder
Silverlight client object model
Microsoft.SharePoint.Client.Silverlight.dll
Microsoft.SharePoint.Client.Silverlight.Runtime.dll
LAYOUTS\ClientBin folder
JavaScript client object model
SP.js
LAYOUTS folder

Each client object model interacts with SharePoint through a Windows Communication Foundation (WCF)

service named Client.svc, which is located in the ISAPI directory. Every request sent as a single Extensible Markup Language (XML) request to the Client.svc service. The results of the server-side calls are then sent back to the calling client in the form of a JavaScript Object Notation (JSON) object.
Server object model
Managed Model
Silverlight Model
Javascript Model
SPContext
ClientContext
ClientContext
ClientContext
SPSite
Site
Site
Site
SPWeb
Web
Web
Web
SPList
List
List
List
SPListItem
ListItem
ListItem
ListItem
SPField
Field
Field
Field

SharePoint 2010: Ten points to pay attention for a good infrastructure

March 13, 2012 2 comments

#1 Limit your SQL

When you install SharePoint 2010 on a complete mode with a SQL SERVER 2008R2, there is an option on the properties of the server, that you can limit the RAM usage. If you don’t limit the usage, it will use 2.1 petabytes.

The default value for SQL Server 2008R2 Maximum Server Memory setting is 2,147,483,647 MB. Therefore, SQL Server will use all available memory for its own use.

1

 

 

#2 Use different users for your environment

When you will configure Web Applications, Service Applications … Do not forget to create for each of these Applications a user.

The main raison is that when this service or user will get an error it will be easy for us to know with service has failed. (EVENT VIEWER)

Second raison is that on IIS7, the application pool names are getting GUID. So we can have more information just on regarding the username:

1

 

If we had the same user for each service, we could never know which GUID was for witch Service.

(1 first) The e6266ed1faa2406cbae0bbbf33f6e4ba is my Access Service..

#3 Use a Warm up Script

Yes, everybody knows SharePoint is slow, and in many cases it’s extremely slow. But there are many solutions therefore. The best solution is to use a WARM UP script.

It will compile everything, and your SharePoint will be very faster.

Download link: http://www.gokanozcifci.be/subsite/warm-up-script-for-sharepoint-2010.html 1

Download link: http://spwakeup.codeplex.com/ 1

 

 

#4 Disable unused warnings on SharePoint

The SharePoint Health Analyzer detected a condition requiring your attention. Drives are at risk of running out of free space.

This is an example of a BETA warning on SharePoint; it can be disabled on Review Job Definitions. Do the same of each job that you think that’s unusual for you.

1

 

 

#5 SQL BROWSER

Start your SQL BROWSER service on services.msc on your SQL Server. It is a very useful tool that helps you to see each warning, error … on the SQL Server

It will show you more information about the login failure’s with an explicit SQL ID.

 

1

 

#6 Service Connections

When you will create a new WEB APPLICATION SharePoint will attach each service on your WEB APPLICATION. Even the one that you don’t need, so in place of using de “default” value use the custom value on Central Administration

1

 

#7 Made a SHORTCUT 14/

Made a Shortcut to the desktop of you 14 document and it will be easier to check your logs and many other things.

1

 

 

#8 DisableloopbackCheck

When you use the fully qualified domain name (FQDN) or a custom host header to browse a local Web site that is hosted on a computer that is running Microsoft Internet Information Services (IIS) 5.1 or a later version, you may receive an error message that resembles the following:

HTTP 401.1 – Unauthorized: Logon Failed

This issue occurs when the Web site uses Integrated Authentication and has a name that is mapped to the local loopback address.

Download Link: http://www.gokanozcifci.be/subsite/DisableLoopbackCheck.html 1

 

 

#9 Use a PowerShell Script for downloading prerequisites.

SharePoint prerequisites installer will install “everything” that he thinks that it will be ever used. But in many of cases it’s not true. Take this script modify it and download the applications that “you” need..

Download Link: http://www.gokanozcifci.be/subsite/download-prerequirements-sharepoint-2010-powershell.html 1

1

 

#10 don’t use port 80 for Central Administration

When you will install SharePoint Server/Foundation, it will ask to give a Port number for Central Administration; give everything but don’t give 80 (http protocol). So you can hide your Central administration from possible attacks. It will give a standard IIS page.

1

reference : http://www.gokanozcifci.be/subsite/points-to-pay-attention-for-sharepoint-2010.html

SharePoint 15 Technical Preview Managed Object Model SDK available for download

March 3, 2012 1 comment

This download contains the following developer documentation:

  • SharePoint 15 Technical Preview Managed Object Model SDK: This compiled help (.chm) file contains reference topics focusing only on types and members that are called by other Microsoft applications. This reference does not document the full SharePoint 15 managed object model. That documentation will accompany a later release of SharePoint 15.

While we make every effort to ensure the technical accuracy in this documentation, it is preliminary documentation and is subject to change.

You can download the SDK from the Download Center

Categories: SharePoint 15

“User modifications to the SharePoint content database” error message when you upgrade a SharePoint Server 2007 content database to SharePoint Server 2010

March 1, 2012 1 comment

The Pre-Upgrade Checker for Microsoft Office SharePoint Server 2007 is designed to verify that your existing installation of SharePoint 2007 is ready for the upgrade to SharePoint 2010.  It verifies that the OS is the correct version, that there are no orphan sites or sub-sites, it verifies the web config file, the SQL database version and a host of other items.

When going to run the Pre-Upgrade Checker included with SharePoint 2007, Service Pack 2, we got a nasty little surprise.  The Pre-Upgrade Checker told us that there was a problem with the database schema.  Uh-oh.

It returned a potential blocking issue that our SQL database schema had some serious user modifications.  It read, in part:

Potential Upgrade Blocking Issues
Issue : Content database with modified database schemas
User modifications to the SharePoint content database, including but not limited to table schemas, index, stored procedures, are not supported and will cause upgrade to future versions of SharePoint to fail.  The databases in the following list seem to have been modified from the original schema:
Data Source=SERVER\SHAREPOINT;Initial Catalog=Content_Database;Integrated Security=True;Enlist=False;Connect Timeout=15

That could be a problem.  We went to the logs and had a look:

[InvalidDatabaseSchema] [DEBUG] [6/14/2010 10:39:19 AM]: Checking schemas in content database Content_Database…
[DatabaseSchema] [ERROR] [6/14/2010 10:39:32 AM]: [Content_Database].[sysdiagrams] EXTRA Table
[DatabaseSchema] [ERROR] [6/14/2010 10:39:36 AM]: [Content_Database] NON EQUAL Property Tables
[SPObjectProcessor] [DEBUG] [6/14/2010 10:39:42 AM]: The rule failed.

It appeared as if there was an extra table inserted into the database, one that was not present in the original SharePoint database schema.  Somehow, there was a table calledsysdiagrams that was not created by SharePoint, and it was causing a mismatch with the Pre-Upgrade Checker.

Upon a little investigation within the SQL Server, the dbo.sysdiagrams table was located at Content_Database -> Tables -> System Tables.

How was the dbo.sysdiagrams table created?  A little bit of searching revealed the answer.  If someone clicks on the Database Diagrams within your database, it will immediate prompt you to create the necessary objects for for database diagramming.  Clicking “Yes” to this prompt will result in the creation of the dbo.sysdiagrams tables and some related stored procedures.  While these don’t pose any obvious risks to SharePoint as the diagrams relate only to the database, the Pre-Upgrade Checker will throw an error if they are present.

To correct the error, and allow the Pre-Upgrade Checker to run successfully, we performed the following:

  • We backed up the SharePoint_Content Database before making any changes.  This is critical in case something goes wrong.
  • I deleted the dbo.sysdiagrams table from Content_Database -> Tables -> System Tables
  • I deleted the following stored procedures from Content_Database –> Programmability -> Stored Procedures -> System Stored Procedures
  • sp_upgraddiagrams
  • sp_helpdiagrams
  • sp_helpdiagramdefinition
  • sp_creatediagram
  • sp_renamediagram
  • sp_alterdiagram
  • sp_dropdiagram

The screenshot  below illustrates these a little better.
stored_procs

After deleting the table and the stored procedures, we were able to run the SharePoint Pre-Upgrade Checker and our SharePoint site passed every check.

references:

http://support.microsoft.com/kb/982579

http://selfinflictedsharepoint.blogspot.com/2010/06/sharepoint-pre-upgrade-checker-fails.html