Central Administration ->Manage Servers in this farm
Unabo Blog
Thursday, April 21, 2011
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.
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.
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
This can be done using class:
SPWebConfigModification modification
It has properties such as:
modification.Value
modification.Value
modification.Owner
modification.Sequence
modification.Type
and for adding/removing:
pWeb.Site.WebApplication.WebConfigModifications.Add(modification);
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)
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) {
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
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
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
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)
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.
And you can see what the current installation is.
Subscribe to:
Posts (Atom)