IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SharePoint .NET Discussion :

créer un sous site sans passer par "Actions du site>Créer un site"


Sujet :

SharePoint .NET

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut créer un sous site sans passer par "Actions du site>Créer un site"
    Bonjour,

    Je travail sur un projet dans lequel il faudrait qu'un administrateur puisse créer un site (dont le modèle est défini à l'avance, le nom et l'adresse sont définis de manière itérative). Je pensais pour cela créer dans une page de gestion du site une Web Part avec un bouton de création de site (par la suite il faudra que des documents soient placés dans le site créé automatiquement) qui créé donc le site comme je le souhaite (le nom et l'adresse contiennent un numéro qui est incrémenté (+1) à chaque création de site).

    Cependant je ne parviens pas a créer un bouton sur une Web Part (j'ai essayé des morceaux de codes C# trouvés dans des tuto), d'autre part je ne sais pas comment faire pour que le programme remplisse automatiquement l'étape de choix du nom, de l'adresse et du modèle de site.

    Je suis débutant en ce qui concerne le développement de Web Parts et pour l'instant, à part des "Hello Sharepoint" ... je n'ai pas réussi à faire grand chose. Je suis donc preneur si quelqu'un a des conseils sur ce point... (tout seul je galère)

    Si quelqu'un a une piste ...

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 1 519
    Points : 1 663
    Points
    1 663
    Par défaut
    Pour ce qui est des boutons tu peux utiliser un SPLinkButton.

    Dans ton CreateChildControls tu fais :
    SPLinkButton myButton = new SPLinkButton();
    myButton.ImageUrl = "url"; (pour avoir une image à ton bouton)
    myButton.Text = "texte"; (pour mettre du texte à ton bouton)
    this.Controls.Add(myButton); (pour afficher le bouton dans ton webpart)

    Ensuite tu peux utiliser le .Click pour déterminer ce qui se passe au clic sur ton bouton.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    Je n'ai pas accès à SPLinkbutton... voici une copie de ma page
    Images attachées Images attachées  

  4. #4
    Membre averti
    Inscrit en
    Décembre 2006
    Messages
    264
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 264
    Points : 311
    Points
    311
    Par défaut
    As-tu fait un ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    using Microsoft.SharePoint.WebControls

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    cette fois ci cela marche, le code compile bien mais j'ai une erreur sur ma page quand j'ajoute le web part:

    Unable to add selected web part(s)

    WebPartPerso: a Web Part or a Web Form Control on this page cannot be displayed or imported. The type is not registered as safe.

  6. #6
    Membre averti
    Inscrit en
    Décembre 2006
    Messages
    264
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 264
    Points : 311
    Points
    311
    Par défaut
    Tu dois définir ton webpart comme un composant sûre. Ca se passe dans le web.config de ton application. La directive est <safecontrol ..... />. Regarde ici

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    Il me semble que WSPBuilder fait cela lors du déploiement. Mais je vais vérifier, dans quel répertoire se trouve le web.config correspondant ? (je ne trouve plus celui qui m'intéresse)

  8. #8
    Membre expérimenté
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 1 519
    Points : 1 663
    Points
    1 663
    Par défaut
    C:\inetpub\wwwroot\wss\VirtualDirectories\n° du port

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    effectivement je n'ai plus l'erreur lors de l'ajout du Web Part .cependant, je ne vois aucun bouton dans mon Web Part

  10. #10
    Membre expérimenté
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 1 519
    Points : 1 663
    Points
    1 663
    Par défaut
    T'as fait un :
    this.Controls.Add(myButton);

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    oui je l'ai fait:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls.WebParts;
    using System.Windows.Forms;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
     
    namespace WebPartJeudi
    {
        [Guid("34806e9d-03ed-4025-a4eb-7561a45afb13")]
        public class WebPartFeature1 : Microsoft.SharePoint.WebPartPages.WebPart
        {
            private bool _error = false;
            private string _myProperty = null;
     
            [Personalizable(PersonalizationScope.Shared)]
            [WebBrowsable(true)]
            [System.ComponentModel.Category("My Property Group")]
            [WebDescription("Meaningless Property")]
            public string MyProperty
            {
                get
                {
                    if (_myProperty == null)
                    {
                        _myProperty = "Hello SharePoint test test deux\n";
                    }
                    return _myProperty;
                }
                set { _myProperty = value; }
            }
     
            public WebPartFeature1()
            {
                this.ExportMode = WebPartExportMode.All;
            }
     
            /// <summary>
            /// Create all your controls here for rendering.
            /// Try to avoid using the RenderWebPart() method.
            /// </summary>
     
            protected override void CreateChildControls()
            {
                if (!_error)
                {
                    try
                    {
     
                        base.CreateChildControls();
     
                        // Your code here...
                        this.Controls.Add(new LiteralControl(this.MyProperty));
     
                        SPLinkButton myButon = new SPLinkButton();
                        myButon.ImageUrl = "http://www.google.fr";
                        myButon.Text = "name";
                        this.Controls.Add(myButon);
     
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                    }
                }
            }
     
            /// <summary>
            /// Ensures that the CreateChildControls() is called before events.
            /// Use CreateChildControls() to create your controls.
            /// </summary>
            /// <param name="e"></param>
            protected override void OnLoad(EventArgs e)
            {
                if (!_error)
                {
                    try
                    {
                        base.OnLoad(e);
                        this.EnsureChildControls();
     
                        // Your code here...
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                    }
                }
            }
     
            /// <summary>
            /// Clear all child controls and add an error message for display.
            /// </summary>
            /// <param name="ex"></param>
            private void HandleException(Exception ex)
            {
                this._error = true;
                this.Controls.Clear();
                this.Controls.Add(new LiteralControl(ex.Message));
            }
        }
    }

  12. #12
    Membre expérimenté
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 1 519
    Points : 1 663
    Points
    1 663
    Par défaut
    Allons y pas à pas.
    En mettant ce code tu as bien le bouton qui s'affiche ?

    public WebPartFeature1()
    {
    }

    protected override void CreateChildControls()
    {
    SPLinkButton myButon = new SPLinkButton();
    myButon.Text = "name";
    this.Controls.Add(myButon);
    }

    Remarques
    myButon.ImageUrl = "http://www.google.fr";
    ce n'est pas correct car pour .ImageUrl tu dois mettre l'url d'une image et non d'une redirection.

    Le OnLoad n'est pour moi pas utile car tu fais déjà un CreateChildControls.

  13. #13
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    J'ai essayé ce code en commentant les bouts de mon code qui n'apparaissent pas ici mais je ne vois toujours pas de bouton...

  14. #14
    Membre expérimenté
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 1 519
    Points : 1 663
    Points
    1 663
    Par défaut
    T'as bien créé un projet Composant webpart de SharePoint ???

    Parce que par défaut en le faisant tu as les fonctions par défaut et en mettant
    SPLinkButton myButon = new SPLinkButton();
    myButon.Text = "name";
    this.Controls.Add(myButon);
    dans le CreateChildControls() ça fonctionne je l'ai testé.

  15. #15
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    Après avoir essayé de déployer le Web Part avec le code que tu m'a donné, je me suis rendu comte que le déploiement ne fonctionne pas, j'ai une erreur quand je vais dans Solution Management de l'administration central de mon Sharepoint:

    LITWAREDEMO : http://litwaredemo/ : SharePoint - 80 : Error: The copying of this file failed: feature.xml.
    This operation uses the SharePoint Administration service (spadmin), which could not be contacted. If the service is stopped or disabled, start it and try the operation again.
    LITWAREDEMO : http://litwaredemo:13300/ : SharePoint - 13300 : Error: The copying of this file failed: feature.xml.
    This operation uses the SharePoint Administration service (spadmin), which could not be contacted. If the service is stopped or disabled, start it and try the operation again.
    LITWAREDEMO : http://litwaredemo:28519/ : SharePoint Central Administration v3 : Error: The copying of this file failed: feature.xml.
    This operation uses the SharePoint Administration service (spadmin), which could not be contacted. If the service is stopped or disabled, start it and try the operation again.

    Quelque soit le Web Part que je déploi, j'ai ce type d'erreur (je ne l'avais pas avant ...) une idée ?

  16. #16
    Membre expérimenté
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 1 519
    Points : 1 663
    Points
    1 663
    Par défaut
    Y a peut être un service SharePoint à démarrer...

  17. #17
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 104
    Points : 38
    Points
    38
    Par défaut
    j'ai pourtant fais un iisreset donc je pensais avoir tout redémarré

Discussions similaires

  1. Réponses: 8
    Dernier message: 03/06/2012, 19h12
  2. 1&1 visualiser mon site sans passer par https
    Par kentinn07 dans le forum 1&1
    Réponses: 0
    Dernier message: 12/05/2011, 19h21
  3. Réponses: 6
    Dernier message: 06/09/2008, 10h57
  4. Réponses: 3
    Dernier message: 06/06/2008, 16h54
  5. Réponses: 10
    Dernier message: 24/02/2004, 12h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo