Archive

Archive for the ‘SharePoint Server 2010’ Category

Integrate MooTools FrameWork With SharePoint 2010

Here i’m talking about integrating MooTools FraweWork with Sharepoint 2010 , firstly let me describe and define what is Mootools FraweWork ??

MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API.

The Stats

MooTools Core
Library Size 64.3K
Features
License MIT
DOM Utilites yes
Animation yes
Event Handling yes
CSS3 Selectors yes (a subset)
Ajax yes
Native Extensions (excluding Element) about six dozen for Array, Object, String, Function, and Number
Inheritance Provided with Class constructor
Other Considerations
plug-ins Roughly 4 dozen official plug-ins available at mootools.net/more. Unofficial plugin directory at mootools.net/plugins.
Official UI library no

so we can do nice tasks with MooTools FrameWork, here going to display Create SharePoint 2010 web part using MooToolsEditable, The SharePoint 2010 web part should allow a user to add the web part to a page where a small html editor will appear.

The editor should be like the one on this page:

http://cheeaun.github.io/mooeditable/

but integrating SharePoint with Mootools framework will raise many issues, especially with Out of the Box Javascriopt files , Script Manager on MasterPage, and Microsoft Ajax .

one of the exception which you may face is ” sys.res.enumreservedname’ is null or not an object” , this is error occuered becuase of a conflict between ScriptManager in Sharepoint Master Page and MooTools Javascript files.

Through my research i found 2 steps i should to do in MooTools.Js to override all of the issues, as as the following

1- Everything is based on Type Class, Replace “Type” in JS File with “mooType”. don’t forget to rename the “this.Type” to “this.mooType” too, then do a search for “new Type(” and replace with “new mooType(“, then do a search for “Type.” and replace with “mooType.” .

2- Function.implement “hide: function(){” renamed to “hide2: function(){” and global replace “hide()” to “hide2()”

Attached here, updated Version 1.3 of MooTools.js File after above steps.

Next Article, will be an example with MooTools FrameWork

mootools-core.js (After Downloading The file, change the extension from JPG to JS)

References:

http://jqueryvsmootools.com/

https://mootools.lighthouseapp.com/projects/2706/tickets/1045-asp-net-bug

Creating Custom Profile Property in SharePoint Server 2010

March 31, 2013 Leave a comment

if you have requirements to create Custom Profile Property in SharePoint 2010

below function do That

private
void CreateCustomProperty(string profilePropertyText,SPSite siteColl)

{


SPSecurity.RunWithElevatedPrivileges(delegate()

{

siteColl.AllowUnsafeUpdates = true;

siteColl.OpenWeb().AllowUnsafeUpdates = true;


//SPContext.Current.Web.AllowUnsafeUpdates = true;


SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);


UserProfileConfigManager profileConfigManager = new
UserProfileConfigManager(serviceContext);


CorePropertyManager coreProperties = profileConfigManager.ProfilePropertyManager.GetCoreProperties();


try

{


List<string> MyCustomProperties = new
List<string>();

MyCustomProperties.Add(profilePropertyText);


ProfilePropertyManager propertyManager = profileConfigManager.ProfilePropertyManager;


foreach (string profileProperty in MyCustomProperties)

{


if (coreProperties.GetPropertyByName(profileProperty) == null)

{


CoreProperty propertyInstance = coreProperties.Create(false);

propertyInstance.Name = profileProperty.Replace(” “, string.Empty);

propertyInstance.Type = PropertyDataType.String;

propertyInstance.Length = 2000;


//propertyInstance.Separator = MultiValueSeparator.Semicolon;

propertyInstance.DisplayName = profileProperty;

propertyInstance.Description = profileProperty;

propertyInstance.IsAlias = false;

propertyInstance.IsSearchable = true;

propertyInstance.Commit();


ProfileTypePropertyManager profileTypePropertyMgr = propertyManager.GetProfileTypeProperties(ProfileType.User);


ProfileTypeProperty profileTypeProperty = profileTypePropertyMgr.Create(propertyInstance);

profileTypeProperty.IsVisibleOnViewer = true;

profileTypeProperty.IsVisibleOnEditor = true;

profileTypePropertyMgr.Add(profileTypeProperty);


ProfileSubtypeManager psm = ProfileSubtypeManager.Get(serviceContext);


ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));


ProfileSubtypePropertyManager pspm = ps.Properties;


ProfileSubtypeProperty psp = pspm.Create(profileTypeProperty);

psp.IsUserEditable = true;


//psp.Commit();

pspm.Add(psp);

}

}

siteColl.AllowUnsafeUpdates = false;


//SPContext.Current.Web.AllowUnsafeUpdates = false;

siteColl.OpenWeb().AllowUnsafeUpdates = true;

}


catch (DuplicateEntryException exception)

{

siteColl.AllowUnsafeUpdates = false;


SPContext.Current.Web.AllowUnsafeUpdates = false;

logMessage(exception.Message, EventLogEntryType.Error);

}

});

}

to check if specific Profile Property exist or not

private
bool CheckCustomPropertyExistance(string profileProperty, SPSite siteColl)

{


bool exist = false;


SPSecurity.RunWithElevatedPrivileges(delegate()

{


SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);


UserProfileConfigManager profileConfigManager = new
UserProfileConfigManager(serviceContext);


CorePropertyManager coreProperties = profileConfigManager.ProfilePropertyManager.GetCoreProperties();


try

{


if (coreProperties.GetPropertyByName(profileProperty) != null)

{

exist = true;

}

}


catch (DuplicateEntryException exception)

{

logMessage(exception.Message, EventLogEntryType.Error);

}

});


return exist;

}

Using List Picker Control in Custom WebPart Properties

March 31, 2013 2 comments

if you are developig custom webpart and one of the requirements is getting list title as webpart property. so, you can do that by just adding custom Property as text and the user write list title and you in code behind will handle and validate list title and check if this list already exist or not. Also if you want to query , add or update list in subsite , you will need to add relative path to the list. to override all of these , you can add Out of the Box List Picker, just you will develop custom toolpane for the list and add TextBox and Button to handle user Click.

Let us do an example ,

1-firstly, we need to create custom toolpane Class as the following, here, we need two controls TextBox to get Full path of selected List and Button to handle User Click.

namespace SharePoint14.Webparts.QuickLinkWebPart

{


public
class
ListPicker: EditorPart

{


TextBox txt;


Button btn;

2-then add Custom ToolPane ID and Title in Construct ,also define Control Init function.

public ListPicker(string webPartID, string webpartname)

{


this.ID = “listpicker” + webPartID;


this.Title = “Custom WebPart Settings”;


//this = webpartname;


this.Init += new
EventHandler(ImagePickerToolPart_Init);

}

3- define Init Function, in this function will add define Script Link Control , and in Name Property add “AssetPickers.JS” Load OOTB JavaScript File which is responsible for Opening nice picker dialog where you can choose the List

private
void ImagePickerToolPart_Init(object sender, EventArgs e)

{

txt = new
TextBox();

btn = new
Button();

sl = new
ScriptLink();

lit = new
Literal();

sl.Name = “AssetPickers.js”;

sl.Localizable = true;

sl.Language = “javascript”;

btn.Text = “…”;

SyncChanges();

}

4- Define CreateChildControls()

protected
override
void CreateChildControls()

{


base.CreateChildControls();

Controls.Add(sl);


this.Controls.Add(new
Label() { Text = “Select a List” });


this.Controls.Add(new
HtmlGenericControl(“br”));

Controls.Add(txt);

Controls.Add(btn);


string strRelativeWebURL = SPEncode.HtmlEncode(SPControl.GetContextWeb(Context).ServerRelativeUrl);


if (strRelativeWebURL.Trim() ==“/”)

{

strRelativeWebURL =“”; //blank browses the root spweb

}


string strAssetPickerConfig = string.Format(@”

<script type=’text/javascript’>

with(new AssetPickerConfig(‘testAssetPickerObj’))

{{

DefaultAssetImageLocation=”;

CurrentWebBaseUrl='{0}’;

OverrideDialogFeatures=”;

OverrideDialogTitle=”;

OverrideDialogDesc=”;

OverrideDialogImageUrl=”;

AssetUrlClientID='{1}’;

AssetTextClientID=”;

UseImageAssetPicker=true; //make this false to show Documents instead

DefaultToLastUsedLocation=true;

DisplayLookInSection=true;

ReturnCallback = null;}}

</script>”,

strRelativeWebURL,

txt.ClientID);

lit.Text = strAssetPickerConfig;

Controls.Add(lit);

btn.OnClientClick = “APD_LaunchAssetPickerUseConfigCurrentUrl(‘testAssetPickerObj’); return false;”;

}

i hope this help you

Importing SharePoint Solution Package (WSP) into Visual Studio 2010

December 30, 2012 1 comment

In this article I’m talking about importing WSP as a result of exporting site template into visual studio 2010.

Let us go to our demo steps

1-      Go to site setting -> Save site as template

 

2-Give exported template a name and description, and check Include Content checkbox in case you want to export all site contents

3- Go to site setting,  You will get a link to your “solution gallery”, which has your template.

4-Open visual studio 2010 -> Create New Project  ->Import SharePoint Solution Package

5- Select “Deploy as Farm “ option

6-Select the path of existing solution


7-    After importing this WSP, a wizard will appear with all contents of WSP and give developers to select and deselects items.

8-Visual studio Solution

Creating a custom WCF service in SharePoint Server 2010

October 11, 2012 Leave a comment

Developing a WCF in SharePoint 2007 was not easy Job. and for now in SharePoint Server 2010 ASP.NET web services are obsolete . in SharePoint 2010, the recommended approach is developing WCF. Creating Custom WCF and hosting it in SharePoint 2010 isn’t difficult task where we can achieve that through multiple approaches like using an open source Visual Studio 2010 extension know as Community Kit for SharePoint: Development Tools Edition which makes developing Custom WCF more easily or Creating Empty SharePoint Project , then Map to ISAP folder then add WCF files ( Interface , Classes, Configuration Files) to it.

Here i going to use Community Kit for SharePoint . The Community Kit for SharePoint: Development Tools Edition extends the Visual Studio 2010 SharePoint project system with advanced templates and tools.

Create WCF Service

1- create a new empty SharePoint Project.

2- Select Deploy as farm solution.

3- Add new Item, Right Click on Project Name , then Select WCFService (CKSDEV).

Services Type

There are 3 different type of service

1- SOAP Service.

2- REST Service

3- ADO.NET Data Service

if you want to change the service type,please modify the factory in .SVC

SOAP Service Factory : MultipleBaseAddressBasicHttpBindingServiceHostFactory

REST Service Factory: MultipleBaseAddressWebServiceHostFactory

ADO.NET Service Factory : MultipleBaseAddressDataServiceHostFactory

Browsing Custom WCF Service

After Service deploy, you need to use the service in another projects. First try to access the service in browser. But remember you need to access the MEX endpoint either you will not get the service accessible in browser. To access the MEX endpoint, you should add “/MEX” at the end of the service name as shown below:

Approaches to Access SharePoint Data Programmatically (Part 1)

Microsoft SharePoint Server 2010 introduces several new approaches to interact with SharePoint Data . LINQ to SharePoint feature allow to build complex query with user friendly LINQ syntax , also both CAML and LINQ to SharePoint support join predictae in queries.one of major evolutions in SharePoint 2010 is the blurring of the distinction, between internal and external data.we can use many of the same techniques to query extenal data.

Key Approaches to Data Access

SharePoint 2010 introduces 3 key approaches to query data :CAML queries, LINQ to SharePoint, and BCS object model.

1- CAML queries

SPQuery and SPSiteDataQuery classes support submitting queries in CAML syntacs, in SharePoint 2010 CAML support JOIN predicate in queries ,also SPQuery class is using to query external list and the result are non-type items.

2- LINQ to SharePoint

SharePoint 2010 allows you to use LINQ queries to perform data operations on SharePoint Data. LINQ to SharePoint works against strongly typed entities . There is a command-line tool in SharePoint 2010 called SPMETAL that we can use to generate thses entities. internally , the LINQ to SharePoint provider generates the underlying CAML queries that perform data operations.

3-Business Connectivity services (BCS) object model

BCS object model enable us to ineract with external data .

In Next Part (Part 2), i’ll explain Query Classes (SPSiteDataQuery and SPQuery classes ) in details and what are the best practices of using these classes .

 

the following screenshot is taken from MSDN , this screenshot illustrate the usage of using each of Queries classes , LINQ to SharePoint , and BCS Object Model

references :-

http://msdn.microsoft.com/en-us/library/ff798432

Publish Service Applications

Publishing service applications enables remote farms to consume the services of the primary farm. SharePoint Server 2010 supports publication of the following services :-

  1. Managed Metadata Service.
  2. User Profile.
  3. Search
  4. Secure Store Service.
  5. Business Data Connectivity.
  6. Web analytics.

The consuming and publishing farms have to be hosted within domains that share a trust.

Once the infrastructure requirements have been met, publishing service applications requires exchanging trust certificates between the farms. These trust certificates include one root and one Security Token Service (STS) certificate. Exchanging trust certificates ensures that each farm acknowledges that the other farm can be trusted.

The following steps for exchanging the trust certificates between farms :-

  1. Export the root certificate from the consuming farm.
  2. Export the STS certificate from the consuming farm.
  3. Export the root certificate from the publishing farm.
  4. Import the root certificate and create a trusted root authority in the consuming farm.
  5. Import the root certificate and create a trusted root authority in the publishing farm.
  6. Import the STS certificate and create a trusted service token issuer on the publishing farm.

First step: – Export the root certificate from the consuming farm

  1. From start menu, find Microsoft SharePoint 2010 Products, then select SharePoint 2010 Management Shell , then write the following commands

    $certificate=(Get-SPCertificateAuthority).RootCertificate

    $certificate.Export(“Cert”) | Set-Content <drive>:\<path>\Root-Consuming.cer -Encoding byte

    Note : <drive>:\<path> here write any path in your environment .

Second step : export the STS certificate from the consuming farm

  1. From start menu, find Microsoft SharePoint 2010 Products, then select SharePoint 2010 Management Shell , then write the following commands

    $certificate = (Get-SPSecurityTokenServiceConfig).LocalLoginProvider.SigningCertificate

    $certificate.Export(“Cert”) | Set-Content d:\Certificates\STS-Consuming.cer -Encoding byte

Third Step : export the root certificate from the publishing farm

  1. From start menu, find Microsoft SharePoint 2010 Products, then select SharePoint 2010 Management Shell , then write the following commands

    $certificate=(Get-SPCertificateAuthority).RootCertificate

    $certificate.Export(“Cert”) | Set-Content d:\Certificates\Root-Publishing.cer -Encoding byte

Fourth Step: Import the root certifi cate and create a trusted root authority on the consuming farm

  1. From start menu, find Microsoft SharePoint 2010 Products, then select SharePoint 2010 Management Shell , then write the following command

    $certificate = Get-PfxCertificate d:\Certificates\Root-Publishing.cer

    New-SPTrustedRootAuthority -Name WFEFarm1 -Certificate $certificate

    -Name paramte represent a new trusted root authority

Fifth step: import the root certifi cate and create a trusted root authority on the publishing farm

  1. From start menu, find Microsoft SharePoint 2010 Products, then select SharePoint 2010 Management Shell , then write the following commands

    $certificate = Get-PfxCertificate <drive>:\<path>\Root-Consuming.cer

    New-SPTrustedRootAuthority -Name WFEFarm2 -Certificate $certificate

    -Name parameter represents a new trusted root authority

Sixth Step: import the STS certifi cate and create a trusted service token issuer on the publishing farm

  1. From start menu, find Microsoft SharePoint 2010 Products, then select SharePoint 2010 Management Shell , then write the following commands

    $certificate = Get-PfxCertificate <drive>:\<path>\STS-Consuming.cer

    New-SPTrustedServiceTokenIssuer -Name WFEFarmTrust1 -Certificate $certificate

    -Name parameter represents the name of the trust.