Thursday, April 21, 2011

View SharePoint 2010 services running on servers in the farm

Central Administration ->Manage Servers in this farm

The SPMetal Tool

SPMetal is a command line tool that generates code that is an alternative to the SharePoint object model. By default, the tool is located at
 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN.
Simply point it at a SharePoint team site and the resulting code file will contain strongly typed entity classes for all of the site’s lists and libraries as they are configured at that moment in time. This code is often easier to use than the SharePoint object model equivalents. The best example of this is actually the main task our web part will perform—querying for data. Using the SharePoint object model, you could issue a query for specific items of a list using an XML-formatted CAML query. Notice that the query is just in the form of a string with no IntelliSense provided for structure, field names, or possible values.
SPList list = m_web.Lists["Issues"];
SPQuery query = New SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Category'/><Value
Type='CHOICE'>Hardware</Value></Eq></Where>";
SPListItemCollection items = list.GetItems(query);

Instead, the entity classes created by SPMetal support LINQ.
using (EntitiesDataContext dc = new EntitiesDataContext(webUrl))
{
var q = from issue in dc.Issues where issue.Category == Category.Hardware
select issue.Title;
A developer would typically use SPMetal during the coding phase, running the tool and adding the resulting file to his Visual Studio project. To run the tool, launch a command window and type a command similar to
SPMetal /web:http://edhild3/sites/dynppt /code:Entities.cs /language:csharp.
In this command we have specified three parameters. The first, web, specifies the site to use as the source. The generated code file will contain classes for working against a similarly structured site. In this case, we chose our team site where we created the Issues list. The second parameter, code, specifies the name for the file you want the generated code to be placed in. This file will be placed in the same directory as the SPMetal tool. Once you have it, copy and add it to your solution. The last parameter, language, specifies the .NET language you want the generated code to be in. There are many more parameters to this file and if you are going to be doing a lot of coding against SharePoint data sources.

Note It is important to realize that this code runs in the context of the developer running the command unless
another user is specified as a parameter. Since SharePoint security trims the data to which a user has access,
make sure the user running this tool actually has access to the data you are planning to code against

Programmatically add/remove SharePoint Changes in web.config

New entries can be added to Sharepoint web.config programmatically. Also the changes can be tracked by owner or tagged. So later all the changes can be removed also.
This can be done using class:
SPWebConfigModification modification
It has properties such as:
modification.Value
modification.Owner
modification.Sequence
modification.Type
and for adding/removing:
pWeb.Site.WebApplication.WebConfigModifications.Add(modification);
pWeb.Site.WebApplication.WebConfigModifications.Remove(modification);

Remove config entries by owner:
protected static void RemoveConfigEntries(SPWebApplication webApplication, string owner)
{
            Collection<SPWebConfigModification> oCollection = webApplication.WebConfigModifications;
            int iStartCount = oCollection.Count;
            for (int c = iStartCount - 1; c >= 0; c--)
            {
                //get all config changes in a collection
                SPWebConfigModification oModification = oCollection[c];

                if (oModification.Owner.Contains(owner))
                    oCollection.Remove(oModification);

            }

            //update only when we actually remove some entries
            if (iStartCount > oCollection.Count)
            {
                webApplication.Update();
                SPFarm.Local.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            }
}

Or On Feature Deactivation: (From book Pro Sharepoint 2010 Solution Dev_Office pp. 254)
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {
SPWebApplication currentWebApp = (SPWebApplication)properties.Feature.Parent;
Collection<SPWebConfigModification> modificationCollection = currentWebApp.WebConfigModifications;
Collection<SPWebConfigModification> removeCollection = new Collection<SPWebConfigModification>();
int count = modificationCollection.Count;
for (int i = 0; i < count; i++)
{
SPWebConfigModification modification = modificationCollection[i];
if (modification.Owner == "SiteProvisionFeature")
{
  // collect modifications to delete
  removeCollection.Add(modification);
}
}
// now delete the modifications from the web application
if (removeCollection.Count > 0)
{
foreach (SPWebConfigModification modificationItem in removeCollection)
{
  currentWebApp.WebConfigModifications.Remove(modificationItem);
}
// Commit modification removals to the specified web application
currentWebApp.Update();
// Push modifications through the farm
currentWebApp.WebService.ApplyWebConfigModifications();
}
}


SharePoint timer job (owstimer.exe) restart

After redeploying an application that uses timer job services, the job needs to be restarted.
net stop "Windows SharePoint Services Timer"
net start "Windows SharePoint Services Timer"
or alternatively use
net stop sptimerv3
net start sptimerv3

SharePoint Dispose Checker Tool

Use this tool to check if objects are disposed in Sharepoint.
Tool can be downloaded here:
http://archive.msdn.microsoft.com/SPDisposeCheck

Index a file share with SharePoint 2010

Give SP search account read rights for the shared folder. To find which user it is:
Central Administration->Application Management->Manage Service Applications->Search Service Application
And look under System Status for:
example:
Default content access account CONTOSO\sp_service
Next add your share to the content sources:
Central Administration->Application Management->Manage Service Applications->Search Service Application->Content Sources->New Content Source
And choose FileShares (fill other values)

Check Sharepoint 2010 version (Enterprise or Standard)

Central Administration->Upgrade and migration->Convert Farm License Type
And you can see what the current installation is.

Sharepoint Query Suggestion (seed)

When you type something in SP search you want suggestions to appear. To add such suggestion execute script. This seeds word “Sharepoint”.
$sa=Get-SPEnterpriseSearchServiceApplication
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $sa -Language EN-US –Type QuerySuggestionAlwaysSuggest -Name "SharePoint"
Start-SPTimerJob -Identity "Prepare Query Suggestions"

Hide/Show List Field on the New/Edit Form (Moss 2007)

Use Sharepoint Tips Utility Pack or SPListDisplaySetting Feature.
More about this can be found here: http://patrikluca.blogspot.com/2008/10/customize-sharepoint-list-form.html

Sharepoint 2010 Manager

The SharePoint Manager 2010 is a SharePoint object model explorer. It enables you to browse every site on the local farm and view every property. It also enables you to change the properties.
http://spm.codeplex.com/

Enable Publishing on SharePoint site collection

This is needed in order to change master page.
First activate SiteSettings-> Site Collection Features ->Sharepoint Server Publishing Infrastructure
Second activate SiteSettings->Manage site features->Sharepoint Server Publishing
Now under Site Settings (Look and Feel) you should see Master page link.

View SharePoint TermSet hidden table

When termssets are created the items are added to the hidden list that can be viewed:
http://{your
site url}/Lists/TaxonomyHiddenList/AllItems.aspx
Note: Termsets survive deletion of site collection but this list is cleared.

Rename SharePoint wsp package

Change the name in Package.package file.

Deploy bug in Visual Studio when run with F5

Error occurred in deployment step 'Activate Features': The field with Id {fa9b24b2-a930-4292-9ccb-b2e4b99c0ac8} defined in feature {549e220b-ab9e-4890-aa80-0ded9435f1b8} was found in the current site collection or in a sub-site.
Even though id is unique.
Just kill the process:  wssphost4.exe

Unable to connect to SharePoint site from Visual Studio 2010

You may get message like:
Cannot connect to the SharePoint site: http://localhost/. Make sure that this is a valid URL and the SharePoint site is running on the local computer …
You need to add your currently logged user (under which you run Visual Studio) to the SQL Server users and map it as owner for following databases (obs names maybe not exact):
SharePoint_Config
SharePoint_AdminContent_[guid]
SharePoint Site Content DB

Create wsp file in SharePoint 2010

Right click on project->Package

Id for SharePoint built-in columns

You can find the IDs for built-in columns in the fieldswss.xml file, which is located on the following path: %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\FEATURES\fields
These IDs are needed when you create content type and need to reference fields with <FieldRef  ID=””>

SharePoint Taxonomy and Metadata. What is that?

Taxonomy=Categorization
Metadata is data about data. A list of possible metadata values is the simplest form of a controlled vocabulary. The purpose of a controlled vocabulary is to prevent authors from defining meaningless metadata values, from offering too specific or too general metadata values, and to prevent different authors from misspelling and choosing slightly different forms of the same metadata value.
Taxonomy is a collection of controlled vocabulary terms organized into a hierarchical structure. Each term in taxonomy is in one or more parent/child (broader/narrower) relationships to other terms in the taxonomy.
SharePoint Server 2010 supports the following types of controlled vocabularies:
Simple list — this is something that was also available in SharePoint 2007, using a simple lookup list.
Synonyms — It is possible to define synonyms, abbreviations, and preferred terms using the new managed metadata infrastructure in SharePoint 2010.
Taxonomy — Support is provided through the managed metadata infrastructure in SharePoint 2010. In SharePoint Server 2007, taxonomy was implemented through building a hierarchy of sites and subsites that introduced a number of drawbacks. SharePoint 2010 has a built-in hierarchical field control.
Thesaurus and ontology

Folksonomy is a term used to describe the result of adding metadata in the form of open-ended labels called tags by a large group of people. Folksonomy is a form of taxonomy that is built by the end users themselves.

Turn on Developer Dashboard in SharePoint

STSADM –o setproperty –pn developer-dashboard –pv On
To disable change On to Off. Another option is OnDemand.

Override Global.asax in SharePoint

Add your new Global.cs in the sharepoint project. Change Global.asax in your virtual dir so it points to this new class that extends original Sharepoint Global.asax. See the note for the class attached.
Note that the new Global.asax must have full assembly reference in order to search for assembly in GAC. Otherwise it would look for it in virturaldir/bin folder.
In web.config you must have:
under <httpModules>

<add name="Session" type="System.Web.SessionState.SessionStateModule" />

using System;
using System.Web;
namespace CMan.Api.Common{
/**
*  Extension for Global.asax
*  Global.asax in virtual dir for sharepoint application should have following code:
*  <%@ Assembly Name="CMan, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b86b954ddd3528c3"%>
*  <%@ Import Namespace="CMan.Api.Common" %>
*  <%@ Application Language="C#" Inherits="CMan.Api.Common.Global" %>
*/
public partial class Global : Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication
 {
   public Global() { }
   protected void Application_EndRequest(Object sender, EventArgs e)
   {
    //ADD YOUR CODE
   }
   //ADD OTHER GLOBAL.ASAX methods/events you need
Application_AcquireRequestState
Application_AuthenticateRequest
Application_AuthorizeRequest
Application_BeginRequest
Application_Disposed
Application_EndRequest
Application_Error 
Application_PostAcquireRequestState
Application_PostAuthenticateRequest
Application_PostAuthorizeRequest
Application_PostMapRequestHandler
Application_PostReleaseRequestState
Application_PostRequestHandlerExecute
Application_PostResolveRequestCache
Application_PostUpdateRequestCache
Application_PreRequestHandlerExecute
Application_PreSendRequestContent
Application_PreSendRequestHeaders
Application_ReleaseRequestState
Application_ResolveRequestCache
Application_UpdateRequestCache
Application_Init
Application_Start
Application_End
  }
 }
}

New Feature Installation - Moss 2007

Change version in DeploymentData.xml
Rebuild
Redeploy
Go to web Site:   Site Actions->Site Settings->Modify All Site Settings->Site Collection Features
Find your feature
Deactivate
Activate (again)

VMWare Change amount of RAM

You need to shut down your machine in order to change amount of RAM. (Not Save State…)

VMWare CTRL+ALT+DEL

Use: CTRL+ALT+INS

Edit group policies in Windows 2008 (Using Local Group Policy Editor)

Go to Run and type gpedit.msc & Click OK
Expand Local Computer Policy, expand Computer Configuration, expand Windows Settings, and then expand Security Settings.
Here you can find different security settings.

Visual Studio 2010 TFS create version label

Team Explorer->Double click on Source Control (for the project)
It opens a working area divided in Folders tree and separate list of folders
Right click on the project you want (under Folders i.e Source Control Explorer)->Apply Label
Now to view your labels:
Right click the project at the same place->View history->Click labels in the toolbar at the top
.

Visual Studio 2010 - Remove project from Recant Projects List

Right click on the project in the Recant Projects->Remove

Visual Studio - Track opened file in Solution Explorer

When a file is opened in Visual Studio, it is nice to have it selected in Solution Explorer.
Well that is easy done:
Go to:
Options->Projects and Solutions->Track active item in solution explorer


Now the as you switch between opened tabs (files) Visual Studio selects current file in Solution Explorer.

Run CMD as Administrator

Click Start and type cmd. Press CTRL+SHIFT+ENTER (In opposite to just ENTER)

Run application with Administrator privileges

Go to start and type cmd to open windows console.
Use command runas:
runas /user:yourdomain\Administrator “copied path to the exe file”
When asked enter password for .


Example to run SQL Server Manager as Administrator user:
runas /user:CONTOSO\Administrator “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”

What is this blog about?

IT Tips

For several months I started to write my notes with different topics within IT.
From the beginning it was my own reminder. You have probably experienced it. You have a problem in front of you, and you know that you had the similar problem but you don't remember how you solved it.
Well this was my list of notes to remember. But the list grew and I realized it would be nice if some of these notes could help others.
A lot of posts will be related to Microsoft .NET and SharePoint 2010 since those are my particular areas of interest.
Well, that's why I write this blog.