Showing posts with label 2013. Show all posts
Showing posts with label 2013. Show all posts

Wednesday, 25 May 2016

SharePoint 2013 wymaga .NET 4.5, który jest już zainstalowany

Próbuję zainstalować SharePoint 2013 na Windows Server 2012 R2:



Tymczasem 4.5 już jest zainstalowane. Niestety, zainstalowane jest też Visual Studio 2015, które dostarcza .NET 4.6, a instalator SP znajdując 4.6 uznaje, że nie ma 4.5.

1.      Odinstaluj Visual Studio 2015.
2.      Znajdź zainstalowaną aktualizację KB3045563 i odinstaluj ją.

Wednesday, 5 November 2014

How to fetch more than 5000 entities from CRM

Let's start with simple example to get all entities from CRM

public EntityCollection GetEntities(string entityName)
{
    var config = ServerConnection.GetServerConfiguration();
    var proxy = ServerConnection.GetOrganizationProxy(config);

    string request = string.Format(@"<fetch mapping ='logical'>
               <entity name = '{0}'></entity></fetch>", entityName);
    FetchExpression expression = new FetchExpression(request);
    var mult = proxy.RetrieveMultiple(expression);

    return mult;           
}
This will work, but will return maximum of 5000 elements in mult.Entities.
Let's add paging now and put that in loop until mult.MoreRecords is false.

string request = string.Format(@"<fetch
                count='5000' page='{1}' mapping ='logical'>
                <entity name = '{0}'></entity></fetch>"
, entityName, page++);
But now Paging cookie is required when trying to retrieve a set of records on any high pages.
Paging cookie is returned in EntityCollection.PagingCookie property. Also, XML tags must be encoded, because this is xml-in-xml.

pagingCookie = string.Format("paging-cookie='{0}'",
    System.Web.
HttpUtility.HtmlEncode(mult.PagingCookie));

Now, complete method looks like this:

public IList<Entity> GetEntitiesNoLimit(string entityName)
{
    var config = ServerConnection.GetServerConfiguration();
    IOrganizationService proxy = ServerConnection.GetOrganizationProxy(config);

    var entities = new List<Entity>();
    int page = 1;
    string pagingCookie = string.Empty;
    while (true)
    {
        string request = string.Format(@"<fetch {2} count='5000' page='{1}'
                         mapping ='logical'><entity name = '{0}'></entity></fetch>",
                         entityName, page++, pagingCookie);
        FetchExpression expression = new FetchExpression(request);
        var mult = proxy.RetrieveMultiple(expression);
        entities.AddRange(mult.Entities);
        if (mult.MoreRecords)
        {
            pagingCookie = string.Format("paging-cookie='{0}'",
                        System.Web.HttpUtility.HtmlEncode(mult.PagingCookie));
        }
        else
        {
            break;
        }
    }

    return entities;
}

Monday, 12 August 2013

Local Security Authority problem

Ever tried to log in to your remote computer, only to see this error message?
An authentication error has occurred. The Local Security Authority cannot be contacted.

I have my Azure Virtual Machine configured in domain. The Domain Controller and DNS is also an Azure VM. I'm trying to log in with my domain credentials. This error means, that the remote machine cannot access domain controller.
This error often occurs (or rather always and only) after I restarted VM - e.g. to change number of cores or memory.

Solution:

1. Log in to VM using local user, not domain one.
2. Open network and sharing center.
3. Click "Change adapter settings". As you can see, Windows cannot identify your domain.
4. Right-click network card icon, open Properties, double-click "Internet Protocol Version 4".
5. DNS server address disappeared. Set it again.
6. Now, you're back in domain. Log out and log in with domain credentials.

Monday, 29 July 2013

SharePoint social feed - how to get mentions

The article on MSDN is good starting point [1]. It shows example on how to get feed manager, make asynchronous call and retrieve newsfeed.

Instead of retrieving newsfeed, let's retrieve mentions. For this use getMentions() method[2].

In original code, while iterating, all non-normal threads were ignored. Here instead, only thread type 3 will be used [3].
Original code retrieved Text property from Thread [4]. For mentions, that would always render something like "Mentioned by John Doe". We need to go deeper in thread's properties to get actual mention text. See code example below.

Another challenge is to get URL of story. I could not find this in documentation, but was able to reverse engineer this property from raw object.
var url = thread.$2c_1;
In the end, text and url were pushed into array, so I can work with it in later and display for user in any form that is convenient.
        var mentionsArray = [];
        var mentionsCount;
        // Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
        SP.SOD.executeOrDelayUntilScriptLoaded(GetFeeds, 'SP.UserProfiles.js');

        // Declare global variables.
        var clientContext;
        var feedManager;
        var mentionsFeed;

        function GetFeeds() {

            // Initialize the current client context and the SocialFeedManager instance.
            clientContext = SP.ClientContext.get_current();
            feedManager = new SP.Social.SocialFeedManager(clientContext);

            // Set parameters for the feed content that you want to retrieve.
            var feedOptions = new SP.Social.SocialFeedOptions();
            feedOptions.set_maxThreadCount(10); // default is 20

            // Change the sort order to optimize the Timeline feed results.
            feedOptions.set_sortOrder(SP.Social.SocialFeedSortOrder.byCreatedTime);
            mentionsFeed = feedManager.getMentions(false, feedOptions);     //do not clear unread mentions

            clientContext.load(feedManager);
            clientContext.executeQueryAsync(CallIterateFunctionForFeeds, RequestFailed);
        }
       function CallIterateFunctionForFeeds() {
            IterateThroughFeed(mentionsFeed);

            // Later mentionsArray will be boud by using Knockout.js ;)
            var viewModel = new AppViewModel();
            ko.applyBindings(viewModel);
        }
        function IterateThroughFeed(feed) {
            var feedOwner = feedManager.get_owner().get_name();

            // Iterate through the array of threads in the feed.
            var threads = feed.get_threads();
            mentionsCount = feed.get_unreadMentionCount();

            for (var i = 0; i < threads.length ; i++) {
                var thread = threads[i];
                var actors = thread.get_actors();

                // Use mentions. (SocialThreadType.mentionReference)
                if (thread.get_threadType() == 3) {

                    // Get the root post's author, content, and number of replies.
                    var post = thread.get_rootPost();
                    var authorName = actors[post.get_authorIndex()].get_name();
                    var postContent = post.get_text();
                    var postReference = thread.get_postReference();
                    var referencedPost = postReference.get_post();
                    var mentionText = referencedPost.get_text();

                    var url = thread.$2c_1;         //reverse engineered this name

                    mentionsArray.push({ text: postContent + " " + mentionText, url: url });
                }
            }
        }
        function RequestFailed(sender, args) {
            //not implemented
        }
MSDN Articles:
[1] Retrieve social feeds by using the SharePoint 2013 JavaScript object model http://msdn.microsoft.com/en-us/library/jj164025.aspx#bkmk_GetFeeds
[2] SP.Social.SocialFeedManager.getMentions Method http://msdn.microsoft.com/en-us/library/jj679814.aspx

Monday, 8 July 2013

Creating SharePoint 2013 on Azure VMs - checklist

Follow this checklist to create SharePoint 2013 Server with configuration database on separate Virtual Machine.
  1. Create Network in Azure
  2. After that create two VMs - first with SQL, second with SP
  3. During creating, add them both to the same Network
  4. Log into first VM - the SQL one. Add AD DS feature and promote it to domain controller
  5. Create domain user, that will be SP SQL user.
  6. Open SQL Management Studio and create login and permissions for SP SQL user
  7. Open Windows Firewall and set inbound rule for port 1433 (SQL Server)
  8. Go to Azure and create endpoint for first VM for port 1433
  9. Log into second VM - the SP one. Join it to domain.
  10. Start SP Configuration Wizard, Create new server farm, use SP SQL user to create configuration DB, configure the rest

Wednesday, 6 February 2013

Surveys in Excel with SharePoint 2013

Did you know, that you can create a survey in Excel right from SharePoint?
To be able to do this, you need to be able to create and edit Office documents in browser, so you either are using Office 365, or have Office Web Apps Server installed.

Go to document library, and when creating new document, choose Excel survey
Give it a name
Now, Excel Web App will open and display wizard.

When you add question, you have following answer types:
  • Text (one line)
  • Paragraph of text
  • Number
  • Date (unfortunately, no date picker, only textbox)
  • Time
  • Boolean value (yes/no)
  • Choice

You add as many questions you like, drag them around and arrange to your wish. When you're ready, click Share survey, and you will get a link that you can send to your frineds or collegues.

The same can be also done using consumer SkyDrive (skydrive.live.com).


Wednesday, 28 November 2012

Sync SkyDrive Pro

With SkyDrive Pro, files can be synchronized easily between PC, SharePoint library, and other devices. Necessary are:
Office 2013
SharePoint 2013 or Office 365.
This functionality was previously known as SharePoint Workspace. It 2013 version it is just much simpler.


Run SkyDrive Pro

Enter URL of what you want to sync
Click Sync Now.

After just few minutes you will see SkyDrive folder in Windows Explorer…
…that is synchronized with SharePoint

Thursday, 15 November 2012

SharePoint 2013 Look & feel in WebApp

Include these files

Copy sp.ui.controls.js from
<15 Hive>\TEMPLATE\LAYOUTS

Also, add SPHostUrl variable to query string, so address is something like:
TestPage.aspx?SPHostUrl=https%3a%2f%2fmyofficethreesixtyfive.sharepoint.com
<head runat="server">
    <title></title>
    <script src="../Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/sp.ui.controls.js" type="text/javascript"></script>
    <script type="text/javascript">
        var hostweburl;
        $(document).ready(function () {
            hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
            var scriptbase = hostweburl + "/_layouts/15/";
            $.getScript(scriptbase + "SP.UI.Controls.js")
        });
        function getQueryStringParameter(paramToRetrieve) {
            var queryString = document.URL.split("?")
            if (queryString.length > 1) {
                var params = queryString[1].split("&");
                var strParams = "";
                for (var i = 0; i < params.length; i++) {
                    var singleParam = params[i].split("=");
                    if (singleParam[0] == paramToRetrieve) {
                       return singleParam[1];
                    }
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div
            id="chrome_ctrl_container"
            data-ms-control="SP.UI.Controls.Navigation"
            data-ms-options='{
                "appHelpPageUrl" : "HelpPage.html",
                "appTitle" : "Diff App",
                "settingsLinks" : [
                {
                    "linkUrl" : "Page1.html",
                    "displayName" : "Navigation 1"
                },
                {
                    "linkUrl" : "Page2.html",
                    "displayName" : "Navigation 2"
                }
            ]}'>
        </div>

Snippets can be downloaded from here:
Scripts snippet
Div container snippet


Tuesday, 13 November 2012

Step-by-step: creating Remote Event Receiver

In this example I will show, how to create autohosted SharePoint 2013 app with Remote Event Receiver, and then how to deploy it to Office 365 Developer Preview.

Start with creating a list in SharePoint site, to which you will attach Event Receiver.
Go to site contents and create new Announcements list.
In Visual Studio, create new project type: App for Office 2013. For hosting type, choose autohosted.
In Solution Explorer, right-click on newly created project and choose Add > New Item. Add Remote Event Receiver


In next dialog, choose list type and which events will be handled.

You will notice, that new project has been added to your solution. This is a web service, that will be hosted outside SharePoint, on Windows Azure. SharePoint will make calls to this web service, that contain code to handle remote events.
At this step, Visual Studio has generated some boilerplate code, that you will need to extend.
Notice 'TokenHelper.cs' file. This file contains ready to use methods, to retrieve SharePointContextToken. This context token can be later used to call back to SharePoint. You can make calls to SharePoint using Client-Side Object Model (CSOM).

If you selected several different events for your list, like eg. ItemAdded, ItemUpdated, ItemDeleted, etc., they will all be handled by ProcessEvent method in web service. To be able to differentiate between various event types, use RemoteEventProperties.EventType property.

    switch (properties.EventType)
    {
        case RemoteEventType.ItemAdding:
            break;
        case RemoteEventType.ItemUpdating:
            break;
        case RemoteEventType.ItemDeleting:
            break;
        default:
            break;
   }
When you finish writing Event Receiver code, deploy it to website.
You should have already Site URL in project properties set. Select Build > Deploy Solution. Visual Studio will connect to your website, ask you for login and password and then deploy solution. You will have to confirm, that you trust this app.

More reading on MSDN:
[3] Bing Video - Remote event receivers in SharePoint 2013 demo (video tutorial for preview version of SharePoint15)