Showing posts with label Sharepoint 2010. Show all posts
Showing posts with label Sharepoint 2010. Show all posts

Friday, 21 December 2012

Get All The Site Groups in SharePoint 2010 Using ECMAScript/JavaScript


Introduction

In this article you will see how to get all the site groups in SharePoint 2010 using ECMAScript. I have the following site groups from which I need to get the group name (Navigate to the site, click on Site Actions. Click on Site Settings. In the Users and Permissions section, click on People and Groups. In the left pane, click on Groups).

ShareECMA1.gif

Steps Involved
  1. Navigate to the SharePoint site (I have a site page created in my site where I am going to add the content editor web part).
  2. Go to Site Actions, click on Edit Page.

    ShareECMA2.gif
     
  3. Click on Insert tab in the ribbon interface and then click on Web Part button.

    ShareECMA3.gif
     
  4. Select Media and Content in the Categories section and then click on Content Editor.

    ShareECMA4.gif
     
  5. Click on Add.
  6. A Content editor web part will be added to the site page.
  7. Click on the down arrow and then click on Edit Web Part.

    ShareECMA5.gif
     
  8. Click on "Click here to add new content".

    ShareECMA6.gif
     
  9. Click on Format Text tab in the ribbon interface and then click on HTML drop down.

    ShareECMA7.gif
     
  10. Click on Edit HTML source.
  11. HTML source window will pop up.

    ShareECMA8.gif
     
  12. Copy and paste the following script.
    <script language="ecmascript" type="text/ecmascript">
            var groupCollection;
            function getSiteGroups() {
                var clientContext = new SP.ClientContext();
                this.groupCollection = clientContext.get_web().get_siteGroups();            clientContext.load(groupCollection);
                clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(thisthis.onQueryFailed));
            }
            function onQuerySucceeded() {
                var groupName = 'Site Groups: \n';
                var groupsEnumerator = this.groupCollection.getEnumerator();
                while (groupsEnumerator.moveNext()) {
                    var group = groupsEnumerator.get_current();
                    groupName += group.get_title() + '\n';
                }
                alert(groupName);
            }
            function onQueryFailed(sender, args) {
                alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
            }</script>    <input id="btnGetSiteGroups" onclick="getSiteGroups()" type="button" value="Get Site Groups" 
    />


     
  13. Click on Ok.
  14. In the ribbon interface click on Save & Close button.

    ShareECMA9.gif
     
  15. In the content editor web part you should find a button named "Get Site Groups", click on that button.

    ShareECMA10.gif
     
  16. An alert will pop up displaying all the site groups as shown in the following.

    ShareECMA11.gif
Reference

SP.Web.siteGroups Property - http://msdn.microsoft.com/en-us/library/ee554059.aspx 

Summary

Thus in this article you have seen how to get all the site groups in SharePoint 2010 using ECMAScript.

Thursday, 20 December 2012

Programmatically sending mail in SharePoint using SPUtility class


To send mails using SharePoint API, we can use SPUtility class sendMail method. For referencehttp://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail.aspx
To use this method we will require:

using Microsoft.SharePoint.Utilities;
using System.Collections.Specialized;

You can assign to, cc, bcc, from, subject by creating stringdictionary, like
StringDictionary headers = new StringDictionary();
headers.add("to",strTo);
headers.add("cc",strCC);
headers.add("bcc",strbcc);
headers.add("from",strFrom);
headers.add("subject",strSubject);
headers.add("content-type","text/html");


string emailBody = “Hi<br><br>Sending mails using SPUtility.”;

SPUtility.SendEmail(web, headers, emailBody);

Where web is SPWeb object that represents site from which you want to send mail.

Sunday, 12 February 2012

Enable Claims based authentication on an existing web application in SharePoint



When you provision a web application in SharePoint 2010 you get the option to enable Claims based authentication. However, after the provisioning there's no option in the GUI to turn it on. PowerShell saves the day again with the option to change from classic to claims based authentication using the lines below.
$WebAppName = "http://test:8001"
$account = "Administrator" 
$wa = get-SPWebApplication $WebAppName
Set-SPwebApplication $wa –AuthenticationProvider (New-SPAuthenticationProvider) 
–Zone Default

The user running these command should be a member of the SharePoint_Shell_Access role on the config DB, and a member of the WSS_ADMIN_WPG local group.

Monday, 6 February 2012

Custom sign out SharePoint page for FBA user.


Hi, everyone!
In my latest project we are using FBA users for our portal. And in the prototype of the master page such as generic web page we have login control with username, password boxes and ‘sing in’ button. If you will use for login just general sign in control of ASP .NET we will lose with authentication, exception will appear in the page. For fixing this problem we have to use SPClaimsUtility.
For example:
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    e.Authenticated = 
SPClaimsUtility.AuthenticateFormsUser(Request.Url, signIn.UserName, 
signIn.Password);
}
But for sign out we have to create custom page for logout current user from portal. In all forums you can find information that’s you can use default signout.aspx page from 14 hive. But it’s true if you created custom login page inherited from SharePoint SignInPage. Default page is working incorrectly, it made sign out but doesn’t remove cookies from browser and the next page what you will see after signout, it will ‘Exception … ArgumentException … encodedValue’.
Insert the next following code to the page for clearing sign out.
protected override void OnLoad(EventArgs e)
{
 base.OnLoad(e);

 FormsAuthentication.SignOut();
 var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
        // Clear .ASPAUTH cookie key.
 if (authCookie != null)
 {
  var myCookie = new HttpCookie(authCookie.Name)
               {Expires = DateTime.Now.AddDays(-1)};
  Response.Cookies.Add(myCookie);
 }

 SPIisSettings iisSettingsWithFallback = 
        
 Site.WebApplication.GetIisSettingsWithFallback(Site.Zone);
 if (iisSettingsWithFallback.UseClaimsAuthentication)
 {
  FederatedAuthentication.SessionAuthenticationModule.SignOut();
                // Clear FedAuth Cookie key
  FederatedAuthentication.SessionAuthenticationModule.DeleteSession       
 TokenCookie();
 }


 SPUtility.Redirect(Web.ServerRelativeUrl, SPRedirectFlags.Default,
       
   Context);
}
That’s all what you need to add to the custom sign out page.

Replacing Signout.aspx in SharePoint 2010


Yes, this was a common requirement in SharePoint 2007 and there wasn’t an easy and supportable approach to achieve that. Now in SharePoint 2010, it’s as easy as calling a method, specifying the
page that you want to replace (for instance: Signout, error, access denied, ..) ,the URL of your new
custom page and that's it!
The following feature receiver replaces the default SignOut page with a custom one on activation
and resets the SignOut page to the default one on deactivation.

image

You can also replace other pages like AccessDenied.aspx, Confirmation.aspx, Error.aspx,
Login.aspx, ReqAcc.aspx, SignOut.aspx or WebDeleted.aspx by specifying a member of SPWebApplication.SPCustomPage enum.



SharePoint 2010 - Changes in Custom Lists, and Some Limitations of Custom Lists


SharePoint 2010 - Changes in Custom Lists:
SharePoint 2010 has introduced following changes in the Custom Lists:
  • New events - WebAdding, WebProvisioning, ListAdding, ListAdded, ListDeleting, ListDeleted
  • Site Collection events
  • Synchronous "after" events to perform post-processing
  • Custom error pages
  • New property PSEventPropertiesBase to store the user name and token of the person who triggered the effective action
  • New integrity constraints based on the lookup
  • Projected Fields - fields from the parent which are referenced and displayed in the child list
  • Lists Join - via LINQ, CAML, SharePoint Designer and API (SPQuery.Join and SPQuery.ProjectedFileds)
  • Max 50M items under the read scenario
  • List query size threshold - return warning or exception of query result exceeds threshold number of records
  • Threshold pre-set is 5000 items for the normal user and 20000 items for the Super User
  • List Administrators are notified when lists exceed threshold
  • List constraints - max 8kb of data per list item (excluding attachments), 6 projected fields on joins (except using the view fields)
  • Columns can be flagged as UNIQUE (must be indexed)
  • Columns can be validated using custom field or by other fields
SharePoint 2010 - Some Limitations of Custom Lists:
SharePoint 2010 provides better performance for the Custom List, however it still have some limitations which are listed below:
  • Maximum number of List Items is 50 million
  • Max of 8kb of data per list item (not including attachments)
  • Max of six projected fields allowed on joins

What happens behind the scene when we create new Web Application in SharePoint?


When we create a new Web Application in SharePoint, following are various actions which happens behind the scene:
  • Creates a unique entry in SharePoint configuration DB for the Web Application and assign GUID to that entry.
  • Create and configures a new site in IIS
  • Creates and configures a new IIS application pool.
  • Configures authentication protocol and encryption settings.
  • Assign a Default alternate access mapping for the Web Application.
  • Creates the first content database for the Web Application.
  • Associate a search service with the Web application.
  • Assign a name to the Web application that appears in the Web application list in SharePoint Central Administration.
  • Assign general settings to the Web application, such as maximum file upload size and default time zone.
  • Updates the web.config file to make entries for custom HTTP Modules andHandlers for SharePoint.
  • Creates virtual directories for SharePoint web services and SharePoint layouts folder.
After creating a Web Application in SharePoint, the web site is actually not created yet. It means if you try to access the Web Application using the web app url, it will show you "Page cannot be displayed" error. Basically at this point of time, a web application has been created and all the mandatory configuration has been done. Now the next step is to create a Site Collection using a particular Site Definition, then only the actual site will be created and you will be able to access the site using the url of Site Collection.