Mittwoch, 31. März 2010

Sharepoint Items.Count, Count

Folgenden Fehler hatten wir heute bei der Programmierung eines Jobs, welcher vom Sharepoint Timer Dienst ausgelöst wird. Es wurde gegen Sharepoint programmiert, dabei eine Liste ausgelesen. Der Rückgabewert hatte im Debugmodus items = 2 und items.Count = null oder 0. D.h. eigentlich hat er über die Query etwas gefunden, man kann aber nicht iterieren, da nichts angezeigt wird. Folgender Fehler steckt hinter diesem Zustand. PERMISSIONS! In dem obigen Fall hatte der User nicht genügend Berechtigungen und da nützt es nichts den Code mit RunWithElevatedPrivilages laufen zu lassen. In die Liste gehen, dort dem User die nötigen Berechtigungen geben und es läuft. Sharepoint nutzt den System Account wenn mit dem Timer Dienst operiert wird. D.h. man sollte diesem "Nutzer" die korrekten Berechtigungen auf die Liste geben. Normalerweise würde man erwarten, dass man keinen Rückgabewert erhält, wenn Berechtigungen fehlen, aber es scheint, dass es immer einen Rückgabewert gibt, nur einmal ist er nicht aufrufbar.

The following error showed up today, while working on developing a job, that was supposed to be called from the Sharepoint Timer service. We developed against Sharepoint, in reading out a list. The return value of the code in the debug mode was items = 2, items.count = null oder 0. That means that the query worked and it found something, but you could not iterate through the result. Following error was the reason. PERMISSIONS! In our case the user did not have the correct permissions and to RunWithEvelatedPrivilages does not help either. You need to go to the list and give the user the correct permissions. You should be aware that a system account is used to run the Timer service. That means give the user the right permissions on the list. Usually you would expect, that it does not return any value, when you don't have the right permissions, but it seems, there is always a return value. When having not the correct permissions you can't access it.

Freitag, 19. März 2010

Guid im webpart

In einem Webpart muss man eine Guid angeben, jedoch, welche soll das sein. Hierzu einfach die Applikation erstellen und versuchen zu veröffentlichen und schon zeigt einem die Fehlermeldung den Guid an, welchen man verwenden sollte.

When creating a new webpart you are supposed to insert a guid into some files. But which one should you insert? Therefore just build and deploy your webpart and the error message will display a guid, that you should use.

Cannot import webpart

Bin gerade an meinen ersten Versuchen mit Sharepoint 2010. Eine neue Instanz und eigene Sitecollections erstellt. Um sich mit den Listen vertraut zu machen wollte ich ein Visual Webpart erstellen und dort ein wenig probieren. Doch das erstellen eines Webparts mit Visual Studio 2010 RC und dem Deployment auf Sharepoint 2010 war nicht so einfach wie ich dachte. Zwar ist das Deployment generel einfacher wie Sharepoint 2007, jedoch gibt es noch ein paar kleine "Bugs". Ein Fehler, welcher mich Stunden gekostet hat war "Cannot import webpart". In einem Blog habe ich ein Vorgehen entdeckt, wie man herausfinden kann, was an einem Webpart fehlerhaft ist, da die Exceptions in Sharepoint nicht gerade aussagekräftig ist.
1. Site actions -> Site settings -> Galleries -> Webparts
Dort muss das Webpart enthalten sein, ist es das nicht, besteht bereits der
Fehler beim Deployment.
2. Wenn man in der Gallery das Webpart direkt anklickt, müsste es sichtbar sein.
Jetzt kann es sein, dass bei Punkt 2 schon eine Fehlermeldung erscheint. Bei mir hat VS 2010 einfach Probleme mit der Versionierung. Hierzu folgendes beachten:
- Feature1.Template.xml, hier muss die Version und Guid die gleiche sein wie in
der AssemblyInfo.cs (.vb)
- [Name].webpart. In dieser Datei befindet sich unter type ein Placeholder,
welcher von VS generiert wird. Am besten diesen ersetzen durch statische
Werte (bei mir wurde hier immer die falsche Version generiert).
$SharePoint.Project.AssemblyFullName$ ersetzen durch ->
[Assemblyname], Version=[meine aktuelle Version], Culture=neutral
When Feature, Webpart und AssemblyInfo Datei die gleiche Version und Id haben, dann einfach Deployment erneut durchführen und manuell nochmals AppPool und IIS neu starten.
Im GAC (Windows -> assemblies) anschliessend nachsehen ob die Assembly kopiert wurde und die richtige Version hat. Im web.config der Sharepoint Webapplikation sollte die Assembly noch registriert sein.

Wenn alle diese Punkte beachtet wurden, sollte man zurück zu Punkt 2 und nochmals in der Webpart Gallery nachsehen, ob man das Webpart darstellen kann. Wenn ja, dann müsste es auch möglich sein das Webpart in der Seite einzufügen.


I am currently doing my first steps in Sharepoint 2010. Installed a new instance and created a site-collection. To get in touch with the lists and different actions, I created a visual webpart and wanted to play around in the code-behind.
But the creation of the webpart with VS 2010 RC and the deployment to Sharepoint 2010 was not that easy as I thought. Although deployment is now easier then Sharepoint 2007, still there seem to be some little "bugs". One error that required hours of bug fixing was "cannot import webpart". In a blog I found a very good introduction with steps to follow, when errors like that happen, because Sharepoint does not throw informative exceptions.
1. site actions -> site settings -> galleries -> webparts
There the webpart must be listed, when you deployed correctly. If it is not
listed, then something went wrong with deployment.
2. When clicking the webpart in the gallery, then the webpart is supposed to
display it's content. Now it is possible, that you already have an error now.
In my case VS 2010 had problems with the different versions. You should consider the following things:
- Feature1.Template.xml, here you need to have the same version as in the
AssemblyInfo.cs (.vb)
- [Name].webpart. In this file you have a placeholder, where VS generates the
version and some other things (in my case a wrong version has been generated).
$SharePoint.Project.AssemblyFullName$ replace with ->
[Assembly-name], Version=[your current version], Culture=neutral
When feature, webpart and assemblyinfo files do have the same version and Id, then deploy again and restart the application pool and iis manually.
In the global assembly cache (Windows -> assemblies) you should check if the assembly was deployed and if it has the correct version number. In the web.config of your sharepoint web-application this assembly is supposed to be registered as well.

When you checked all those things, then go back to number 2 and check once again if you can display the webpart in the gallery. If it is so, then you might be able to insert the webpart to your page.

Donnerstag, 4. März 2010

Going Sharepoint

Seit dem 1. März arbeite ich als Software Engineer bei der 4 Screen in Luzern. Meine neue Aufgabe und Herausforderung dort wird Sharepoint 2010 sein. Aus diesem Grund werde ich vermehrt in Zukunft Sachen zum Thema Sharepoint posten. Meine ersten Schritte, Fehler, etc.
Since March 1st I am working as a software engineer at 4 Screen in Lucerne. My new job and challange in future will be Sharepoint 2010. That will be the reason, why I will post more about Sharepoint in future. To leave some facts about my first steps, errors, etc.