Monday, 25 November 2013

Don't use SPList.Items, use GetItems() instead

private static void GetItemsFromList()
{
    //from MDSN: It is best practice is to use one of the GetItem* methods of SPList to return a filtered collection of items.

    using (SPSite site = new SPSite(webUrl))
    {
        using (SPWeb web = site.OpenWeb())
        {
            SPList list = web.GetList(ListUrl);  //my list has 2 items
            Console.WriteLine(list.ItemCount);   //returns 2
            Console.WriteLine(list.Items.Count); //returns 0

            foreach (SPListItem item in list.Items)
            {
                // will not go inside loop, because list.Items is empty
            }

            for (int i = 0; i < list.ItemCount; i++)
            {
                var item = list.Items[i];  //will cause ArgumentOutOfRangeException
            }

            var items = list.GetItems(new SPQuery());  //returns all items
        }
    }
}

Wednesday, 11 September 2013

Crystal Reports: word wrap

How to make long text in field wrap automatically? (some screenshots in German)

Right-click on field -> Format Object

In General tab select variable size

And make field tall enough to fit more than one line of text

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.

Wednesday, 7 August 2013

VPN broke my SharePoint

When I navigated to my SharePoint site, I saw this message:
This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.
The reason for this was, I installed Cisco VPN on my server in order to be able to access internal network and work with TFS (in 192.168.x.x range).
Unfortunately, SQL Server is on another private network (10.x.x.x range). And as result, it could not be found by SharePoint server.

Disconnecting from VPN solved my problem.

Tuesday, 6 August 2013

Always run Visual Studio as administrator

Here I will show how to set Visual Studio to always run as administrator under Windows Server 2012 or Windows 8.

1. Pin VS to taskbar
2. Right click on VS icon

3. Right click on Visual Studio 2012

4.  Select Properties. Go to Compatibility
5.  Select "Run this program as an administrator".


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

Monday, 17 June 2013

Change Photoshop language to English

I installed localized version of Photoshop CS6 (this tutorial works well with previous versions too).
Problem is, that all online tutorials are based on English version. So I want to change my UI language.

Go to where you installed Photoshop -> Locales -> language folder -> Support Files
eg.
C:\Program Files\Adobe\Adobe Photoshop CS6\Locales\pl_PL\Support Files
Then find file "tw10428.dat" and change it's extention to ".bak". Restart Photoshop.

Now, because Photoshop cannot find your localized language, it will display menus in English.

Saturday, 8 June 2013

Aktualizacja do Windows 8

Troche z opóznieniem, ale za chwile opisze, jak przebiega aktualizacja systemu Windows 7 do Windows 8.

System instaluje na 32-bitowym Win 7. To niestety pozostalosc po dawnej instalacji. W któryms artykule opisywalem problem z zainstalowaniem Developer Preview w wersji 64-bit i tak juz zostalo. Pózniej juz nie chcialo mi sie instalowac calkowicie od nowa systemu tylko dla zmiany wersji. 
Jak pewnie wiecie, aktualizowac mozna tylko 32 do 32-bit, a 64 do 64-bit.

Instalacja jest niesamowicie prosta. Mam pobrany (korzystam z MSDN) obraz plyty instalacyjnej. Montuje go za pomoca Virtual Clone Drive (po raz ostatni, Win 8 ma te funkcje juz wbudowana). Uruchamiam setup. 

Przygotowanie trwa doslownie 8 minut. Mam 3 opcje aktualizacji do wyboru:
  • instalacja z zachowaniem ustawien i aplikacji
  • instalacja tylko z zachowaniem ustawien
  • czysta instalacja. 
Wybieram pierwsza opcje. Okazuje sie, ze musze pozbyc sie MS Security Essentials. Nie sa kompatybilne z Win 8. Nastepnie wykonuje restart.

Po restarcie, mimo ze spodziewalem sie instalatora, znów otwiera sie Windows 7. Instalator wyswietla pytanie, czy chce kontynuowac od ostatniego momentu. Dopiero w tym momencie uruchamia sie pelnoekranowy instalator i zaczyna sie kopiowanie plików. 

Ta czesc instalacji trwa najdluzej. Razem ze sprawdzeniem sprzetu i "przygotowaniem do pierwszego uruchomienia" mija dokladnie 1 godzina i 45 minut.

Potem pozostaje juz tylko wybrac kolory systemu i siec W-LAN. Szkoda, ze w tym momencie nie mozna skorzystac z automatycznego wysylania hasla, które jest dostepne w niektórych routerach. Nie pamietam, wiec stwierdzam, ze podam pózniej. Niespodzianka bylo, ze Windows 8 przejal ustawienia i znal juz haslo do mojej sieci.
Nastepnie system pyta o ustanowienie hasla uzytkownika i adres e-mail, aby automatycznie skonfigurowac program pocztowy. Akurat ten krok pomijam.

Znów czekam. Tym razem tylko 3 minuty, w tym czasie ekran wyswietla mi wszystkie kolory teczy. Po chwili otwiera mi sie menu Start. System jest wreszcie gotowy do pracy.

Udalo sie, Windows 8 zostal zainstalowany.

Podsumowujac: Windows 8 instaluje sie dziecinnie latwo, ale trwa to cale wieki.

Thursday, 6 June 2013

Missing ACPI Driver

Zainstalowałem Windows 8 na netbooku ASUS Eee PC 1201N.
Natychmiast po aktualizacji do Win 8 zaczął wyskakiwać komunikat "Missing ACPI Driver". Jest to spowodowane błędnym sterownikiem klawiszy skrótów (te małe niebieskie ikonki na klawiaturze) w ASUSie.

Aby naprawić ten błąd, należy najpierw odinstalować stary sterownik.
Po restarcie wyszukaj na stronie producenta sterowników do ASUS 1225B. Można wybrać Windows 8 i pod "Other" będzie do pobrania "Hotkey services". Pobierz i zainstaluj.

Wpis pochodzi z bloga http://windows8betatest.blogspot.com/

Friday, 5 April 2013

Animated tile-style hyperlinks

I must admit, I begin to love jQuery. I am not JavaScript developer, yet jQuery is so easy, that even I can use it.

In this post I will explain how to create animated, scrollable box with alternating links and images. Just like this one:


1.       Start by adding these scripts inside body of your page:

    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.cycle/2.88/jquery.cycle.all.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
   <script type="text/javascript">

        $(document).ready(function () {
            var randomDelay = function () {
                var min = 1000;
                var max = 1500;
                var wait = Math.round(Math.random() * (max - min) + min);

                return wait;
            };

            $('.animated-tile').cycle({
                fx: 'scrollDown',
                easing: 'easeOutBounce',
                speed: 3000,
                delay: -3000,
                timeoutFn: randomDelay,
                random: 0,
                pause: 1,
            });
        });

    </script>

Here, in randomDelay function, set minimum and maximum time in milliseconds.

2.      Put div section where the box will be:
<div class="animated-tile" style="position: relative; width: 110px; height: 110px; overflow: hidden;">
Width and height should be the same as dimensions of images to cycle.

3.       Put multiple links with images inside. That's it!
<a href="http://goleszympansy.pl>
   <img src="myimage.jpg" height="110px" width="110px" border="0px">
</a>

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).


Tuesday, 22 January 2013

Crystal Reports: page orientation

Right-click on report page:
Choose Design -> Page Setup -> Orientation

Saturday, 19 January 2013

Autofokus w Nikon D7000

Ujęcie zarejestrowane aparatem Nikon D7000.
Nowe Nikony mają funkcję ciągłego autofokusu podczas nagrywania. Jak ta funkcja sprawdza się w praktyce, można zobaczyć na poniższym video.

  • jeśli filmuję z ręki, aparat łatwo "gubi" ostrość. Żeby ją odnaleźć czasami przeszukiwany jest nawet cały zakres
  • autofokus hałasuje. Nawet na nagraniu cały czas słychać silnik.