Home Blog Page 10

[SharePoint 2010 – Developpement] Create User Control in SharePoint 2010 MasterPage

2

Today we need to create a user control that modify SharePoint Logo behaviour :
-We want to redirect the user to a site if the user is in a subsite

Procedure :

Add a UserControl in your SharePoint Visual Studio project

  1. Create a new element in visual studio, it will create files in ControlTemplates

image
Deploy the project
Go to “C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATECONTROLTEMPLATES” in order to see the full link of your userControl that you are gonna use in the next step
Reference your UserControl in the masterPage thanks to, and adapt the link :

   1: <%@ Register Src="~/_controltemplates/yourprojectName/Logos.ascx" TagName="Logos" TagPrefix="uc1" %> 

Reference the userControl in the masterPAge :

   1: <uc1:Logos id="Logos1" runat="server"> </uc1:Logos >        

Code the user control thanks to the .cs

How to debug a user control :

It’s possible to debug the user control, by attaching all Sharepoint Processus (see CKSDev Extension for visual studio)

image

[SharePoint 2010 – Developpement Informations] SPSecurity.RunWithElevatedPrivileges informations

0

SPSecurity.RunWithElevatedPrivileges launch the code with the administrator account of SharePoint.
Thought it could tell you during the execution : “Access denied” or :

UnauthorizedAccessException was unhandled by user code
0x80070005

Make sure you have sufficient privileges to access this resource. If you are attempting to access a file, make sure it is not readonly…

Make sure you re-open a new SPSite inside the SPSecurity.RunWithElevatedPrivileges in order to get the authorization of the administrator.

 

Example in a feature receiver :

 

   1: SPSecurity.RunWithElevatedPrivileges(delegate()
   2:             {
   3:                 using (SPSite site = new SPSite(properties.List.ParentWeb.Site.Url))
   4:                 {
   5:                     using (SPWeb web = site.OpenWeb(properties.List.ParentWeb.Url))
   6:                     {
   7:                         SPList List = properties.List;
   8:
   9:                         try
  10:                         {
  11:                             this.EventFiringEnabled = false;
  12:                             base.ItemAdded(properties);

[SharePoint 2010 – Developpement] The file is not extracted, it has to be extracted before modifications (Le fichier n’est pas extrait, il doit être extrait avant d’être modifié)

0

In my code, i got the SPLIMITEWebPartManager object, before the page checkout.

Actually, you’ll have to first :

  1. CheckOut the page
  2. Get the SPLimitedWebPartManager

This post explain how to do it

http://blogs.edwardwilde.com/2009/11/29/splimitedwebpartmanager-savechanges-throws-microsoft-sharepoint-webpartpages-webpartpageuserexception-the-file-is-not-checked-out/

———————————————–

Dans la page de code, je récupérais SPLIMITEWebPartManager avant le checkout de la page en question.
Il faut d’abord :

  1. Faire le checkout de la page
  2. Recuperer l’objet SPLimitedWebPartManger

Ce post explique la manipulation

http://blogs.edwardwilde.com/2009/11/29/splimitedwebpartmanager-savechanges-throws-microsoft-sharepoint-webpartpages-webpartpageuserexception-the-file-is-not-checked-out/

[Windows 2008] Activer l’audio et le wifi sur windows server 2008 / Enable Audio and wireless on windows server 2008

0

Bon nombres de personnes utilisent windows server 2008 comme systeme utilisateur, ainsi ils ont besoin des fonctionnalités d’un systeme d’exploitation standard telles que le wifi et l’audio.

Ci dessous, voici comment activer l’audio et le wifi, une fois les pilotes du systeme installés.

WIFI :

  • Dans le gestionnaire du serveur (démarrer), 
  • aller dans fonctionnalités et 
  • Activer une fonctionnalité du serveur nommée “Service de reseau local sans fil”

AUDIO :

  • Dans demarrer / executer, taper services.msc
  • Activer un service Windows nommé “audio windows” ou “windows audio” en anglais, 
  • Selectionner demarrage automatique

Le son et le wifi fonctionneront

[SharePoint 2010 – Developpement] Add current user to person field default value with event receiver ItemAdding–SharePoint 2010

1

I wanted to set a person field default value with my current user, but that doesnt exist in sharepoint.
What i did is :

  • I created an event receiver
  • I checked if it was my library
  • Then i set the person value thanks to the ItemAdding event firing
   1: /// <summary>
   2:        /// An item is being added.
   3:        /// </summary>
   4:        public override void ItemAdding(SPItemEventProperties properties)
   5:        {
   6:            SPSecurity.RunWithElevatedPrivileges(delegate()
   7:            {
   8:                try
   9:                {
  10:                    this.EventFiringEnabled = false;
  11:                    base.ItemAdded(properties);
  12:                    if (properties.List.RootFolder.Name == "libraryInternalName")
  13:                    {
  14:                        SPWeb web = properties.List.ParentWeb;
  15:                        SPList List = properties.List;
  16:                        //replace the id by your person colomn
  17:                        SPField fld = List.Fields[new Guid("03457d42-31a3-4088-b9af-4e3f2e368545")];
  18:                        SPUser usr = web.CurrentUser;
  19:                        SPFieldUserValue defValue = new SPFieldUserValue();
  20:                        defValue.LookupId = usr.ID;
  21:                        fld.DefaultValue = defValue.ToString();
  22:                        fld.Update();
  23:                        List.Update();
  24:                    }
  25:  
  26:                }
  27:                catch (Exception)
  28:                {
  29:                }
  30:                finally
  31:                {
  32:                    this.EventFiringEnabled = true;
  33:                }
  34:            });
  35:        }

[SharePoint 2010 – Developement – Debuging] Error while debugging (Erreur au debuguage de Visual studio)

0

While debuging i got that tricky message :

“The source file is different from when the module was built. Would you like the debugger to use i…”

French : “Le fichier source est différent de celui utilisé lors de la génération du module. Souhaiter_vous tout de même que le débogueur utilise ce fichier”

Context and solution

I’m programming a Sharepoint 2010 SOlution with visual studio and I have a project name

Common where i put all my classes.

I was in debuging mode in order to see what’s wrong with my code.

Actually i was using a dll from that common project in the package of the SharePoint project. This dll was the dll in the release folder.

But my project was build in the debug mode… All i had to do was to choose the right dll (from the debug project). Or to build the project in the Release mode.

 

Hope that help

[SharePoint 2010] [FR] Documents that does not appear in search results (Documents qui n’apparaissent pas dans la recherche)

0

En testant la fonctionnalités de recherche sur un site que j’ai crée avec des bibliothèques personnalisées (programmées en Event Receiver via les Features, un poste suivant traitera de comment créer une liste via Event receiver d’une feature, et ses avantages), je me suis rendu compte que la recherche n’indéxait pas les documents des bibliothèques.
C’est dû au fait que la propriété NoCrawl de l’object SPList etait à true, ce qui a pour résultat de ne pas indéxer le contenu de la bibliothèque.
image

Exemple :

   1: SPList list = web.List[“Liste personnalise”];
   2:  
   3: list.NoCrawl = true;
   4:  
   5: list.update();

Il faut passer la propriété à false pour autoriser l’indéxation par le service de recherche SharePoint

   1: SPList list = web.List[“Liste personnalise”];
   2:  
   3: list.NoCrawl = false;
   4:  
   5: list.update();

[SharePoint – Developpement – Debug] [FR] How to debug a Site Definition – SharePoint 2010

0

Cela peut être utile de debuger une site definition étant donné que celle ci est fait d’un fichier onet.xml.
Pour cela :
-Poser des points de debugage
-Effectuer dans visual studio un CTRL+ALT+P, et selectionner les processus w3…, cliquez sur Attach.
Créez maintenant la site definition, le debugueur est maintenant mis en place

[TFS 2010] Install TFS for Sharepoint 2010 : Error can’t create site based on template STS#0 for 1033

0

I got that error when i tried to install TFS english version on a Sharepoint French Version.
To fix that problem, install the English language pack for SharePoint 2010 Server.

[SharePoint 2010 – Developpement] Publish and approve file programmatically sharepoint 2010

0

I created a module which deploy a file (itemStyle for a ContentQueryWepPart), and i wanted to publish and approve it directly programmatically.
In the feature of your module :

  • Create an event Receiver
  • Add this code :
   1: public override void FeatureActivated(SPFeatureReceiverProperties properties)
   2: {
   3:     publishItemStyle(properties);
   4: }
   5:  
   6: private void publishItemStyle(SPFeatureReceiverProperties properties)
   7: {
   8:     try
   9:     {
  10:         SPWeb web = (SPWeb)properties.Feature.Parent;
  11:         SPFile file = web.GetFile("Style Library/Xsl Style Sheets/ItemStyle.xsl");
  12:  
  13:         if (file.Level == SPFileLevel.Checkout)
  14:             file.CheckIn("", SPCheckinType.MajorCheckIn);
  15:         if (file.Level == SPFileLevel.Draft)
  16:         {
  17:             if (file.DocumentLibrary.EnableModeration) file.Approve("");
  18:             else file.Publish("");
  19:         }
  20:         file.Update();
  21:     }
  22:     catch (Exception e)
  23:     {
  24:     }
  25: }

Hope this help,