Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

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 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

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.

Rename SharePoint wsp package

Change the name in Package.package file.

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

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=””>

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)