Thursday, June 28, 2012

Unable to authorize to SharePoint 2010 on Android phone

The default browser of Android Devices blocks the Authentication popup window of SharePoint 2010. Therefore when you try to get in the your site, you receive "401 Unauthorized error".

The easy way to resolve it : download Firefox browser on your phone, which officially supported by Microsoft for SharePoint 2010. Firefox supports SharePoint’s login popup and allows you to login to your site!

You can download it by Play Store of Android or by QR Code :


QRCode

Sunday, June 24, 2012

New CAML Designer is released !

All of us know U2U CAML Builder and all of us encountered on bugs of it.
So, Karine Bosch noticed on release of new version of CAML Designer.

I hope it will help us - SharePoint Developers




Monday, June 18, 2012

SharePoint 2010 - Creating a Anonymous Web Applications By PowerShell

I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.

AnonymousState determines if anonymous users have access to the site collection as follows:

  • A "0" disables anonymous access. In other words, anonymous users have no access to a Web site.
  • A "1" allows default anonymous access. This specifies that anonymous users can access lists and libraries if the lists and libraries allow anonymous access.
  • A "2" specifies that anonymous users can access the entire Web site.
AnonymousPermMask allows you to control granular permissions. The values of the mask (taken directly from the source code) are:

  • ViewListItems = View items in lists, documents in document libraries, and view Web discussion
  • AddListItems = items to lists, add documents to document libraries, and add Web discussion
  • EditListItems = Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.
  • DeleteListItems = Delete items from a list, documents from a document library, and Web discussion comments in documents.
  • ApproveItems = Approve a minor version of a list item or document.
  • OpenItems = View the source of documents with server-side file handlers.
  • ViewVersions = View past versions of a list item or document.
  • DeleteVersions = Delete past versions of a list item or document.
  • CancelCheckout = Discard or check in a document which is checked out to another user.
  • ManagePersonalViews = Create, change, and delete personal views of lists.
  • ManageLists = Create and delete lists, add or remove columns in a list, and add or remove public views of a list.
  • ViewFormPages = View forms, views, and application pages, and enumerate lists.
  • Open = Allow users to open a Web site, list, or folder to access items inside that container.
  • ViewPages = View pages in a Web site.
  • AddAndCustomizePages = Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a Windows SharePoint Services–compatible editor.
  • ApplyThemeAndBorder = Apply a theme or borders to the entire Web site.
  • ApplyStyleSheets = Apply a style sheet (.css file) to the Web site.
  • ViewUsageData = View reports on Web site usage.
  • CreateSSCSite = Create a Web site using Self-Service Site Creation.
  • ManageSubwebs = Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.
  • CreateGroups = Create a group of users that can be used anywhere within the site collection.
  • ManagePermissions = Create and change permission levels on the Web site and assign permissions to users and groups.
  • BrowseDirectories = Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces.
  • BrowseUserInfo = View information about users of the Web site.
  • AddDelPrivateWebParts = Add or remove personal Web Parts on a Web Part Page.
  • UpdatePersonalWebParts = Update Web Parts to display personalized information.
  • ManageWeb = Grant the ability to perform all administration tasks for the Web site as well as manage content. Activate, deactivate, or edit properties of Web site features through the object model or through the user interface (UI). When granted on the root Web site of a site collection, activate, deactivate or edit properties of site collection scoped Features through the object model. To browse to the Site Collection Features page and activate or deactivate site collection scoped Features through the UI, you must be a site collection administrator.
  • UseClientIntegration = Use features that launch client applications; otherwise, users must work
  • UseRemoteAPIs = Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces to access the Web site.
  • ManageAlerts = Manage alerts for all users of the Web site.
  • CreateAlerts = Create e-mail alerts.
  • EditMyUserInfo = Allows a user to change his or her user information, such as adding a picture.
  • EnumeratePermissions = Enumerate permissions on the Web site, list, folder, document, or list item.




$WebAppURL = "http://www.brianbeach.com"
$HostHeader = "www.brianbeach.com"
$WebAppName = "Anonymous Web Application"
$ContentDatabase = "Content_Anonymous_Default"
$AppPoolName = "Anonymous Content"
$AppPoolUserName = "DOMAIN\USER_NAME"

Write-Host "Creating the anonymous web application"
$AppPoolCred = Get-Credential $AppPoolUserName
$AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCred
$AuthProvider = New-SPAuthenticationProvider -AllowAnonymous
$WebApp = New-SPWebApplication -AllowAnonymousAccess -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAccount -Name $WebAppName -URL $WebAppURL -HostHeader $HostHeader -Port 80 -AuthenticationProvider $AuthProvider -DatabaseName $ContentDatabase


$SiteName = "Anonymous Root Site"
$OwnerEmail = "USER_NAME@DOMAIN.com"
$OwnerAlias = "DOMAIN\USER_NAME"
$SiteURL = "http://www.brianbeach.com"

Write-Host "Creating a default site collection in the anonymous web application"
New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template "STS#0"
$Web = Get-SPWeb $SiteURL
$Web.title = $SiteName
$Web.AnonymousState = 2;
$Web.AnonymousPermMask64 = "ViewListItems, ViewVersions, ViewFormPages, Open, ViewPages, UseClientIntegration, AddListItems"
$Web.update()

SharePoint 2010 - Creating a Site Collections By PowerShell

I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.

List of common templates:
  • STS#0 - Team Site
  • STS#1 - Blank Site
  • STS#2 - Document Workspace
  • MPS#0 - Basic Meeting Workspace
  • MPS#1 - Blank Meeting Workspace
  • MPS#2 - Decision Meeting Workspace
  • MPS#3 - Social Meeting Workspace
  • MPS#4 - Multipage Meeting Workspace
  • WIKI#0 - Wiki
  • BLOG#0 – Blog


  • $SiteName = "Human Resources Site"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com/sites/hr"
    $SiteTemplate = "STS#0"

    Write-Host "Creating a relative site collection in the intranet web application"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()



    $WebAppURL = "http://intranet.DOMAIN.com"
    $ContentDatabase = "Content_Intranet_BLOG"

    Write-Host "Creating a new content database in the intranet web application"
    New-SPContentDatabase $ContentDatabase -WebApplication $WebAppURL

    $SiteName = "Intranet Blog"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com/sites/blog"
    $SiteTemplate = "BLOG#0"

    Write-Host "Creating a relative site collection in the intranet web application with a separate content database"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -ContentDatabase $ContentDatabase -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()



    $SiteName = "Intranet WIKI"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $WebAppURL = "http://intranet.DOMAIN.com"
    $SiteURL = "http://wiki.DOMAIN.com"
    $SiteTemplate = "WIKI#0"

    Write-Host "Creating a hostheader site collection in the intranet web application"
    $WebApp = Get-SPWebApplication $WebAppURL
    New-SPSite -url $SiteURL -HostHeaderWebApplication $WebApp -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()

    $WebAppName = "Intranet Web Application"
    $HostHeader = "wiki.DOMAIN.com"

    Import-Module WebAdministration
    New-WebBinding -Name $WebAppName -Port 80 -Protocol "http" -HostHeader $HostHeader

    SharePoint 2010 - Creating a Web Application By PowerShell

    I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.

    $WebAppURL = "http://intranet.DOMAIN.com"
    $HostHeader = "intranet.DOMAIN.com"
    $ContentDatabase = "Content_Intranet_Default"
    $WebAppName = "Intranet Web Application"
    $AppPoolName = "Intranet Content"
    $AppPoolUserName = "DOMAIN\SERVICE_ACCOUNT"

    Write-Host "Creating the intranet web application"
    $AppPoolCred = Get-Credential $AppPoolUserName
    $AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCred
    $AuthProvider = New-SPAuthenticationProvider
    $WebApp = New-SPWebApplication -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAccount -Name $WebAppName -URL $WebAppURL -HostHeader $HostHeader -Port 80 -AuthenticationProvider $AuthProvider -DatabaseName $ContentDatabase


    $SiteName = "Intranet Root Site"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com"
    $SiteTemplate = "STS#1"

    Write-Host "Creating a default site collection in the intranet web application"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()

    SharePoint 2010 - Creating the Farm By PowerShell

    I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.




    Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0
    Clear-Host

    $FarmAccountName = "DOMAIN\SERVICE_ACCOUNT"
    $Passphrase = "PASSWORD"
    $DatabaseServer = "DATABASE_SERVER_NAME"
    $ConfigDatabase = "Config"
    $ContentDatabase = "Content_Admin"

    Write-Host "Creating Configuration Database"
    $FarmAccount = Get-Credential $FarmAccountName
    $Passphrase = (ConvertTo-SecureString $Passphrase -AsPlainText -force)
    New-SPConfigurationDatabase -DatabaseServer $DatabaseServer -DatabaseName $ConfigDatabase -AdministrationContentDatabaseName $ContentDatabase -Passphrase $Passphrase -FarmCredentials $FarmAccount

    Write-Host "Configuring Farm"
    Initialize-SPResourceSecurity
    Install-SPService
    Install-SPFeature -AllExistingFeatures

    Write-Host "Configuring Central Administration"
    New-SPCentralAdministration -Port 8080 -WindowsAuthProvider NTLM
    Install-SPHelpCollection -All
    Install-SPApplicationContent



    How to delete the deployed Event Receiver in Sharepoint server 2010 By C#

    I took it from this article




    private void DeleteEventReceiverFromAList(string siteUrl)
    {
    using (SPSite site = new SPSite(siteUrl))
    {
    using(SPWeb web = site.OpenWeb())
    {
    try
    {
    SPList list = web.Lists["myList"];
    if (list != null)
    {
    string className = "EventReceiverClass";
    string asmName = "EventReceiverAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111111";
    web.AllowUnsafeUpdates = true;
    int receivers = list.EventReceivers.Count;
    bool isAddedReceiverExist = false;
    bool isUpdatedReceiverExist = false;
    for (int i = 0; i < receivers; i++)
    {
    SPEventReceiverDefinition eventReceiver = list.EventReceivers[i];
    if (eventReceiver.Class == className && eventReceiver.Type == SPEventReceiverType.ItemAdded)
    {
    eventReceiver.Delete();
    break;
    }
    }
    }
    }
    catch { }
    finally
    {
    web.AllowUnsafeUpdates = false;
    }
    }
    }
    }

    How to delete the deployed Event Receiver in Sharepoint server 2010 - PowerShell

    I took it from this article

    $spWeb = Get-SPWeb -Identity http://contoso.com

    $spList = $spWeb.Lists["My List Name"]
    $eventsCount = $spList.EventReceivers.Count
    $assembly = "Project.Name.Class, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11111111111"
    $class = "Namespace.MyClass.ClassName"
    $type = 10002
    $name = "My Event Name"
    for ($i = 0; $i -lt $eventsCount; $i+=1)
    {
    if ($spList.EventReceivers[$i].Assembly -eq
    $assembly
    -and
    $spList.EventReceivers[$i].Class -eq $class
    -and
    $spList.EventReceivers[$i].Type -eq $type
    -and $spList.EventReceivers[$i].Name -eq
    $Name)
    {
    $spList.EventReceivers[$i].Delete()
    }
    }
    $spList.Update()

    Tuesday, June 12, 2012

    Read SPListItemVersion in SharePoint 2010

    SPListItemVersion Class return the collection of versions for a list item. If versioning is enabled on a list, each time you modify an item a version is created.

    Enable SharePoint List versioning using c#:


    using (SPSite spsite = new SPSite("http://contoso.com"))
    {
    SPWeb spweb = spsite.OpenWeb();
    SPList list = spweb.Lists["ListName"];
    list.EnableVersioning = true;
    list.Update();
    }



    Retrieve SPListItem versions using c#:


    public  class PageVersions
    {
    public string PageVersion { get; set; }
    public SPUser PageVersionOwner { get; set; }
    public DateTime PageVersionDate { get; set; }
    }

    public class GetVersionsClass
    {

    public PageVersions CalculateVersionPoints(SPListItem item,int prevDates)
    {
    PageVersions pv = new PageVersions();

    SPListItemVersionCollection oVersionInfo = item.Versions;

    foreach (SPListItemVersion oVersion in oVersionInfo)
    {
    if (oVersion.Level == SPFileLevel.Published)
    {



    if (oVersion.Created.ToLocalTime().CompareTo(DateTime.Now.AddDays(prevDates)) >= 0)
    {
    pv.PageVersion = oVersion.VersionId.ToString();
    pv.PageVersionDate = oVersion.Created;
    pv.PageVersionOwner = oVersion.CreatedBy.User;

    }

    }
    }

    return pv;
    }
    }


    Monday, June 11, 2012

    Custom Style and Slots in Content Query Web Part (CQWP)


    The CQWP allows us to modify or create new styles which help to show custom data.
    In addition by Slots we can use custom parameters and show custom fields.

    For example:










    1.Open CQWP in notepad or VS

    2.Find "CommonViewFields"

    3.Add custom columns:


    Role, Text
    Action, Text
    Responsibility, Text




    4.Open SharePoint Designer and CheckOut of:

    /Style Library/XSL Style Sheets/ItemStyle.xsl

    5.Insert our new template or modify old one:






















    _blank








    <tr style="background-color:#f7f3f7;color:#848284">
    <td style="font-size:12px;color:black" valign="top">Role</td>
    <td style="font-size:12px;color:black" valign="top">Action</td>
    <td style="font-size:12px;color:black" valign="top">Responsibility</td>
    </tr>























    Thursday, June 7, 2012

    New feature of .NET Framework 4.5 - Await

    Most of us , who uses Silverlight Client Object Model has encountered with the problems of asynchronous programming by the Microsoft blog : Async in 4.5: Worth the Await.
    I just took a piece of code from this blog, to show how it makes our lives easier :)

    Synchronous example:


    public static void CopyTo(Stream source, Stream destination)
    {
    byte[] buffer = new byte[0x1000];
    int numRead;
    while((numRead = source.Read(buffer, 0, buffer.Length)) > 0)
    {
    destination.Write(buffer, 0, numRead);
    }
    }


    Asynchronous Programming Model:


    public static IAsyncResult BeginCopyTo(Stream source, Stream destination)
    {
    var tcs = new TaskCompletionSource();

    byte[] buffer = new byte[0x1000];
    Action readWriteLoop = null;
    readWriteLoop = iar =>
    {
    try
    {
    for (bool isRead = iar == null; ; isRead = !isRead)
    {
    switch (isRead)
    {
    case true:
    iar = source.BeginRead(buffer, 0, buffer.Length, readResult =>
    {
    if (readResult.CompletedSynchronously) return;
    readWriteLoop(readResult);
    }, null);
    if (!iar.CompletedSynchronously) return;
    break;

    case false:
    int numRead = source.EndRead(iar);
    if (numRead == 0)
    {
    tcs.TrySetResult(true);
    return;
    }
    iar = destination.BeginWrite(buffer, 0, numRead, writeResult =>
    {
    try
    {
    if (writeResult.CompletedSynchronously) return;
    destination.EndWrite(writeResult);
    readWriteLoop(null);
    }
    catch(Exception e) { tcs.TrySetException(e); }
    }, null);
    if (!iar.CompletedSynchronously) return;
    destination.EndWrite(iar);
    break;
    }
    }
    }
    }
    catch(Exception e) { tcs.TrySetException(e); }
    };
    readWriteLoop(null);

    return tcs.Task;
    }

    public static void EndCopyTo(IAsyncResult asyncResult)
    {
    ((Task)asyncResult).Wait();
    }



    New C# language async support:


    public static async void CopyToAsync(Stream source, Stream destination)
    {
    byte[] buffer = new byte[0x1000];
    int numRead;
    while((numRead = await source.ReadAsync(buffer, 0, buffer.Length)) > 0)
    {
    await destination.WriteAsync(buffer, 0, numRead);
    }
    }