Donnerstag, 21. Oktober 2010

Custom Field Type -> User : <Field Name="ParentType">User</Field>

Wenn man ein Custom Field Type des ParentTypes User erstellen will, dann geht man vor wie bisher, nur an zwei Stellen müsste man etwas ändern.

1. fldtypes_[your name].xml
Dort muss man den folgenden ParentType definieren:
<Field Name="ParentType">User</Field>

2. FieldControl verlangt beim get der überschriebenen Methode Value ein gewisses Format [Sharepoint UserId];#[Sharepoint UserName] als String.
public override object Value
{
get
{
return "1;#Mein Name";
}
}


Sharepoint UserId bzw. UserName erhält man wie folgt:
Aktueller User:
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.RootWeb)
{
SPUser oUser = oWebsite.CurrentUser;
oUser.Name; //Der Sharepoint UserName
oUser.ID; //Die Sharepoint UserId
}


Ein User aus einer Gruppe:
using (SPSite spSite = new SPSite("[URL zu meiner Sharepointinstanz]"))
{
using (SPWeb spWeb = spSite.RootWeb)
{
foreach (SPUser user in spWeb.SiteGroups["[Mein Gruppenname]"].Users)
{
user.Name;
user.ID;
}
}
}


3. Ihre Field Klasse erbt bei normalen Custom Field Types von der Basisklasse SPField. In diesem Fall muss es SPFieldUser sein. Der restliche Code bleibt gleich. Wenn man einen Defaultwert setzen will, kann man die dazugehörige Eigenschaft überschreiben.
public class [Ihr Name]Field : SPFieldUser
{ ...

HINWEIS: Wenn Sie SPField als Basisklasse benutzen, dann bleibt der Wert in der Liste leer.


If you want to create a custom-field-type of parent-type User, then you just create your custom-field-type like any other and make changes at two spots.

1. fldtypes_[your name].xml
There you have to define the following ParentType:
<Field Name="ParentType">User</Field>

2. FieldControl requires a special format in the get function of the overridden method Value. [Sharepoint UserId];#[Sharepoint UserName] as string.
public override object Value
{
get
{
return "1;#My name";
}
}


You can get the values of Sharepoint UserId or UserName like this:
Current user:
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.RootWeb)
{
SPUser oUser = oWebsite.CurrentUser;
oUser.Name; //The Sharepoint UserName
oUser.ID; //The Sharepoint UserId
}


User from a specified group:
using (SPSite spSite = new SPSite("[URL of my Sharepoint-instance]"))
{
using (SPWeb spWeb = spSite.RootWeb)
{
foreach (SPUser user in spWeb.SiteGroups["[My group-name]"].Users)
{
user.Name; //The Sharepoint UserName
user.ID; //The Sharepoint UserId
}
}
}


3. Usual custom-field-types inherit from the base-class SPField. In this case your class needs to inherit from SPFieldUser. The rest of the code remains the same. If you want to set a default-value, then you need to override the property DefaultValue.
public class [Your name]Field : SPFieldUser
{ ...

HINT: If you do use SPField as the base class, then the value in the list will remain empty.

Mehrere SP.UI.ModalDialog.showModalDialog - CallBack

Wenn man mehrere SP.UI.ModalDialog.showModalDialog Fenster auf einer Seite platziert, ist es wichtig, dass die Callback Methoden unterschiedlich heissen. Ansonsten funktioniert immer nur ein Dialog Callback. Deshalb in den Properties des Dialogs immer einen anderen Methodennamen verwenden.

If you are using multiple SP.UI.ModalDialog.showModalDialog windows on your page, be aware to have different callback methods defined. Otherwise there will be just one callback working. Therefore set in the properties of your dialog always a different method.

Dialog 1:

function OpenDialog1()
{
var options1 = {
url: '/_layouts/MyDialog.aspx',
title: 'MyDialog',
allowMaximize: false,
showClose: true,
width: 400,
height: 400,
dialogReturnValueCallback: DialogCallback1 };

SP.UI.ModalDialog.showModalDialog(options1);
}

function DialogCallback1(dialogResult, returnValue) {
[Your code on callback]
}

Dialog 2:

function OpenDialog2()
{
var options2 = {
url: '/_layouts/MySecondDialog.aspx',
title: 'MySecondDialog',
allowMaximize: false,
showClose: true,
width: 400,
height: 400,
dialogReturnValueCallback: DialogCallback2 };

SP.UI.ModalDialog.showModalDialog(options2);
}

function DialogCallback2(dialogResult, returnValue) {
[Your code on callback]
}


Es existiert noch eine andere Schreibweise ->
There is also another way of defining the dialog ->

Dialog 1:

function OpenDialog1()
{
SP.UI.ModalDialog.showModalDialog(options);
var options1 = SP.UI.$create_DialogOptions();
options1.url = '/_layouts/MyDialog.aspx';
options1.width = 400;
options1.height = 400;
options1.allowMaximize = false;
options1.showClose = true;
options1.dialogReturnValueCallback = DialogCallback1;

SP.UI.ModalDialog.showModalDialog(options1);");
}

function DialogCallback1(dialogResult, returnValue) {
[Your code on callback]
}

Dialog 2:

function OpenDialog2()
{
SP.UI.ModalDialog.showModalDialog(options);
var options2 = SP.UI.$create_DialogOptions();
options2.url = '/_layouts/MySecondDialog.aspx';
options2.width = 400;
options2.height = 400;
options2.allowMaximize = false;
options2.showClose = true;
options2.dialogReturnValueCallback = DialogCallback2;

SP.UI.ModalDialog.showModalDialog(options2);
}

function DialogCallback2(dialogResult, returnValue) {
[Your code on callback]
}

Mittwoch, 20. Oktober 2010

Timerjob does not fire

Wenn Sie einen Timerjob erstellt und deployed haben, jedoch dieser keine Funktion auszuführen scheint, dann liegt es evtl. daran, dass die Assembly nicht neu instanziert wurde. Hierzu unter Verwaltung -> Services -> Sharepoint Timer neu starten. Danach den Timerjob nochmals starten.

When you created and deployed a timer-job, this seems not to work or functionallity seems not to fire, then the reason might be that the assembly was not initialized properly. Therefore restart Administrative Tools -> Services -> Sharepoint Timer. Then run your timer-job again.

Freitag, 15. Oktober 2010

Import spreadsheet als Liste

Bei dem Import eines Spreadsheets als Liste in Sharepoint 2010 hatte ich folgende Fehlermledungen:
1. "Automation server can't creat object"
ActiveX Controls sind nicht aktiviert oder Sie verwenden nicht den IE.

2. "The specified file is not a valid spreadsheet or contains no data to import"
Gehen Sie im Internet Explorer unter Tools -> Internet Options -> Security -> Trusted Sites -> Sites (Button) und fügen Sie die Seite hinzu. Sollte es dort eine Fehlermeldung geben, dann die Checkbox uncheck, denn Sie wollen wahrscheinlich eine http:// Seite hinzufügen.


When importing a spreadsheet as a list in Sharepoint 2010 I had the following error-messages:
1. "Automation server can't creat object"
ActiveX controls are either not activated or you are not using the IE.

2. "The specified file is not a valid spreadsheet or contains no data to import"
Go to Internet Explorer under Tools -> Internet Options -> Security -> Trusted Sites -> Sites (Button) and add this site to your trusted sites. If there is also an error-message, then uncheck the checkbox below, because you are trying to add a http:// site.

Montag, 11. Oktober 2010

Sharepoint 2010 -> Javascript API window dialog

Wer in seiner Sharepointseite ein windows bzw. dialog selbst erstellen und öffnen will, der muss lediglich auf ein wenig Sharepoint API zurückgreifen:

If someone wants to use the window/dialog of Sharepoint in his Sharepoint instance, you can use the Sharepoint API like this:

<script type="text/javascript">
function MyDialog() {
var thisdialog = SP.UI.$create_DialogOptions();
thisdialog.url = "/_layouts/DialogDemo/MyDialog.htm";
thisdialog.width = 400;
thisdialog.height = 300;
SP.UI.ModalDialog.showModalDialog(thisdialog);
}
</script>


More information can be found here (thanks to the authors):
External blog
External blog

Mittwoch, 6. Oktober 2010

Incompatible Web Part markup detected. Use *.dwp Web Part XML instead of *.webpart Web Part XML.

Wenn Sie ein eigenes Webpart erstellt haben und oben genannte Fehlermeldung erhalten, dann liegt es daran, dass das Webpart von der falschen Klasse erbt. Sie muss von folgender Klasse erben:
System.Web.UI.WebControls.WebParts.WebPart
und NICHT:
Microsoft.SharePoint.WebPartPages.WebPart

If you get the above mentioned error message, then you inherit from the wrong class in your custom webpart. It is supposed to inherit from:
System.Web.UI.WebControls.WebParts.WebPart
and NOT:
Microsoft.SharePoint.WebPartPages.WebPar

Hier ein kleines Beispiel, wie man ein eigenes Webpart erstellt:
Here is a little example how to create your custom webpart:
Link 1