Loading...

Saturday, October 29, 2011

Sharepoint 2010 REST API to get the List and Library Data


1)What is REST?
Representational State Transer

2)What we can do with it?

i) Query Service Application  like excel services
 and display the excel Charts.
 ii)Query  List Data and Display data with Jquery or Silverlight(/_vti_bin/listdata.svc)

Wednesday, October 19, 2011

Sharepoint 2010 Social Features:Tag Cloud By AccountName


In OOB tag cloud, we get tag cloud only by Current user or By All tags.
To Customize tag cloud by accountname or profile ,
1. Add the reference of /_layouts/1033/styles/socialdata.css in page layouts or masterpage.

2. Add dll reference C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\microsoft.sharepoint.portal.dll
3. In Visual studio, Right click solutionAdd service reference click on ‘Advanced’ buttonAdd web referenceclick link Web services on local machine.
4. Search for socialdataservice.asmx.

public class TagWP : WebPart
{

localhost.SocialTermDetail[] details;

localhost.SocialDataService objSocialDataService = null;

long tagCount = 0;

protected override void CreateChildControls()

{

objSocialDataService = new localhost.SocialDataService();

int maximuItems=10;
int intstartIndex=1;
objSocialDataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
string accountname= SPHttpUtility.HtmlEncode(Context.Request.QueryString["accountname"]);
details = objSocialDataService.GetTagTermsOfUser(accountname, maximuItems);
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)

{
writer.Write("DIV id='tagCloudDatatagCloudByProfile' class='ms-TagCloud ms-TagCloudLink


");

writer.Write("DIV id='tagCloudByProfile'

");

Sunday, October 9, 2011

Sharepoint 2010 Social Features: Rating Publishing Pages/Blog pages

1)Enable the publishing features in site collection/site level

In Page Library Settings-->Rating Setting -->Enable the Contents to be rated.
Edit the Page in Sharepoint Designer or modify the Pagelayouts.

2)Add the namespace
%@ Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %

3)Make sure that User Profile Service application is running in CA-->Manage Service applications
Add Rating Control  in Page Layout
SharePointPortalControls:AverageRatingFieldControl FieldName="Rating" runat="server"

Make sure that Field Name matches the Rating Column Name in Page Library.
4) To view the quick effects
CA > Monitoring > Timer Jobs > Review Job Definitions > look for 'User Profile Service Application - Social Data Maintenance Job' and 'User Profile Service Application - Social Rating Synchronization Job'.
Run the jobs.
5)If You get the Error 'Object reference not set to an instance' on viewing rated publishing Page
cmd-->inetmgr ->Restart SharePoint Web Services under Sites

6)
Include the reference of JS file in Page Layouts
script type='text/javascript'
$(document).ready(function() {
var pathname = window.location;
var soapEnv ="soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>\
soap:Body>\
GetRatingOnUrl xmlns='http://microsoft.com/webservices/SharePointPortalServer/SocialDataService'>\
url>+ pathname + /url>\
/GetRatingOnUrl>\
/soap:Body>\
/soap: Envelope>"
alert (soapEnv);
$.ajax({
url: "http://servername/_vti_bin/SocialDataService.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""

});

});

function processResult(xData, status) {

var result = $(xData.responseXML).find("Rating")
//get rating value from webservice
var avg = parseFloat(result.text());

$(".ms-currentRating img").addClass(getClassNameForRating(avg));

}
function getClassNameForRating(rating) {
//apply class according  to ratings
if(isNaN(rating)

rating = 0)

return "";

if (rating < 0.25)

return "ms-rating_0";

if (rating <; 0.75)

return "ms-rating_0_5";

if (rating <; 1.25)

return "ms-rating_1";

if (rating < 1.75)

return "ms-rating_1_5";

if (rating < 2.25)

return "ms-rating_2";

if (rating < 2.75)

return "ms-rating_2_5";

if (rating < 3.25)

return "ms-rating_3";

if (rating < 3.75)

return "ms-rating_3_5";

if (rating < 4.25)

return "ms-rating_4";

if (rating <; 4.75)

return "ms-rating_4_5";

else

return "ms-rating_5";

}



/script>



Monday, September 19, 2011

OOB authorization with SPSecurityTrimmedControl

Using In Webparts
1)Declare SPSecurityTrimmedControl
SPSecurityTrimmedControl stcEditItem = new SPSecurityTrimmedControl();


2)Define Controls in WebPart
protected override void CreateChildControls()

{

stcEditItem.ID = "idPrm";

stcEditItem.Permissions = SPBasePermissions.ManageWeb;

ltrPopup.ID = "ltrPerm";

stcEditItem.Controls.Add(ltrPopup);

this.Controls.Add(stcEditItem);
}
3)Render the Trimmed Html contents,Now these content are available to administrators only


protected override void Render(HtmlTextWriter writer)

{

StringBuilder sb = AddModalPopUp(SPContext.Current.Web);

ltrPopup.Text = sb.ToString();

stcEditItem.RenderControl(writer);

}
Using in Visual Webpart
Open the .ascx file and add the controls inside SPSecurityTrimmedControl
SharePoint:SPSecurityTrimmedControl ID="ctrlSecurityTrimmed" runat="server" Permissions="ManageWeb">
controls. here..
SharePoint:SPSecurityTrimmedControl>

'value does not fall in expected range' When assigning SPUser to ListItem


If you try to assign,
ListItem["UserField"]=SPContext.Web.CurrentUser
And you get th Error  " value does not fall in expected range"
Cause:  ListItem is in different Sitecollection
So Directly You can not assign current user.
Resolution:
SPUser differntSiteCollectionUser = differentWeb.SiteUsers.GetByEmail(currentUserMailId);-->GetmailID with SPFieldUserValue

Thursday, September 8, 2011

Modal Popup and The Notification Area

Here I am covering
        1)Passing Url to Modal Popup from Server code in .cs file
          i)add the hiddenfield control to .aspx page          
and set value in cs file
hdnUrl.Value = "../Lists/ListName/NewForm.aspx?RootFolder=&";

        2)On Click of Ok button of Modal Popup Displaying the message in notification area which is part of sp2010 framework
Add following in Javascript tags
var url = document.getElementById('').value;

var options = {

url: url

title: "title",

allowMaximize: true,

showClose: true,

dialogReturnValueCallback: refreshCallback

};

function open() { SP.UI.ModalDialog.showModalDialog(options); }

function silentCallback(dialogResult, returnValue) {

}

function refreshCallback(dialogResult, returnValue) {

SP.UI.Notify.addNotification('Successful!');

SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

}


Invoke the function

asp:Label runat="server" ID ="lblr" Text ="Open Popup">

Friday, September 2, 2011

To Position the Modal Popup Correctly...

Override the following css class and update the refering css file
.ms-dlgContent

{
position:fixed !important;
}
or use CSSRegistration.Register("_/layoout%Path%..") method (in CreatechildControl for Webpart/Prerender for usercontrol).