tag:blogger.com,1999:blog-27024855796115476222024-02-18T19:46:36.100-08:00Astuces au travailDéveloppement .NET, SQL ServerLusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.comBlogger29125tag:blogger.com,1999:blog-2702485579611547622.post-24949970471848381092011-09-14T13:45:00.000-07:002011-09-14T13:45:55.260-07:00Désormais, le contenu de ce blog est accéssible sur: <a href="http://lusiasiano.blogspot.com/">http://lusiasiano.blogspot.com</a>.<br />
<br />
<br />
Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-6473449230366808902010-10-21T01:38:00.000-07:002010-10-21T01:38:01.488-07:00Argument de publication ou de rappel non valide<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-family: Calibri;">Lors d'un développement d'une application web avec AJAX, j'ai rempli un contrôle <i style="mso-bidi-font-style: normal;">ListBox</i> avec AJAX.</span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-family: Calibri;">Il y a plusieurs appels AJAX sur la page avant <i style="mso-bidi-font-style: normal;">Postback</i> (que l’on clique sur le bouton pour enregistrement).</span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-family: Calibri;">Au moment de l’enregistrement, j'ai eu le message d'erreur suivant:</span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 10pt; line-height: 115%;"><span style="font-family: Calibri;">Argument de publication ou de rappel non valide. La validation d'événement est activée via <pages enableEventValidation="true"/> dans la configuration ou via <%@ Page EnableEventValidation="true" %> dans une page. Pour des raisons de sécurité, cette fonctionnalité vérifie si les arguments des événements de publication ou de rappel proviennent du contrôle serveur qui les a rendus à l'origine. Si les données sont valides et attendues, utilisez la méthode ClientScriptManager.RegisterForEventValidation afin d'inscrire les données de publication ou de rappel pour la validation.</span></span></i></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-family: Calibri;">Depuis <span style="mso-spacerun: yes;"> </span>ASP.NET 2.0 il y a une validation d'événement qui vérifie la requête POST pour s'assurer<span style="mso-spacerun: yes;"> </span>que l'événement de <i style="mso-bidi-font-style: normal;">Postback</i> est valide.</span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-family: Calibri;">La validation d'événement évite l'attaque qui renvoi <span style="mso-spacerun: yes;"> </span>des données par l'événement qui ne vient pas d’un contrôle enregistré sur la page</span></div>
<span style="font-size: 10pt; line-height: 115%;"><span style="font-family: Calibri;"><div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<b style="mso-bidi-font-weight: normal;"><u><span style="font-size: small;">Les solutions qui peuvent corriger le problème :</span></u></b></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-size: small;">1. Désactiver la validation d'événement (mais risque de sécurité) avec <span><em>EnableEventValidation = false</em>.</span></span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-size: small;">2. Utiliser la méthode d’Ajax <em>UpdatePanel</em> (Placer le contrôle <em>Listbox</em> dans <em>UpdatePanel</em> et déclencher la mise à jour <span style="mso-spacerun: yes;"> </span>pour ajouter/supprimer des éléments de <em>Listbox</em>). Le <em>viewstate</em> sera alors mis à jour et la validation d'événement passe.</span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-size: small;">3. Utiliser <em>Postback</em> pour ajouter/supprimer les items du contrôle <em>ListBox</em></span></div>
<span style="font-size: small;"><div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
J'ai réussi à ne plus avoir ce message d'erreur en vidant le contenu du contrôle <span style="mso-spacerun: yes;"> </span><i style="mso-bidi-font-style: normal;">ListBox</i> <span style="mso-spacerun: yes;"> </span>lors de l’envoi de formulaire. Le contrôle <i style="mso-bidi-font-style: normal;">ListBox</i> reste en même état avant et après <i style="mso-bidi-font-style: normal;">Postback</i>.</div>
<div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 8pt; mso-ansi-language: EN-US; mso-no-proof: yes;">document.forms[0].onsubmit = <span style="color: blue;">function</span>() {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 8pt; mso-ansi-language: EN-US; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>document.getElementById(<span style="color: #a31515;">'IdControle'</span>).options.length = 0;</span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-family: "Courier New"; font-size: 8pt; line-height: 115%; mso-no-proof: yes;">};</span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
</div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<br /></div>
<span style="font-size: 10pt; line-height: 115%;"><span style="font-family: Calibri;"><div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-size: 10pt; line-height: 115%;"><a href="http://stackoverflow.com/questions/228969/asp-net-invalid-postback-or-callback-argument-event-validation-is-enabled-usi"><span lang="EN-US" style="mso-ansi-language: EN-US;"><span style="color: purple;">http://stackoverflow.com/questions/228969/asp-net-invalid-postback-or-callback-argument-event-validation-is-enabled-usi</span></span></a></span><span lang="EN-US" style="font-size: 10pt; line-height: 115%; mso-ansi-language: EN-US;"></span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<span style="font-family: "Calibri", "sans-serif"; font-size: 10pt; mso-ansi-language: FR; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><a href="http://blogs.msdn.com/b/amitsh/archive/2007/07/31/why-i-get-invalid-postback-or-callback-argument-errors.aspx"><span style="color: purple;">http://blogs.msdn.com/b/amitsh/archive/2007/07/31/why-i-get-invalid-postback-or-callback-argument-errors.aspx</span></a></span></div>
</span></span></span></span></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-47751572455165156482010-10-07T14:01:00.000-07:002010-10-07T14:01:08.109-07:00Ajax sur Firefox : La fonction onreadystatechange n'est pas appelée<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">Sur un projet dans lequel on a utilisé l’Ajax, on a rencontré un problème de code qui fonctionne bien sur Internet Explorer mais pas sur Firefox. Le problème réside dans la fonction définie par l’attribut "onreadystatechange" qui n'est jamais appelée sur Firefox.</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<br />
<u><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">Ci-dessous le déroulement d'appel Ajax que l'on a fait initialement</span></u><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">:</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">-Instancier la classe XMLHttpRequest selon le navigateur.</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">-Définir la fonction qui doit être appelée dans l’attribut «onreadystatechange » (événement pour le changement d'état). </span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">-Ouvrir la connexion avec la méthode « open »</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">-Envoyer la requête sur serveur de manière synchrone.</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">-Vérifier si l’état est prête/les données sont disponibles ou reçues (l'état défini par l'attribut « readyState » est égale à 4)</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">-Vérifier si le statut est égal à 200 = OK, 404 si non trouvé.</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">-Exécuter la fonction définie par « onreadystatechange »</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span><br />
<br />
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">var req;</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">function Initialize()</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">{</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 1;"> </span>try</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 1;"> </span>{</span></div>
<div style="line-height: 9pt; margin-left: 35.4pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">// Version récente d’Internet Explorer</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 2;"> </span>req=new ActiveXObject("Msxml2.XMLHTTP"); </span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 1;"> </span> }</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 1;"> </span>catch(e1)</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> {</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 2;"> </span>try</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 2;"> </span> {</span></div>
<div style="line-height: 9pt; margin-left: 70.8pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">// Version plus ancienne d’Internet Explorer</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 3;"> </span>req=new ActiveXObject("Microsoft.XMLHTTP"); }</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 2;"> </span>catch(e2)</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 2;"> </span>{</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 3;"> </span>req=null;</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 2;"> </span>}</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">}</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">if(!req && typeof(XMLHttpRequest)!="undefined")</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">{</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"> </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"> <span style="mso-tab-count: 2;"> </span>req=new XMLHttpRequest(); // Firefox, Safari,..</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"> </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">}</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"> </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">}</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"> </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<br /></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">function Fonction1()</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">{</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span>Initialize();</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">if(req!=null)</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;">{</span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>/* 0= non initialisé, </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>si la connexion est déjà initialisée, on annule la requête HHTP</span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>*/</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span></span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">if (req.readyState != 0) </span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>req.abort();</span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt;"><span style="mso-spacerun: yes;"> </span></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt;"><span style="mso-spacerun: yes;"> </span></span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;">req.onreadystatechange = Fonction2;</span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>/* mode : POST/GET, </span></div>
<div style="line-height: 9pt; margin-left: 35.4pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>url : url où trouver les données,</span></div>
<div style="line-height: 9pt; margin-left: 35.4pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>type : true(asynchrone), false(synchrone)</span></div>
<div style="line-height: 9pt; margin-left: 35.4pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>*/</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"><span style="mso-spacerun: yes;"> </span>req.open(mode,url, type); </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>req.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); </span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>var data = "AJAX_QUERY= TestAjaxQuery" ;</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>req.send(data);</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">}</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">}</span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US;"></span></div>
<div style="line-height: 10pt; mso-line-height-rule: exactly;">
<span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 8pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;"><br />function Fonction2()<br />{<br /><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span>if (req.readyState == 4)<br /><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span>{<br /><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span>if (req.status == 200) // OK<br /><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span>{<br /><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 3;"> </span>Alert('Retour Ajax OK');<br /><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 2;"> </span>}<br /><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span>}<br />}</span><span lang="EN-US" style="font-family: "Arial", "sans-serif"; mso-ansi-language: EN-US;"><br /></span><span lang="EN-US" style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-ansi-language: EN-US; mso-bidi-font-family: Arial;">La fonction « Fonction2 » n’est jamais exécutée sur Firefox. </span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">Après les recherches, j’ai découvert que cette anomalie est reproductible pour l’appel synchrone sur Firefox et il s'agit d'un bug. <br /><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=412112">https://bugzilla.mozilla.org/show_bug.cgi?id=412112</a><br />Sur un appel synchrone, Firefox considère que la réponse d'Ajax est déjà arrivée et qu'il n'est pas nécessaire de vérifier l'état. Par conséquence, il n’est pas nécessaire de vérifier le changement d’état.<br /><br />Le code devient alors comme suit:</span></div>
<div style="line-height: 10pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;"><br /></span><span style="font-family: "Arial", "sans-serif"; font-size: 10pt;"><br /></span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;">function Fonction1()<br />{<br /> Initialize();<br /> if(req!=null)<br /> {<br /> /*0= non initialisé</span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>si la connexion est déjà initialisée, on annule la requête HHTP</span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>*/<br /> if (req.readyState != 0) <br /> req.abort(); </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;"><br /> /* mode : POST/GET,</span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;"><span style="mso-spacerun: yes;"> </span>url : url où trouver les données, </span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;">type : true(asynchrone), false(synchrone)</span></div>
<div style="line-height: 9pt; mso-line-height-rule: exactly; text-indent: 35.4pt;">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;">*/<br /> req.open(mode,url, type); <br /> req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');<br /> var data = "AJAX_QUERY= TestAjaxQuery";<br /> req.send(data);<br /> //req.onreadystatechange = Fonction2<br /> if (req.status == 200) // OK<br /> {<br /> <span style="mso-tab-count: 1;"> </span>Fonction2();<br /><span style="mso-spacerun: yes;"> </span>} <br /><span style="mso-spacerun: yes;"> </span>}<br />}</span></div>
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 9pt; mso-bidi-font-family: Arial;"><div style="line-height: 10pt; mso-line-height-rule: exactly; text-indent: 35.45pt;">
<br />function Fonction2()<br />{<br /><span style="mso-spacerun: yes;"> </span>Alert('Retour Ajax OK'); <br />}</div>
</span><span style="font-family: "Arial", "sans-serif";"><br /></span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;">Cette fois ci le code fonctionne sur Internet Explorer et sur Firefox.<br /><br /><u>Pour voir plus loin:</u><br /><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial;"><a href="http://www.onejohn.org/wpjohn/2008/05/firefox-bug-with-onreadystatechange/">http://www.onejohn.org/wpjohn/2008/05/firefox-bug-with-onreadystatechange/</a><br /><a href="http://lukav.com/wordpress/2007/04/12/firefox-firebug-and-synchronos-calls-problem/">http://lukav.com/wordpress/2007/04/12/firefox-firebug-and-synchronos-calls-problem/</a></span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"></span></span><div style="line-height: 10pt; mso-line-height-rule: exactly; text-indent: 35.45pt;">
<br /></div>
<div style="line-height: 10pt; mso-line-height-rule: exactly; text-indent: 35.45pt;">
<br /></div>
<div style="line-height: 10pt; mso-line-height-rule: exactly; text-indent: 35.45pt;">
<br /></div>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-23741619002704907442010-09-02T23:57:00.000-07:002010-09-02T23:57:42.105-07:00Google Map à partir de XML<span style="font-family: "Trebuchet MS", sans-serif; font-size: 85%;">Lors d’un projet j’ai eu l’occasion d’intégrer Google Map dans une application web.Le but de visualiser la dispersion des élèves d’une école dans le monde.</span><span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Les étapes à faire :</strong></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">1. Interroger le service Geocoder de Google afin d’obtenir les coordonnées de chaque pays.Je crée une classe nommée Geocodeur avec une méthode static et publique qui permet d’obtenir latitude et longitude d’un pays.</span><br />
<span style="color: #666666; font-family: "Trebuchet MS", sans-serif; font-size: 78%;">using System.Net;</span><br />
<span style="font-size: 85%;"><span style="font-size: 78%;"><span style="color: #666666; font-family: "Trebuchet MS", sans-serif;">public class Geocodeur</span></span></span><br />
<span style="font-size: 85%;"><span style="font-size: 78%;"><span style="color: #666666; font-family: "Trebuchet MS", sans-serif;">{</span></span></span><br />
<span style="font-size: 85%;"><span style="font-size: 78%;"><span style="color: #666666; font-family: Trebuchet MS;"> </span><span style="color: #666666; font-family: "Trebuchet MS", sans-serif;"> private static string _googleUri = “http://maps.google.com/maps/geo?q=”;<br />
// [CLE] est une clé propre à un domain obtenu en s’inscrivant sur Google </span></span></span><br />
<span style="font-size: 85%;"><span style="font-size: 78%;"><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif;"> //<a href="http://code.google.com/intl/fr/apis/maps/signup.html">http://code.google.com/intl/fr/apis/maps/signup.html</a></span></span></span></span><br />
<span style="font-size: 85%;"><span style="font-size: 78%;"><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif;"> private static string _googlekey = [CLE];<br />
private const string _output = "csv"; </span></span></span></span><br />
<br />
<span style="font-size: 85%;"><span style="font-size: 78%;"><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif;"> // Constituer l'url pour intérroger le service geocodeur de Google<br />
private static string getGeocodeUri(string adresse)</span></span></span></span><span style="font-size: 85%;"><span style="font-size: 78%;"><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif;"> {<br />
adresse = HttpUtility.UrlEncode(adresse);<br />
return string.Format("{0}{1}&output={2}&key={3}",_googleUri,adresse,_output,_googlekey);<br />
}<br />
<span style="font-size: small;"> </span><span style="font-size: x-small;"> </span><span style="font-size: xx-small;">// Intérroger le service de geocodeur de Google<br />
public static string getCoordonne(string adresse)</span></span></span></span></span><span style="color: #666666; font-family: "Trebuchet MS", sans-serif; font-size: xx-small;">{<br />
WebClient client = new WebClient();<br />
string uri = getGeocodeUri(adresse);<br />
byte[] datageo= client.DownloadData(uri);<br />
return System.Text.Encoding.ASCII.GetString(datageo);<br />
}</span><span style="font-family: "Trebuchet MS", sans-serif;"><br />
<span style="color: #666666;"><span style="font-size: x-small;"> </span><span style="font-size: xx-small;"> public Geocodeur()</span></span></span><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif;"><span style="font-size: xx-small;"> {</span></span></span><br />
<span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif;"><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif; font-size: xx-small;"> </span></span></span></span><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif;"><span style="color: #666666;"><span style="font-family: "Trebuchet MS", sans-serif; font-size: xx-small;"> }<br />
}</span></span></span></span><br />
<span style="font-size: xx-small;"><span style="color: #666666; font-family: "Trebuchet MS", sans-serif;">String strCoordonne = Geocodeur.getCoordonne(“France”);<br />
String strLat = strCoordonne.Split(',')[2];<br />
String strLng = strCoordonne.Split(',')[3];</span><br />
</span><span style="font-family: "Trebuchet MS", sans-serif;">2. Enregistrer ensuite ces coordonnées avec les informations à afficher pour chaque pays dans un fichier xml.<br />
Le fichier possède la structure ci-dessous:</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5358607634730696306" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrWK1_0ssN8sKXdR5yTKRxkmd1j4EMH8WQder1aZipNAd6PmaNT70Aj8NfOO2bscdo8mrHjF6khzWNLAO1TQzVgSIpbQWXdcjrBt6iZazNILWLV8XFeXn2DaJoLHWlTmpF9UOEluKa9XM/s400/xml.bmp" style="display: block; height: 70px; margin: 0px auto 10px; text-align: left; width: 400px;" /> </span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">3. Créer une page html qui héberge le Google map.<img alt="" border="0" id="BLOGGER_PHOTO_ID_5358604894501392082" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDTQuT_Nu-SdqRUZKIlmea2xHxN5I9mYpYM3ckxkZSCGSROFwaZKF3gNOvJpdKfHnGMx6RNwH2Yv_U9LMvyYlMGoDOdQxLWwxZBEKggiYx7ouKrndhl8Su0xHCukDAVsp_QIBoU8MM5nU/s400/html.bmp" style="cursor: hand; display: block; height: 118px; margin: 0px auto 10px; text-align: left; width: 407px;" /> 4. Dans le fichier javascript Geo.js, je charge le fichier xml créé précédemment :<br />
<span style="color: #333333; font-size: xx-small;">// Pour savoir si navigateur est ie6</span></span><br />
<span style="font-size: xx-small;"><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">var is_ie6 = ( window.external && typeof window.XMLHttpRequest == "undefined"); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">var iconeGrande = new GIcon();</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconeGrande.image = 'iconeGrande.png';</span><br />
<br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">// Résoudre le problème IE6 qui ne supporte pas l'image png avec transparent</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">if(is_ie6){ iconeGrande.image = 'iconeGrande.gif';}</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconeGrande.shadow = null;i</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">coneGrande.iconSize = new GSize(48, 48);</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconeGrande.shadowSize = null;</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconeGrande.iconAnchor = new GPoint(24,24);</span></span><span style="font-size: xx-small;"><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconeGrande.infoWindowAnchor = new GPoint(24,24);<br />
var iconePetite = new GIcon();</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconePetite.image = 'iconePetite.png';</span><br />
<br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">if(is_ie6){ iconePetite.image = 'iconePetite.gif';}</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconePetite.shadow = null;</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconePetite.iconSize = new GSize(32, 32); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconePetite.shadowSize = null;</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconePetite.iconAnchor = new GPoint(16,16);</span></span><span style="font-size: xx-small;"><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">iconePetite.infoWindowAnchor = new GPoint(16,16);<br />
var map;</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">var xml;</span></span><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"><br />
<span style="font-size: xx-small;">function initialiserGoogleMap(langue) </span></span><span style="font-size: xx-small;"><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">{ </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> map = new GMap2(document.getElementById("map_canvas")); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> map.setCenter(new GLatLng(33.8869170,9.5374990), 2, G_NORMAL_MAP); </span></span><span style="font-size: xx-small;"><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> map.addControl(new GLargeMapControl());<br />
GDownloadUrl("geolocalisation.xml", function(data,responseCode)</span><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> { </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> if(responseCode == 200) { xml = GXml.parse(data); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var markers = xml.documentElement.getElementsByTagName("marqueur"); </span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"> for (var i = 0; i < markers.length; i++)</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> { </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var icone; </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var id = markers[i].getAttribute("id"); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> // Si la France, on utilise grande icone </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> if(id == '1') { icone = iconeGrande; } </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> else { icone = iconePetite; } </span><br />
<br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var information; </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> if(langue == "fr") </span><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> {</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> information = markers[i].getAttribute("informationFr"); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> } </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> else</span><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> { </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> information = markers[i].getAttribute("informationEn"); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> } </span><br />
<br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var nombre = markers[i].getAttribute("nombre"); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var point = new GLatLng(parseFloat(markers[i].getAttribute("latitude"))</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> , parseFloat(markers[i].getAttribute ("longitude"))); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var marker = createMarker(point, nombre,information, icone); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> map.addOverlay(marker); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> } </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">} </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">else {</span></span><br />
<span style="font-size: xx-small;"><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> alert ('Erreur'); </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">} </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">});</span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">}</span></span><br />
<span style="font-size: xx-small;"><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">function createMarker(point, nombre, information,icone)</span><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">{ </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif;"> var marker = new GMarker(point, icone); </span></span><br />
<span style="font-size: xx-small;"><span style="color: #333333;"> <span style="font-family: "Trebuchet MS", sans-serif;">var html = information;</span></span></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: xx-small;">GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html, {beakOffset:03}); });</span> <br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif; font-size: xx-small;"> return marker; </span><br />
<span style="color: #333333; font-family: "Trebuchet MS", sans-serif; font-size: xx-small;">}</span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-10162624002325131572010-07-20T11:36:00.001-07:002010-07-20T11:41:03.539-07:00Installer le Framework .NET sur un poste client via code (sans être administrateur)<span xmlns=""></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">Lors d'un projet de migration des applications Winforms du .NET 1.1 vers .NET 3.5, on a réfléchi au moyen de déploiement du Framework .NET3.5 sur les postes d'utilisateurs. Les utilisateurs ne sont pas administrateurs sur les postes. Ils ne peuvent donc pas installer le Framework eux-mêmes. Le déploiement de l'application se fait par ClickOnce via un URL :</span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><strong>http:// [url]. [Domaine].com/[nomapplication].application</strong></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">Une possibilité était d'inclure le code d'installation de Framework .NET3.5 lors de lancement de l'application.</span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt; text-decoration: underline;"><strong>Les principes :</strong></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">1. Vérifier si le Framework .NET 3.5 est installé sur le poste client.</span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">2. Si Oui, installer l'application.</span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">3. Si Non, installer d'abord le Framework .NET 3 .5 en utilisant un profil administrateur, puis installer l'application.</span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><strong>Les étapes :</strong></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">1. J'ai défini dans le fichier de configuration le chemin vers l'exécutable du Framework .NET3.5, le nom ainsi que le mot de passe d'utilisateur qui installera l'application et l'url de l'application.</span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>……..</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em><appSettings></em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em><add key= "application" value="http://[URL application]\setup.exe"/></em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em><add key= "cmd" value="http://[URL application]\setup.exe"/></em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em><add key= "user" value="[Nom utilisateur]"/></em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em><add key= "pwd" value="[Mot de passé utilisateur]"/></em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em><add key= "domain" value="[Domaine utilisateur]"/></em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em></appSettings></em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>……</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">2. J'ai créé une classe qui contient une méthode permettant de lancer un processus sous le contexte d'un utilisateur. J'ai eu le code ci-dessous en cherchant sur internet.</span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">Pour voir plus loin : <a href="http://msdn.microsoft.com/en-us/library/ms682431(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms682431(VS.85).aspx</a></span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using System;</em></span><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using Microsoft.Win32;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using System.Runtime.InteropServices;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using System.Diagnostics;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>namespace Lanceur</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> /// </em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> /// Description résumée de CreateProcessWithLogon.</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> /// </em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public class CreateProcessWithLogon</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> {</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public const UInt32 Infinite = 0xffffffff;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public const Int32 Startf_UseStdHandles = 0x00000100;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public const Int32 StdOutputHandle = -11;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public const Int32 StdErrorHandle = -12;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public struct StartupInfo</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em> {</em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int cb;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public String reserved;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public String desktop;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public String title;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int x;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int y;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int xSize;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int ySize;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int xCountChars;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int yCountChars;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int fillAttribute;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int flags;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public UInt16 showWindow;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public UInt16 reserved2;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public byte reserved3;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public IntPtr stdInput;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public IntPtr stdOutput;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public IntPtr stdError;</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>} </em></span></div><div style="margin-left: 35pt;"><br />
</div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public struct ProcessInformation</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public IntPtr process;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public IntPtr thread;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int processId;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> public int threadId;</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
</div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>[DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public static extern bool CreateProcessWithLogonW(</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>String userName,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>String domain,</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>String password,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>UInt32 logonFlags,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>String applicationName,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>String commandLine,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>UInt32 creationFlags,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>UInt32 environment,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>String currentDirectory,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>ref StartupInfo startupInfo,</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>out ProcessInformation processInformation);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>[DllImport("kernel32.dll", SetLastError=true)]</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public static extern bool GetExitCodeProcess(IntPtr process, ref UInt32 exitCode);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>[DllImport("Kernel32.dll", SetLastError=true)]</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public static extern UInt32 WaitForSingleObject(IntPtr handle, UInt32 milliseconds);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>[DllImport("Kernel32.dll", SetLastError=true)]</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public static extern IntPtr GetStdHandle(IntPtr handle);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>[DllImport("Kernel32.dll", SetLastError=true)]</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public static extern bool CloseHandle(IntPtr handle);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public static void Launch(string command, string user, string domain, string pwd){</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>StartupInfo startupInfo = new StartupInfo();</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>startupInfo.reserved = null;</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>startupInfo.flags &amp;= Startf_UseStdHandles;</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>startupInfo.stdOutput = (IntPtr)StdOutputHandle;</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>startupInfo.stdError = (IntPtr)StdErrorHandle;</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>UInt32 exitCode = 123456;</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>ProcessInformation processInfo = new ProcessInformation();</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>String currentDirectory = System.IO.Directory.GetCurrentDirectory();</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>try</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>CreateProcessWithLogonW(</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>user,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>domain,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>pwd,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>(UInt32) 1,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>command,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>command,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>(UInt32) 0,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>(UInt32) 0,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>currentDirectory,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>ref startupInfo,</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>out processInfo);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>} </em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>catch (Exception e)</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine(e.ToString());</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
</div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine("Exécution ...");</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>WaitForSingleObject(processInfo.process, Infinite);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>GetExitCodeProcess(processInfo.process, ref exitCode);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine("Code sortie: {0}", exitCode);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>CloseHandle(processInfo.process);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>CloseHandle(processInfo.thread);</em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">3. Dans le point d'entrée de l'application, j'ai ajouté le code pour vérifier l'existence du Framework .NET 3.5 sur le poste client en vérifiant la présence de clé dans la base de registre. </span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using System.Windows.Forms;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using System.Data;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using System.Configuration;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using System.Collections;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>using Microsoft.Win32;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>namespace Lanceur</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>///</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>/// Classe lanceur</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>/// </em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>public class MainClass</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>/// </em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>/// Point d'entrée principal de l'application.</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>///[STAThread]</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>static void Main() </em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>string application = ConfigurationSettings.AppSettings["application"];</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>try</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine("Vérification de composant requis.");</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>// Vérifier si framework .NET3.5 est installé </em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>if(!NETInstalled())</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine("Installation de composant requis en cours ....");</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>string cmd = @ConfigurationSettings.AppSettings["cmd"];</em></span></div><br />
<div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>// Installation en silence</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>cmd = cmd + " /q:a /c:'setup.exe /q /norestart' /norestart";</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>string user = ConfigurationSettings.AppSettings["user"];</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>string domain = ConfigurationSettings.AppSettings["domain"];</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>string pwd = ConfigurationSettings.AppSettings["pwd"]; </em></span></div><div style="margin-left: 106pt;"><br />
</div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>// Installation du framework .NET 3.5</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>CreateProcessWithLogon.Launch(cmd, user,domain,pwd); </em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine("Installation de composant requis est teminé.");</em></span></div><div style="margin-left: 106pt;"><br />
</div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>// Installation de l'application </em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine("Installation de l'application.");</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>InstallApplication(application);</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>else</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>// Installation de l'application </em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Console.WriteLine("Installation de l'application.");</em></span></div><div style="margin-left: 106pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>InstallApplication(application);</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>catch(Exception Ex)</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;">{…}</span></div><div style="margin-left: 35pt;"><br />
</div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>// Lancement de l'application</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>try </em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>// Code propre à l'application</em></span></div><div style="margin-left: 70pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>Application.Run((System.Windows.Forms.Form)(IHMManager.Instance.getIhmPrincipale()));</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>catch(….)</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{} </em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>private static bool NETInstalled()</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>RegistryKey cle = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5");</em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em> if(cle == null)</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> {</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>return false;</em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em> }</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> return true;</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>private static void InstallApplication(string application)</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> try</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> { </em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em> // Prévenir l'utilisateur qi tout se passe bien, de passer par la nouvelle icône pour la prochaine connexion</em></span><span style="font-family: Trebuchet MS; font-size: 10pt;"><em> MessageBox.Show("L'application [NOMAPPLICATION] sera installée sur votre poste. Merci de cliquer sur la nouvelle icône sur votre bureau pour la prochaine connexion.");</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>System.Threading.Thread.Sleep(500);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>System.Diagnostics.Process.Start(@application);</em></span></div><div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>System.Diagnostics.Process.Start(@application); </em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em> }</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>catch(Exception Ex)</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>{</em></span><br />
<div style="margin-left: 35pt;"><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>throw Ex;</em></span></div><span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<span style="font-family: Trebuchet MS; font-size: 10pt;"><em>}</em></span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">Cette solution n'a finalement pas été retenue. Mais cela me permet de découvrir une possibilité sur le moyen d'installation les éléments requis. </span><br />
<br />
<span style="font-family: Trebuchet MS; font-size: 10pt;">On utilise finalement un outil PsTools->PsExec qui permet d'installer à distance et en masse une application sur un poste client sous contexte d'un administrateur.</span></div>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-75186703221657680972010-07-08T01:44:00.000-07:002010-07-08T01:59:41.181-07:00Astuce pour afficher les résultats de requête sur une seule ligne/sous forme d’une chaine de caractères<span style="font-family: "Trebuchet MS", sans-serif;">Une fois je voulais récupérer les données d’une table de la base de données SQL Server 2008 sous forme d’une chaîne de caractères. Je pensais faire une fonction avec un curseur et concatène des données de chaque ligne pour former une chaîne de caractères. </span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Supposons, il y a une table suivante dans une base de données :</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><strong>Table dbo.PAYS</strong></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">ID LIBELLE</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">1 France</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">2 Allemagne</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">3 Belgique</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">4 Espagne</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Lorsque l’on fait la requête: <span style="color: red; font-family: "Courier New", Courier, monospace;">SELECT LIBELLE FROM dbo.PAYS</span>, le résultat affiché:</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">LIBELLE</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">France</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">Allemagne</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">Belgique</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">Espagne</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Une astuce facile pour former une chaîne de caractère à partir de ce résultat est d’utiliser le mot clé : </span><span style="font-family: "Courier New", Courier, monospace;">FOR XML PATH</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Le mode <span style="font-family: "Courier New", Courier, monospace;">FOR XML PATH</span> est utilisé pour construire un XML à partir de résultats de requête.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Examples:</strong></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Requête</strong></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">SELECT dbo.PAYS.LIBELLE </span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">FROM dbo.PAYS </span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">ORDER BY dbo.PAYS.ID </span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">For XML PATH</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Résultat</strong></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><row></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><LIBELLE>France</LIBELLE></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"></row></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><row></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><LIBELLE>Allemagne</LIBELLE></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"></row></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><row></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><LIBELLE>Belgique</LIBELLE></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><row></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><row></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"><LIBELLE>Espagne</LIBELLE></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;"></row></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Requête:</strong></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">SELECT dbo.PAYS.LIBELLE + ''</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">FROM dbo.PAYS </span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">ORDER BY dbo.PAYS.ID</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">For XML PATH ('Pays')</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Résultat :</strong></span><br />
<pays><span style="color: red; font-family: "Courier New", Courier, monospace;"><Pays>France</Pays></span><br />
<pays><span style="color: red; font-family: "Courier New", Courier, monospace;"><Pays>Allemagne</Pays></span><br />
<pays><span style="color: red; font-family: "Courier New", Courier, monospace;"><Pays>Belgique</Pays></span><br />
<pays><span style="color: red; font-family: "Courier New", Courier, monospace;"><Pays>Espagne</Pays></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Et, la requête suivante:</strong></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">SELECT dbo.PAYS.LIBELLE + ',' </span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">FROM dbo.PAYS </span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">ORDER BY dbo.PAYS.ID</span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">For XML PATH ('')</span><br />
<span style="color: #073763; font-family: "Trebuchet MS", sans-serif;"><strong>Et voila le résultat:</strong></span><br />
<span style="color: red; font-family: "Courier New", Courier, monospace;">France,Allemagne,Belgique,Espagne</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Voir plus loin sur <span style="font-family: "Courier New", Courier, monospace;">FOR XML PATH</span> :</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><a href="http://technet.microsoft.com/fr-fr/library/ms189885(SQL.90).aspx">http://technet.microsoft.com/fr-fr/library/ms189885(SQL.90).aspx</a></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-47524497554052587442010-07-07T02:59:00.000-07:002010-07-07T03:00:44.116-07:00Problème de génération Word via une tâche planifiée<span style="font-family: "Trebuchet MS", sans-serif;">J’ai travaillé sur un projet .NET C# qui génère des documents Word via un exécutable lancé par une tâche planifiée. </span><span style="font-family: "Trebuchet MS", sans-serif;">J'utilise Interop.Word pour la génération des documents.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">L'exécutable a été installé sur Windows Server 2003, la génération se passait bien.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Récemment, on a migré l'application sur Windows Server 2008. Depuis la génération ne marchait plus.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Apres plusieurs recherches, j'ai pu trouver le "hack" pour contourner ce problème:</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>1. Sur Windows x86</strong> </span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-Créer le répertoire c:\\windows\system32\config\systemprofile\desktop</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-Accorder les droits au compte qui exécute la génération Word</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>2. Sur Windows x64</strong></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-Créer le répertoire c:\\windows\SysWOW64\config\systemprofile\desktop</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-Ajouter les droits au compte qui exécute la génération Word</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Le répertoire Desktop est apparemment nécessaire pour l’ouverture du fichier Office. Ce répertoire existe sur Windows Server 2003 mais disparaît sur Windows Server 2008.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Pour suivre la discussion sur ce sujet:</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><a href="http://social.msdn.microsoft.com/Forums/en/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91">http://social.msdn.microsoft.com/Forums/en/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91</a></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-11099446637995274372010-06-25T09:52:00.000-07:002010-06-25T09:52:56.356-07:00Impossible d'installer ou d'exécuter l'application. Cette application requiert l'assembly EnvDTE version 8.0.xx, qui doit d'abord être installée dans le Global Assembly Cache.<span style="font-family: "Trebuchet MS", sans-serif;">J’ai travaillé sur une application WINFORMS qui utilise EnvDTE version 7.0.xx pour l’automation de Visual Studio. L’application a été développée sur .NET 1.1 avec Visual Studio 2003.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Récemment, j’ai fait la migration de cette application vers le framework .NET 3.5 avec Visual Studio 2008.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">J’ai déployé l’application via ClickOnce Deployment.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Lorsque je l’ai installée sur ma machine, cela marche sans problème. Par contre, lorsque je l’ai installée sur une machine où il n’y a pas de Visual Studio .NET installé, j’ai obtenu une erreur suivante :</span><br />
<span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>Impossible d'installer ou d'exécuter l'application. Cette application requiert l'assembly EnvDTE version 8.0.xx, qui doit d'abord être installée dans le Global Assembly Cache.</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">J’ai ensuite changé toutes les références d’EnvDTE 7.0.xx dans mon application par EnvDTE version 8.0.xx. </span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">J’ai réessayé de l’installer la machine où il n’y a pas de Visual Studio .NET installé.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Mais, cette fois-ci j’ai obtenu l’erreur suivante:</span><br />
<span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>Impossible d'installer ou d'exécuter l'application. Cette application requiert l'assembly EnvDTE version 7.0.xx, qui doit d'abord être installée dans le Global Assembly Cache.</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">J’ai essayé de trouver la réponse à ce problème. Apres plusieurs recherches, j’ai trouvé un article sur MSDN qui m’a aidé à résoudre ce problème.</span><br />
<span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>“Cette erreur est liée à un conflit de résolution de type à l'exécution. En d'autres termes, la version de EnvDTE incluse dans Visual Studio 2005 est 8.0.xx, mais la référence de configuration du projet recherche une version antérieure de cet assembly ; la version 7.0.xx. Pour corriger ce problème, vous devez ajouter une redirection de liaison pour la version la plus récente de EnvDTE au fichier de configuration (.config) de votre projet. Ainsi, Visual Studio pourra charger la version la plus récente de EnvDTE et empêcher l'erreur de se produire."</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">J’ai ajouté dans mon fichier App.config à l’intérieure de la section « runtime », la configuration suivante :</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQg8rEQ_KmcpTRYCpndlAUSqblFzAlxRuaAl5JPPid4hVNQJB_K2wN-8sn8Qy_pS6Z4WKYz8M_IK__r2Fmh3Kg7D3AmmNBrNnc14uUqXJgb4GB5hQasPufdsqEwOyIwfLZaE9HuAb86SY/s1600-h/runtime.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="188" mt="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQg8rEQ_KmcpTRYCpndlAUSqblFzAlxRuaAl5JPPid4hVNQJB_K2wN-8sn8Qy_pS6Z4WKYz8M_IK__r2Fmh3Kg7D3AmmNBrNnc14uUqXJgb4GB5hQasPufdsqEwOyIwfLZaE9HuAb86SY/s400/runtime.bmp" width="400" /></a></div><span style="font-family: "Trebuchet MS", sans-serif;">Je peux maintenant déployer l’application avec succès.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Pour lire plus loin:</span><br />
<a href="http://msdn.microsoft.com/fr-fr/library/4eeya3de(VS.80).aspx"><span style="font-family: "Trebuchet MS", sans-serif;">http://msdn.microsoft.com/fr-fr/library/4eeya3de(VS.80).aspx</span></a>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-657037014432264842010-06-18T14:27:00.000-07:002010-06-18T14:27:15.225-07:00[SQL Server] Erreur de restauration de base de données<span style="font-family: trebuchet ms;">Lors de restauration d’une base de données, j’ai rencontré un message d’erreur :</span><br />
<span style="font-family: trebuchet ms;"><br />
<em>System.Data.SqlClient.SqlError: Le support de sauvegarde est formé de 2 familles de supports, mais seules 1 sont fournies. Tous les membres doivent être fournis. (Microsoft.SqlServer.Smo)</em><br />
<em></em><br />
Cette erreur est due à la sauvegarde dans deux emplacements et qu’on ne reprend qu’un emplacement pour la restauration.<br />
<br />
Pour corriger cette erreur, j’ai du refaire le sauvegarde et la restauration de la base de données.<br />
1. Sélectionner la base de données<br />
2. Cliquer sur Sauvegarder<br />
3. Supprimer tous les emplacements listés<br />
4. Sélectionner un nouvel emplacement<br />
5. A partir du fichier généré, restaurer la base</span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com4tag:blogger.com,1999:blog-2702485579611547622.post-29266014181454412092010-06-15T09:58:00.000-07:002010-06-15T09:58:32.477-07:00Word ne peut pas démarrer le convertisseur mswrd632.wpc<span style="font-family: "Trebuchet MS", sans-serif;">J'ai travaillé avec Interop.Word pour générer les documents Word via une application Winforms.</span> <br />
<span style="font-family: "Trebuchet MS", sans-serif;">J'ai récemment fait la migration de la version Office 2003 vers 2007.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Lorsque j'ai ouvert le document généré avec Word 2007, j'ai obtenu l'erreur:</span> <br />
<span style="font-family: "Trebuchet MS", sans-serif;"><em>Word ne peut pas démarrer le convertisseur mswrd632.wpc</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Après des recherches, cette erreur est due à la mise à jour de sécurité Windows XP, Windows 2000, and Windows Server 2003 au 8 Décembre 2009.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Pour éviter l'affichage de ce message, j'ai supprimé le convertisseur mswrd632 en base de registre. Pour ce faire:</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-Exécuter regedit</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-Aller dans HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Text Converters\Import\MSWord6.wpc</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-Cliquer droit puis supprimer</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Cela désinscrit le convertisseur indiqué dans le message d’erreur. Microsoft Office utilisera ses propres convertisseurs pour ouvrir les documents.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Pour plus d'explication:</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-<a href="http://support.microsoft.com/kb/973904">http://support.microsoft.com/kb/973904</a></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">-<a href="http://support.microsoft.com/kb/243088">http://support.microsoft.com/kb/243088</a></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com1tag:blogger.com,1999:blog-2702485579611547622.post-73879738880839855562010-06-11T08:41:00.000-07:002010-06-15T09:58:48.144-07:00L'identité actuelle ([machine]/ASPNET) ne dispose pas d'un accès en écriture à 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files'.<span style="font-family: "Trebuchet MS", sans-serif;">Lors d'une migration du Framework .NET1.1 vers .NET3.5, lorsque je lance une application web, j'ai obtenu un message suivant sur le navigateur:</span><span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>L'identité actuelle ([machine]/ASPNET) ne dispose pas d'un accès en écriture à 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files'.</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">La solution la plus facile est d’ajouter à l’utilisateur ASPNET des droits en lecture sur le dossier C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Sinon, lancer aspnet_regiis.exe depuis le dossier C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. Cette commande permet de mapper l'application à la version ISAPI ASP.NET du Framework 2.0 et exécuter d'autres opérations de configuration. </span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Les options pour cette commande sont disponibles sur:</span><br />
<a href="http://msdn.microsoft.com/fr-fr/library/k6h9cz8h(VS.80).aspx"><span style="font-family: "Trebuchet MS", sans-serif;">http://msdn.microsoft.com/fr-fr/library/k6h9cz8h(VS.80).aspx</span></a>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-70223469940729157852010-06-10T11:28:00.000-07:002010-06-15T09:59:01.363-07:00Cyrstal Report "ApplyLogOnInfo" très lent<span style="font-family: "Trebuchet MS", sans-serif;">J'ai migré une application qui utilise Crystal Report qui génère un fichier PDF avec les données de la base SQL Server.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">La migration se fait à partir du .NET 1.1 vers .NET3.5.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Depuis la génération du pdf est très lente.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">La partie qui est particulièrement lente se trouve dans la boucle:</span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>TableLogOnInfo logOnInfo = new TableLogOnInfo();</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>for (int i = 0; i < dossierCyrstal.Database.Tables.Count; i++)</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>{</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> //logOnInfo</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> logOnInfo.ConnectionInfo.ServerName = [Nom du serveur];</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> logOnInfo.ConnectionInfo.DatabaseName = [Nom base de données];</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> logOnInfo.ConnectionInfo.UserID = [Nom d'utilisateur];</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> logOnInfo.ConnectionInfo.Password = [Mot de passe];</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> dossierCrystal.Database.Tables[i].ApplyLogOnInfo(logOnInfo);</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>}</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Après les recherches sur le net, j'ai remplacé la boucle ci-dessous avec deux lignes de code:</span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> dossierCrystal.DataSourceConnections[0].SetConnection</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> ([Nom du serveur], [Nom base de données], [Nom d'utilisateur], [Mot de passe]);</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em> dossierCrystal.Refresh();</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Depuis, la génération s'accélère.</span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-72264037594203125032010-06-08T14:47:00.000-07:002010-06-15T09:59:34.169-07:00Interopérabilité Word 2007 Un composant externe a levé une exception<span style="font-family: "Trebuchet MS", sans-serif;">J’ai travaillé sur une application Winforms développée en C# qui génère des documents Word.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">La génération consiste à remplacer les mots clés dans le document par les données de la base de données.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Sur certains postes d'utilisateur, la génération renvoie une exception:</span><br />
<span style="font-family: Trebuchet MS;">"<em><strong>Composant externe a levé une exception</strong></em>" ou "<em><strong>Le relais a reçu des données incorrectes</strong></em>"</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Après plusieurs recherches, c'est lors d'appel de l'objet <em>Find</em> qui pose problème.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Ceci est dû à l'enregistrement des bibliothèques antérieures à 2007 qui sont enregistrées dans la base de registre Windows après celles de 2007.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Deux solutions possibles:</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">1. Exécuter la ligne de commande: <em><strong>C:\Program Files\Microsoft Office\Office12\Winword.exe /r</strong></em> qui force la réinscription des dll Word dans la base de registre Windows.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Ou s'il n'y a qu'une seule version Word sur le poste, aller dans <em><strong>Démarrer -> Exécuter -> winword.exe /r </strong></em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">2. Utilisez liaison tardive pour l'objet <em>Find</em> (<em>late binding</em>).</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">J'ai transformé le code suivant:</span><br />
<em><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;">object missingValue = Type.Missing; </span></span></em><br />
<em><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;">object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll; M</span></span></em><em><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;">icrosoft.Office.Interop.Word.Find find = ThisApplication.Selection.Range.Find;</span></span></em><br />
<em><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;">object texteRecherche = TextRecherche;</span></span></em><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>object texteRemplace = TextNew;</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>f</em></span><em><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;">ind.Execute(ref texteRecherche ref missingValue, ref missingValue, ref missingValue,</span></span></em><br />
<em><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;">ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref texteRemplace,</span></span></em><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>ref replaceAll, ref missingValue, ref missingValue, ref missingValue, ref missingValue);</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">à</span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>object missingValue = Type.Missing; </em></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll; M</em></span></span><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>icrosoft.Office.Interop.Word.Find find = ThisApplication.Selection.Range.Find;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>object texteRecherche = TextRecherche;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>o</em></span></span><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>bject texteRemplace = TextNew;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>object[] Parameters;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters = new object[15];</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[0] = texteRecherche </em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[1] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[2] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[3] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[4] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[5] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[6] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[7] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[8] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[9] = texteRemplace </em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[10] = replaceAll;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[11] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>Parameters[12] = missingValue;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>P</em></span></span><span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>arameters[13] = missingValue;</em></span></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>Parameters[14] = missingValue;</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>find.GetType().InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, find,Parameters);</em></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>// Libérer les ressources</em></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>System.Runtime.InteropServices.Marshal.ReleaseComObject(oFind);</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>oFind = null;</em></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Trebuchet MS", sans-serif;"><em>System.Runtime.InteropServices.Marshal.ReleaseComObject(oSelection);</em></span></span><br />
<span style="font-family: "Trebuchet MS", sans-serif; font-size: x-small;"><em>oSelection = null;</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Le problème a été résolu.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">NB: Bien que la première méthode est plus facile, l'application peut échouer par la suite, si la bibliothèque de type Excel 95,… est réinscrite par une autre application ou un service pack.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"><strong>Pour aller plus loin:</strong></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><a href="http://support.microsoft.com/kb/313104">http://support.microsoft.com/kb/313104</a></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><a href="http://support.microsoft.com/kb/210565">http://support.microsoft.com/kb/210565</a></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-77282098431446123772010-01-31T06:22:00.001-08:002010-01-31T06:49:01.842-08:00An error has occurred while attempting to load Crystal Reports runtime<span xmlns=""></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">I was using .NET 1.1 framework</span><span style="font-family: "Trebuchet MS", sans-serif;"> and am currently migrating a web application to .NET 3.5 framework using Visual Studio .NET 2008. </span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">I get the Crystal Report Runtime from Visual Studio .NET 2008 installation.</span><br />
<span style="font-family: Trebuchet MS;"></span><span style="color: #333333;"><br />
</span><span style="font-family: "Trebuchet MS", sans-serif;">I use Crystal Report for PDF generation within the application.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">In my application project, I reference dll of Crystal and set "copy local" to true. It works well on my machine.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">But when I install the application on Server (Windows Server 2008, IIS7), I get the following error:</span><br />
<br />
<div style="background: white;"><span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>An error has occurred while attempting to load the Crystal Reports runtime.</em></span></div><div style="background: white;"><span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>Either the Crystal Reports registry key permissions are insufficient or the Crystal Reports runtime is not installed correctly.</em></span></div><div style="background: white;"><em><span style="color: red; font-family: "Trebuchet MS", sans-serif;">Please install the appropriate Crystal Reports redistributable (CRRedist*.msi) containing the correct version of the Crystal Reports runtime (x86, x64, or Itanium) required. Please go to </span><a href="http://www.businessobjects.com/support" target="_blank" title="http://www.businessobjects.com/support"></a><a href="http://resources.businessobjects.com/support/downloads/redistributables/vs_2008/redist/x86/CRRedist2008_x86.msi"></a><a href="http://resources.businessobjects.com/support/downloads/redistributables/vs_2008/redist/x64/CRRedist2008_x64.msi"></a><span style="color: red; font-family: "Trebuchet MS", sans-serif;">http://www.businessobjects.com/support</span><span style="color: red; font-family: "Trebuchet MS", sans-serif;"> for more information.</span></em></div><br />
<span style="font-family: "Trebuchet MS", sans-serif;">If you encounter the above error, maybe the following solution could help.</span><br />
<br />
<span style="font-family: Trebuchet MS;">- Check if Crystal Report Runtime is installed on server.</span><br />
<span style="font-family: Trebuchet MS;">(If </span><span style="font-family: Trebuchet MS;"><span style="color: #333333;">folder C:\Program Files\Common Files\Business Objects\ [version]\managed exists).</span></span><br />
<span style="font-family: Trebuchet MS;"><span style="color: #333333;">Otherwise install Crystal Report Runtime. </span></span><br />
<br />
<span style="font-family: Trebuchet MS;"><span style="color: #333333;">You can download Crystal Report Runtime from the following links:</span></span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"> </span><span style="font-family: "Trebuchet MS", sans-serif;"><span style="color: #333333;">"CRRedist2008_x86.msi" (for 32bit)</span></span><span style="font-family: "Trebuchet MS", sans-serif;"><span style="color: #333333;"><br />
<a href="http://resources.businessobjects.com/support/downloads/redistributables/vs_2008/redist/x86/CRRedist2008_x86.msi">http://resources.businessobjects.com/support/downloads/redistributables/vs_2008/redist/x86/CRRedist2008_x86.msi</a></span></span><span style="color: #333333;"><strong><br />
</strong><span style="font-family: "Trebuchet MS", sans-serif;"></span></span><span style="color: #333333;"><span style="font-family: "Trebuchet MS", sans-serif;"></span></span><br />
<span style="color: #333333;"><span style="font-family: "Trebuchet MS", sans-serif;">"CRRedist2008_x64.msi" (for 64bit)</span></span><span style="color: #0f243e; font-family: "Trebuchet MS", sans-serif;"><a href="http://resources.businessobjects.com/support/downloads/redistributables/vs_2008/redist/x64/CRRedist2008_x64.msi">http://resources.businessobjects.com/support/downloads/redistributables/vs_2008/redist/x64/CRRedist2008_x64.msi</a></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;"> - </span><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">Check if Crystal is running on 32 bit server or 64 bit server. Go to your application project (in Visual Studio .NET), right click, and select "Properties".</span><span style="color: #333333; font-family: "Trebuchet MS", sans-serif;">On the Build tab, find the Platform Target combo box. If Crystal runs on 32 bit server, change the Platform Target to x86 instead of Any CPU.</span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com3tag:blogger.com,1999:blog-2702485579611547622.post-74590154857110373912010-01-22T01:40:00.000-08:002010-01-31T06:49:16.678-08:00Unable to install or run the application. The application requires that assembly EnvDTE Version 8.0.xx be installed in the Global Assembly Cache (GAC) first.<span style="font-family: "Trebuchet MS", sans-serif;">I was working on a Winforms application that used EnvDTE library version 7.0.xx for Visual Studio automation. The application was developed using .NET 1.1 with Visual Studio 2003.</span><span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">Recently, I was doing a migration of that application to .NET 3.5 with Visual Studio 2008.</span><span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">I chose to deploy using ClickOnce deployment.</span><span style="font-family: "Trebuchet MS", sans-serif;"><br />
</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">When I installed it on my machine, it worked. But then, I did a test with an end user machine without any Visual Studio .NET installed. </span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">I got the following error:</span><br />
<span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>Unable to install or run the application. The application requires that assembly EnvDTE Version 8.0.xx be installed in the Global Assembly Cache (GAC) first.</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">Then, I changed all references of EnvDTE 7.0.xx in my application with EnvDTE version 8.0.xx. I deployed it again to an end user machine.</span><br />
<span style="font-family: "Trebuchet MS", sans-serif;">But I still got the following error:</span><br />
<span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>Unable to install or run the application. The application requires that assembly EnvDTE Version 7.0.xx is installed in the Global Assembly Cache (GAC) first.</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">I spent some time to fix the problem. But then I found an article in MSDN that helped me to solve the problem.</span><br />
<span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>“This error is due to a runtime resolution conflict. The version on EnvDTE that is included with visual studio 2008 is 8.0.xx; but the project’s configuration reference is looking for an earlier version of this assembly, version 7.0.xx. </em></span><br />
<span style="color: red; font-family: "Trebuchet MS", sans-serif;"><em>To fix this problem, you must add a binding redirect for that newer version of EnvDTE to your project’s configuration (.config) file.“</em></span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">I then added to my App.config file the following configuration inside the “runtime” section.</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDYaEQcBFTITrG-_4_XumIt4ZJz4LZ0Edx-iy86l_M7SRFCXkEjPkzUu7SJL5MEMrTh4iNgpxbyE2YEiyXGYaTL1stuJ8keBTGQ-bRdqhK7TSfNnqClPtmuZkkpVhXXZO7WvzfyaZKJQc/s1600-h/runtime.bmp" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" height="187" mt="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDYaEQcBFTITrG-_4_XumIt4ZJz4LZ0Edx-iy86l_M7SRFCXkEjPkzUu7SJL5MEMrTh4iNgpxbyE2YEiyXGYaTL1stuJ8keBTGQ-bRdqhK7TSfNnqClPtmuZkkpVhXXZO7WvzfyaZKJQc/s400/runtime.bmp" width="400" /></a></div><span style="font-size: x-small;"><span style="font-size: small;"><span style="font-family: "Trebuchet MS", sans-serif;">I am now able to deploy the application to end user machines with success.</span><br />
<br />
<span style="font-family: "Trebuchet MS", sans-serif;">To learn more : </span><br />
<span style="font-family: "Trebuchet MS", sans-serif;"><a href="http://msdn.microsoft.com/en-us/library/4eeya3de(VS.80).aspx">http://msdn.microsoft.com/en-us/library/4eeya3de(VS.80).aspx</a></span></span></span><span style="font-family: "Trebuchet MS", sans-serif;"></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-67999802103933473582009-11-16T06:12:00.000-08:002009-11-16T06:18:07.217-08:00[SQL Server 2008]Login associé à dbo est vide<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcfRtlc2Zt82g1uY8bIhyphenhyphendwy6hkOvsHdaN-vuxaExEggnuDt6qQ1bRFWVrViU_QE6FicA0RoMOr62A5WpjTpa14WTLXDbrbYDMUoqHLWPI1-o0Wn3TMcJ33Nh41tyg12ys65nKJCRJNN0/s1600/dbo.png"><img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 353px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5404705214948517650" border="0" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcfRtlc2Zt82g1uY8bIhyphenhyphendwy6hkOvsHdaN-vuxaExEggnuDt6qQ1bRFWVrViU_QE6FicA0RoMOr62A5WpjTpa14WTLXDbrbYDMUoqHLWPI1-o0Wn3TMcJ33Nh41tyg12ys65nKJCRJNN0/s400/dbo.png" /></a><br /><div><span style="font-family:Calibri;"><p style="MARGIN: 0cm 0cm 10pt" class="MsoNormal">Lors de la restauration d’une base de données, si le login propriétaire de <strong>dbo</strong> n’existe pas sur le nouveau serveur, le login associé à <strong>dbo</strong> est vide.</span></p><p style="MARGIN: 0cm 0cm 10pt" class="MsoNormal"><span style="font-family:Calibri;">Nous pouvons modifier le login associé à l'utilisateur <strong>dbo</strong> avec la commande:</span></p><p style="MARGIN: 0cm 0cm 10pt" class="MsoNormal"><span style="font-family:Calibri;"><em>'sp_changedbowner login'</em></span></p><p style="MARGIN: 0cm 0cm 10pt" class="MsoNormal"><span style="font-family:Calibri;">Par exemple, si on souhaite définir <i style="mso-bidi-font-style: normal"><strong>sa</strong></i> en tant que dbo sur la base de données nommée <i style="mso-bidi-font-style: normal">TEST</i> :</span></p><p style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpFirst"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;">1.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;">Aller dans SQL Server Management Studio</span></p><br /><p style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;">2.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;">Sélectionner la base de données</span></p><br /><p style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;">3.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;">Cliquer droit puis sélectionner Nouvelle Requête</span></p><br /><p style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 10pt 36pt; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpLast"><i style="mso-bidi-font-style: normal"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;">4.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span></i><span style="font-family:Calibri;">Exécuter la commande <span style="mso-spacerun: yes"></span><i style="mso-bidi-font-style: normal">sp_changedbowner <b style="mso-bidi-font-weight: normal">sa</b></i></span></p></div>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-19653571381560697442009-07-30T01:07:00.000-07:002010-06-15T09:59:48.182-07:00SQL Server 2000 Mettre à jour le contenu d’une colonne du type NTEXT<span style="font-family: verdana; font-size: 85%;">Ci-dessous le script que j’ai utilisé pour mettre à jour une colonne du type NTEXT.<br />
Le but est de remplacer un texte dans cette colonne.<br />
<br />
<br />
<em><span style="font-size: 78%;">SET NOCOUNT ON<br />
<br />
<br />
DECLARE @ptrval binary(16);<br />
DECLARE @offset int;<br />
<br />
DECLARE @Cle varchar;<br />
DECLARE @TexteARemplacer varchar; --Texte à remplacer<br />
DECLARE @LenTexteARemplacer int; --Longueur de la chaîne à remplacer<br />
DECLARE @NouveauTexte varchar; --Nouveau texte<br />
<br />
SET @Cle = 'cle';<br />
SET @TexteARemplacer = 'Texte à remplacer';<br />
SET @LenTexteARemplacer = LEN(@TexteARemplacer)<br />
SET @NouveauTexte = 'Nouveau texte';<br />
<br />
-- Récupérer le contenu de la colonne à mettre à jour<br />
SELECT<br />
@ptrval = TEXTPTR(TEST_COLONNE_LIBELLE)<br />
FROM TEST_TABLE<br />
WHERE<br />
TEST_COLONNE_CLE = ' + @Cle + '<br />
<br />
--Récupérer la première position du texte à remplacer dans le libellé<br />
SELECT<br />
@offset = PATINDEX('%'+@TexteARemplacer+'%', TEST_COLONNE_LIBELLE) - 1<br />
FROM TEST_TABLE<br />
WHERE<br />
TEST_COLONNE_CLE = ' + @Cle + '<br />
<br />
--Mettre à jour le libellé<br />
WHILE @offset > -1<br />
BEGIN<br />
UPDATETEXT TEST_TABLE.COLONNE_LIBELLE @ptrval @offset @LenTexteARemplacer @NouveauTexte; <br />
SELECT<br />
@offset = PATINDEX('%'+@TexteARemplacer+'%', COLONNE_LIBELLE) - 1<br />
FROM TABLE<br />
WHERE<br />
COLONNE_CLE = ' + @Cle +'<br />
END<br />
<br />
<br />
SET NOCOUNT OFF</span></em></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-42138481149291515242009-07-29T00:56:00.000-07:002010-06-15T10:00:21.465-07:00IE8 Impossible à débugger un projet web depuis Visual Studio s'il y a déjà IE8 ouvert<div align="justify"><span style="font-family: verdana; font-size: 85%;">IE8 possède une propriété <em>Loosely-Coupled Internet Explorer (LCIE)</em> qui lui permet de s'exécuter sur plusieurs processus actives.<br />
<br />
Débugger de Visual Studio n'arrive pas à déterminer sur quel processeur il faut attacher le débuggeur.<br />
Vous pouvez corriger ce problème en désactivant la propriété "<em>process growth</em>" de LCIE.<br />
<br />
1. Ouvrir RegEdit<br />
2. Aller sur HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main<br />
3. Ajouter un dword nommé <em>TabProcGrowth</em><br />
4. Adjuster T<em>abProcGrowth</em> à 0<br />
5. Redémarrer IE8</span></div><span style="font-family: verdana; font-size: 85%;">Ce problème n'apparaît plus sur Visual Studio 2008. </span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-91273841534157131342009-07-28T06:30:00.000-07:002010-06-15T10:00:05.818-07:00Impossible de démarrer le débogage sur le serveur web<span style="font-family: verdana; font-size: 85%;">J'ai trouvé des explications très complètes pour le message d'erreur : Impossible de démarrer le débogage sur le serveur web lorsqu’on lance un projet web ASP.NET sur Visual Studio .NET.<br />
<br />
</span><a href="http://msdn.microsoft.com/en-us/library/aa290100(VS.71).aspx"><span style="font-family: verdana; font-size: 85%;">http://msdn.microsoft.com/en-us/library/aa290100(VS.71).aspx</span></a><span style="font-family: verdana; font-size: 85%;"><br />
<br />
Pour information, c’est écrit en anglais mais facile à comprendre.</span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-21281358062076542742009-07-10T02:09:00.000-07:002010-06-15T09:59:21.429-07:00sp_help_revlogin Transférer les utilisateurs entre SQL Server 2000 et 2008<span style="font-family: verdana; font-size: 85%;">Lors d'un projet de migration de base de données SQL Server 2000 vers 2008, j'ai recherché une procédure permettant de transférer les utilisateurs.<br />
<br />
J’ai retrouvé un script sur le site laboratoire-microsoft.com, une version de procédure <em>sp_help_revlogin</em> pour SQL server 2005. J’ai essayé de l’exécuter mais j’ai obtenu un message d’erreur suivant :<br />
<br />
<em><span style="color: #999999;">Serveur : Msg 195, Niveau 15, État 10, Procédure sp_help_revlogin, Ligne 53<br />
'LOGINPROPERTY' n'est pas un nom de fonction reconnu.</span></em><br />
<br />
J’ai donc continué ma recherche. C’est sur le site de support de Microsoft que j’ai retrouvé la solution.</span><br />
<span style="font-family: Verdana; font-size: 85%;"></span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">USE master</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">GO</span><br />
<span style="color: #666666; font-family: Verdana; font-size: 78%;"></span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DROP PROCEDURE sp_hexadecimal</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">GO</span><br />
<span style="color: #666666; font-family: Verdana; font-size: 78%;"></span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">CREATE PROCEDURE sp_hexadecimal</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">@binvalue varbinary(256),</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">@hexvalue varchar(256) OUTPUT</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">AS</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @charvalue varchar(256)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @i int</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @length int</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @hexstring char(16)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @charvalue = '0x'</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @i = 1</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @length = DATALENGTH (@binvalue)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @hexstring = '0123456789ABCDEF' </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">WHILE (@i <= @length) </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">BEGIN</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @tempint int</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @firstint int</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @secondint int</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @firstint = FLOOR(@tempint/16)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @secondint = @tempint - (@firstint*16)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @charvalue = @charvalue +</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SUBSTRING(@hexstring, @firstint+1, 1) +</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SUBSTRING(@hexstring, @secondint+1, 1)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @i = @i + 1</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: Verdana; font-size: 78%;"></span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT @hexvalue = @charvalue</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">GO</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;"></span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DROP PROCEDURE sp_help_revlogin </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">GO</span><br />
<span style="color: #666666; font-family: Verdana; font-size: 78%;"></span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @name sysname</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @xstatus int</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @binpwd varbinary (256)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @txtpwd sysname</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @tmpstr varchar (256)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @SID_varbinary varbinary(85)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE @SID_string varchar(256)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;"></span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@login_name IS NULL)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE login_curs CURSOR FOR </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT sid, name, xstatus, password FROM master..sysxlogins </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">WHERE srvid IS NULL AND name <> 'sa'</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">ELSE</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DECLARE login_curs CURSOR FOR </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SELECT sid, name, xstatus, password FROM master..sysxlogins </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">WHERE srvid IS NULL AND name = @login_name</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">OPEN login_curs </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@@fetch_status = -1)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">BEGIN</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT 'No login(s) found.'</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">CLOSE login_curs </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DEALLOCATE login_curs </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">RETURN -1</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = '/* sp_help_revlogin script ' </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT @tmpstr</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = '** Generated ' </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">+ CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT @tmpstr</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT ''</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT 'DECLARE @pwd sysname'</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">WHILE (@@fetch_status <> -1)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">BEGIN</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@@fetch_status <> -2)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">BEGIN</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT ''</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = '-- Login: ' + @name</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT @tmpstr </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@xstatus & 4) = 4</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">BEGIN -- NT authenticated account/group</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@xstatus & 1) = 1</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">BEGIN -- NT login is denied access</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT @tmpstr </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">ELSE BEGIN -- NT login has access</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT @tmpstr </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">ELSE BEGIN -- SQL Server authentication</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@binpwd IS NOT NULL)</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">BEGIN -- Non-null password</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">EXEC sp_hexadecimal @binpwd, @txtpwd OUT</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@xstatus & 2048) = 2048</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd + ')'</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">ELSE</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' + @txtpwd + ')'</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT @tmpstr</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">+ ''', @pwd, @sid = ' + @SID_string + ', @encryptopt = '</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">ELSE BEGIN </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">-- Null password</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">+ ''', NULL, @sid = ' + @SID_string + ', @encryptopt = '</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">IF (@xstatus & 2048) = 2048</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">-- login upgraded from 6.5</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = @tmpstr + '''skip_encryption_old''' </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">ELSE </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">SET @tmpstr = @tmpstr + '''skip_encryption'''</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">PRINT @tmpstr </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">END</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">CLOSE login_curs </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">DEALLOCATE login_curs </span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">RETURN 0</span><br />
<span style="color: #666666; font-family: verdana; font-size: 78%;">GO</span><br />
<span style="font-family: verdana; font-size: 85%;"><br />
Il s’agit de créer deux procédures stockées nommées <em>sp_hexadecimal</em> et <em>sp_help_revlogin</em> dans la base de données <em>master</em>.</span><br />
<span style="font-family: verdana; font-size: 85%;"><br />
Après avoir créé la procédure stockée <em>sp_help_revlogin</em>, je l’ai exécutée à partir de l'Analyseur de requêtes du serveur SQL Server 2000.<br />
<em><span style="color: #999999;">EXEC master.sp_help_revlogin;</span></em><br />
<em><span style="color: #999999;"><br />
</span></em>La procédure stockée <em>sp_help_revlogin</em> produit des scripts de connexion qui créent des noms d'accès avec le SID et le mot de passe d'origine. J’ai fait copier-coller de la sortie, puis je l’ai exécutée dans l'Analyseur de requêtes du serveur SQL Server 2008.</span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-58140685266724885682009-04-23T08:51:00.000-07:002009-04-23T09:00:24.969-07:00Validation de procédures stockées dans la base SQL Server<span style="font-family:verdana;font-size:85%;">Dans un projet, j’ai travaillé avec des applications qui utilisent de nombreuses procédures stockées. Ceci donne la facilité qu’en cas de bug urgent, nous pouvons corriger la procédure concernée sans faire une livraison complète de l’application.<br /><br />Un jour, on est amené à faire de nettoyage dans la base de données afin de supprimer des colonnes non utilisées. Il nous fallait un moyen de vérifier la validité des procédures stockées après la suppression des colonnes.<br /><br />Pour cela j’ai fait une application Windows qui permet de valider les objets dans la base de données.<br />Plus loin, j’ai développé un outil qui permet de comparer l’état des bases de données. Dans mon cas, je l’utilise pour comparer la base de données de développement et celle de la production. Le comparateur de bases de données sera abordé prochainement.<br /><br />Ci-dessous un extrait de code pour valider les objets de la base de données:<br /><br /><span style="font-size:78%;color:#666666;"><em>// Connexion à la base de données</em><br />SqlConnection conn = new SqlConnection("Data Source=" + pServer + ";Initial Catalog="+pDb+";User Id="+login+";Password="+password+";");<br />conn.Open();<br /><br /><em>/*Requête sur la table système sysobjects pour récupérer les objets de la base de données suivant le type d’objet (P pour procédure stockée, V pour vue,…)<br />OBJECTPROPERTY (id, propriété): Retourne les informations concernant les objets (id = id de l’objet)<br />OBJECTPROPERTY(id,'ExecIsQuotedIdentOn') : retourne la propriété de QUOTED_IDENTIFIER lors de création de l’objet<br />OBJECTPROPERTY(id, 'ExecIsAnsiNullsOn') : retourne la propriété d’AISI NULLS lors de création de l’objet</em></span></span><em><br /></em><span style="font-family:verdana;font-size:85%;"><span style="font-size:78%;color:#666666;"><em>*/</em><br />string cmdText = "SELECT name, OBJECTPROPERTY(id,'ExecIsQuotedIdentOn') as ident_on, " +<br />" OBJECTPROPERTY(id,'ExecIsAnsiNullsOn') as ainsi_null ,USER_NAME(uid) as owner " +<br />" FROM sysobjects WHERE xtype= '" + objectType+"'";<br />SqlDataAdapter daTable1 = new SqlDataAdapter(cmdText,conn);<br />DataSet ds = new DataSet("Table");<br />daTable1.Fill(ds);<br /><br /><em>// Parcourir les objets</em><br />foreach(DataRow row in ds.Tables[0].Rows)<br />{<br /> StringBuilder sbCmd = new StringBuilder();<br /> StringBuilder sbCmdProc = new StringBuilder();<br /> string objectName = row["name"].ToString();<br /> string owner = row["owner"].ToString();<br /> string ansi_null = Convert.ToBoolean(row["ainsi_null"])?"ON":"OFF";<br /> string ident_on = Convert.ToBoolean(row["ident_on"])?"ON":"OFF";<br /> SqlCommand cmd = new SqlCommand("",conn);<br /> try<br /> {<br /><em> // sp_helptext : récupérer la definition d’objet<br /></em> cmd = new SqlCommand("exec sp_helptext '" + owner + "." + objectName+"';",conn);<br /> cmd.CommandType = CommandType.Text;<br /> SqlDataReader drDef = cmd.ExecuteReader();<br /><br /> while(drDef.Read())<br /> {<br /> sbCmdProc.Append(drDef["text"].ToString());<br /> }<br /> drDef.Close();<br /><br /><em> // Ne pas exécuter la requête/ mode parse</em><br /> sbCmd.Append("set noexec on;");</span></span><br /><span style="font-family:verdana;font-size:85%;"><span style="font-size:78%;color:#666666;"><br /><em> // Proriété ansi_null d’objet</em><br /> sbCmd.Append("set ansi_nulls "+ ansi_null +";");</span></span><br /><span style="font-family:verdana;font-size:85%;"><span style="font-size:78%;color:#666666;"><br /><em> // Proriété quoted_identifier d’objet</em><br /> sbCmd.Append("set quoted_identifier "+ ident_on+";");<br /> cmd = new SqlCommand(sbCmd.ToString(),conn);<br /> cmd.CommandType = CommandType.Text;<br /> cmd.ExecuteNonQuery();<br /><br /><em> // Executer l’objet</em><br /> cmd = new SqlCommand(sbCmdProc.ToString(),conn);<br /> cmd.CommandType = CommandType.Text;<br /> cmd.ExecuteNonQuery();<br /> }<br /> catch(Exception ex)<br /> {<br /><em> // Erreur dans l’exécution, l’objet n’est pas valide<br /> // Ici, mettre un message d’erreur<br /> }</em><br /> finally<br /> {<br /><em> /*Mettre ainsi_null par défaut (ON) et quoted_identifier par défaut (OFF)<br /> Et remettre en mode exécution<br /> */</em><br /> sbCmd = new StringBuilder();<br /> sbCmd.Append("set ansi_nulls ON;");<br /> sbCmd.Append("set quoted_identifier OFF;");<br /> sbCmd.Append("set parseonly off; set noexec off;");<br /><br /> cmd = new SqlCommand(sbCmd.ToString(),conn);<br /> cmd.CommandType = CommandType.Text;<br /> cmd.ExecuteNonQuery();<br /> }<br />}<br /><em>// Fermer la connexion de la base de données</em><br />conn.Close();</span></span><br /></span></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-52128430525447440052009-04-16T23:57:00.000-07:002009-04-17T00:05:43.971-07:00Checkout from SVN and Rebuild Solution File from Command Line<span style="font-family:verdana;font-size:85%;">I create a <strong>.bat</strong> file to checkout an application source from SVN and to rebuild solution file without opening Visual studio .NET.</span><br /><br /><span style="font-family:verdana;font-size:78%;color:#009900;"><em>rem ****Déclare path to Tortoise and Visual Studio .NET ***</em></span><br /><span style="font-family:verdana;font-size:78%;">set path=%path%;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\ </span><br /><span style="font-family:verdana;font-size:78%;"><br /><span style="color:#009900;"><em>rem ****Checkout application source from SVN****</em></span></span><br /><span style="font-family:verdana;font-size:78%;"><span style="color:#009900;"><em>rem ****/closeonend:1 Close automatically Tortoise Dialog Box if no error</em></span> TortoiseProc.exe /command:checkout /path:"D:\MyProject" /url:"</span><a href="https://svn.toto.com/svnrepos/MyProject/trunk"><span style="font-family:verdana;font-size:78%;">https://svn.toto.com/svnrepos/MyProject/trunk</span></a><span style="font-family:verdana;font-size:85%;"><span style="font-size:78%;">" /closeonend:1</span> </span><br /></span><p><span style="font-family:verdana;font-size:85%;"><span style="font-size:78%;color:#009900;"><em>rem ****Rebuild solution in debug mode - output to log file****</em></span></span><br /><span style="font-family:verdana;font-size:78%;">devenv.exe /rebuild Debug "D:\MyProject\MyProject.sln" /out "d:\logMyProject"</span></p>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-70594602043800838632009-03-27T09:12:00.000-07:002010-06-15T10:00:34.796-07:00Expérience avec AjaxControlToolKit<div><span style="font-family: verdana; font-size: 85%;"></span><span style="font-family: verdana; font-size: 85%;"><em>AjaxControlToolkit</em> est un ensemble de contrôles servers issu d’un partenariat entre Microsoft et la communauté d’ASP.NET Ajax. Il contient des contrôles extendeurs ainsi que des contrôles web permettant de construire une application internet riche. Les contrôles extendeurs sont des contrôles auxquels nous pouvons ajouter des scripts clients (JavaScript,..) dans l’événement du contrôle. <em>AjaxControlToolkit</em> met également à disposition des contrôles d’animation permettant d’ajouter des effets visuels plus sophistiqués dans une page web.<br />
<br />
<em>AjaxControlToolkit</em> est construit à partir <em>ASP.NET 2.0 Ajax Extension</em>. Le dernier release fonctionne sur le <em>Framework .NET 3.5 SP1.</em> La release contient le code source complet. Ceci permet d’utiliser les contrôles existants ainsi que la création de nouveaux contrôles.<br />
<br />
Les avantages :<br />
- Un ensemble des contrôles prêts à utiliser,<br />
- Une intégration aisée dans l’environnement Visual Studio 2008<br />
- Un développement rapide d’une interface web sophistiquée<br />
- Compatible avec de nombreux navigateur web<br />
- Un site web dédié contenant la documentation et des exemples<br />
<br />
Avant d’utiliser….<br />
Il faut savoir qu’il s’agit d’un nouveau produit. Ainsi par manque de maturité, il est nécessaire de faire la validation des maquettes. La connaissance de <em>JavaScript</em> est parfois utile afin d’adapter les contrôles aux besoins très spécifiques du projet.</span><br />
<div><div><div><div><div><div><div><br />
<span style="font-family: verdana; font-size: 85%;"><strong>Téléchargement du package d’<em>AjaxControlToolkit</em></strong><em><br />
</em>Le package complet (avec code source) peut être téléchargé à partir de l’adresse suivante :</span><a href="http://ajaxcontroltoolkit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=16488"><span style="font-family: verdana; font-size: 85%;">http://ajaxcontroltoolkit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=16488</span></a><span style="font-family: verdana; font-size: 85%;"><br />
</span></div><div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDu87oz_irZdAammQo_UV-HZnxjAK2efT724lGgEU9Lo91vOLxmMGkEMpqq8PqAk0lvCIlAZjCWWGiOtpVnkiT8LsoclPUbtn_9quSlnEktPdTpYO5ule_ZUIaW8vdvQ5ZHe-KBXqo0KA/s1600-h/2.JPG"><span style="font-family: verdana; font-size: 85%;"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5317901784903985410" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDu87oz_irZdAammQo_UV-HZnxjAK2efT724lGgEU9Lo91vOLxmMGkEMpqq8PqAk0lvCIlAZjCWWGiOtpVnkiT8LsoclPUbtn_9quSlnEktPdTpYO5ule_ZUIaW8vdvQ5ZHe-KBXqo0KA/s320/2.JPG" style="cursor: hand; height: 180px; width: 175px;" /></span></a><br />
<span style="font-family: verdana; font-size: 85%;"><br />
</span><span style="font-family: verdana; font-size: 85%;">Les contenus téléchargés :<br />
* <em>AjaxControlToolkit</em> – Contient la source ainsi que les contrôles d’<em>Ajax</em>* <em>SampleWebsite</em> – Site web qui montre comment utiliser les contrôles<br />
* <em>ToolkitTests</em> – Site web qui contient des tests automatisés pour tous les contrôles<br />
* <em>AjaxControlExtender</em> – Installeur de <em>Template</em> pour créer un nouveau contrôle extendeur avec Visual <em>Studio 2008 SP1</em>.<br />
<br />
<strong>Pour commencer avec Visual Studio .NET 2008</strong><br />
1. Créer un nouveau site web.<br />
2. Cliquer droit sur la boîte à outil -> Ajouter un onglet<br />
3. Cliquer droit sur le nouveau onglet, sélectionner « Choisir les éléments ».<br />
4. Cliquer sur le bouton « parcourir »<br />
5. Aller dans le répertoire d’<em>AjaxControlToolkit</em> téléchargé. Sélectionner la dll <em>AjaxControlToolkit.dll</em> dans le répertoire « SampleWebSite/bin ».<br />
6. Cliquer sur OK pour fermer la boite de dialogue.<br />
L’ensemble des nouveaux contrôles seront visibles sur la boite à outil.<br />
<img alt="" border="0" id="BLOGGER_PHOTO_ID_5317904048121700786" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh1P2gM8wLEjpLNESu_I79xnY-lUN17LP6pfoejmY-WJ2JViiO7gfdx5OjJjHdtTJQCKEwKzJFCDjPZUcYX1h_WsSESBRndh0jb9VPTdrfVWCoGFUeF_OqN9PZvTmnSl1p-xUIjaHl0_o/s400/3.JPG" style="cursor: hand; display: block; height: 400px; margin: 0px auto 10px; text-align: center; width: 117px;" /></span></div><div><br />
</div><div><span style="font-family: verdana; font-size: 85%;"></span></div><div><span style="font-family: verdana; font-size: 85%;">Lorsque nous faisons un <em>drag and drop</em> d’un de ces contrôles dans le formulaire web, la directive <em>Registrer</em> sera ajouté en haut de formulaire.<br />
</span></div><div align="left"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5317903406558809090" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAUujU8zHdTRZ_IPuyXOaInn0FiBWMf2oGfw3N1ECEjQMlAVYFVTJolChxL8wv4mdPEsNyWsDD9l5rZaW3U0qnBB3BhDOoC0vOIO2TWHjqQ5fCHCtTOoERKY1hK-dKjBD62iwHHUwKrk4/s400/5.bmp" style="cursor: hand; display: block; height: 39px; margin: 0px auto 10px; text-align: center; width: 400px;" /></div><div>Afin d’éviter d’avoir cette déclaration dans plusieurs pages, nous pouvons très bien l’insérer une fois pour toute dans le fichier <em>web.config</em>. Pour cela, il faut déclarer dans la section <em>configuration/system.web/pages/controls</em> :<br />
<add assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"></div><img alt="" border="0" id="BLOGGER_PHOTO_ID_5317903575947667874" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2B6XFFtPaqjnwLqftd6agST3lhFZKfWwi09u81GE9JwxsXuvI3JytumzBapORjr0oBcWpcmmDDb-BUsnLyw6P_owX8_DJGWZZ7GtAiiQgYTIvJu8yeOX06_sf8Ow978epsqJpJ1o0iXM/s400/6.bmp" style="cursor: hand; display: block; height: 34px; margin: 0px auto 10px; text-align: center; width: 400px;" /> Par défaut le <em>tagPrefix</em> est nommé <em>cc1</em>. Remplacer avec un libellé plus compréhensible.<br />
<br />
Afin de réaliser d’enchaînement des formulaires de validation, un web contrôle <em>wizard</em> est utilisé dans un contrôle d’extension Ajax <em>UpdatePanel</em>. Le <em>wizard</em> est affiché en pop up modal en grisant le contenu principal. Cela empêche l’utilisateur d’interagir avec la page principale pendant qu’il remplisse le <em>wizard</em>. Pour réaliser cela, le contrôle <em>AjaxControlToolkit</em> <em>ModalPopupExtender</em> est utilisé.<br />
<br />
Le contrôle <em>UpdatePanel</em> permet de ne mettre à jour ses contenus lors d’un aller retour serveur.<br />
Le contrôle <em>Wizard</em> permet d’avoir une interface multi étapes avec les boutons suivant-précédent et la gestion des états intégrés.<br />
Le contrôle <em>ModalPopupExtender</em> permet d’ouvrir un élément de page en tant que pop up modal.<br />
L’ouverture se fera côté client. Lorsqu’il est nécessaire de faire un <em>postback</em>, il suffit d’ajouter la propriété <em>OnClick</em> sur les boutons d’ouverture/de fermeture de pop up.<br />
<br />
Ci-dessous un extrait de la page <em>aspx</em> : </div><div><span style="font-family: Verdana; font-size: 85%;"></span><updatepanel id="Panel1"><wizard></wizardsteps><br />
</wizard></contenttemplate><triggers></triggers><span style="font-family: verdana; font-size: 85%;"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5317903064799020450" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRpyosLk2HFVYWZDOwOg47MMS03RgEsDebT0KzvBI6x9bUiCuir-2iDp9HOOvknMeg0A4P8Z8zRuPjQ6QO86MEQ72HmKXYth4q0qLe8ABcw11QgdGsSxdZxT9L5DMjFoNyp_k_ublMaBQ/s400/4.bmp" style="cursor: hand; display: block; height: 314px; margin: 0px auto 10px; text-align: center; width: 400px;" /></span></updatepanel><span style="font-family: verdana; font-size: 85%;">Pour aller plus loin : </span><a href="http://ajaxcontroltoolkit.com/"><span style="font-family: verdana; font-size: 85%;">http://ajaxcontroltoolkit.com/</span></a><span style="font-family: verdana; font-size: 85%;"> </span></div></div></div></div></div></div></div>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-35027485026392659152009-03-18T06:18:00.000-07:002010-06-15T10:00:45.902-07:00Could not load type 'System.Web.UI.ScriptReferenceBase'<span style="font-family: verdana; font-size: 85%;">I am currently working on a web site project using AjaxControlToolKit with .NET3.5 SP1.</span><br />
<span style="font-family: verdana; font-size: 85%;">Today I deploy the web site into a test server Windows 2008.<br />
I was surprised as I got this message on the browser:<br />
<em><span style="color: #ff6666;">Could not load type 'System.Web.UI.ScriptReferenceBase' from assembly 'System.Web.Extensions, Version=3.5.0.0,...</span></em></span><br />
<span style="font-family: verdana; font-size: 85%;"><em><span style="color: #ff6666;"><br />
</span></em>After workaround I found that .NET3.5 is installed on my machine but not on the server.<br />
But with this tricky solution, I did not need to install .NET3.5 SP1 version on server nor recompile my web site with .NET 3.5.<br />
<br />
Replace <strong>ajaxToolkit:ToolkitScriptManager to asp:ScriptManager</strong> in the aspx file.<toolkitscriptmanager.........></toolkitscriptmanager.........></span><br />
<br />
<toolkitscriptmanager.........></toolkitscriptmanager.........>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0tag:blogger.com,1999:blog-2702485579611547622.post-78834200591633762442009-03-03T07:02:00.000-08:002010-06-15T10:01:14.132-07:00Générer Excel en C#<span style="font-family: verdana; font-size: 85%;"></span><a href="" name="_Toc215538444"><span style="font-family: verdana; font-size: 85%;"><strong>GENERATION EXCEL VIA OBJET COM</strong></span></a><br />
<span style="font-family: verdana; font-size: 85%;">La génération utilise directement l’objet Excel installé sur le poste.<br />
<strong>Avantages :</strong><br />
- Emuler l’interface d’utilisateur Excel, avoir la main sur chaque cellule Excel pour affter une valeur, la formater,…<br />
- Le fichier généré du type d’Excel binaire (plus sécurisant)<br />
<strong>Incovenients :</strong><br />
- Nécessite que Excel soit installé<br />
- Le temps de génération est long si le fichier est volumineux<br />
</span><a href="" name="_Toc215538446"><span style="font-family: verdana; font-size: 85%;"><strong>Mise en oeuvre</strong></span></a><br />
<span style="font-family: verdana; font-size: 85%;">Pour povoir piloter Excel, il faut ajouter la référence vers le library d’Excel.<br />
Ajouter ensuite dans la ligne directive « Using » cette ligne :<br />
<em>using Excel = Microsoft.Office.Interop.Excel;</em><br />
Les classes les plus importantes dans le modèle d’objet Excel sont:<br />
1. Microsoft.Office.Interop.Excel.Application représente l’application Excel<br />
2. Microsoft.Office.Interop.Excel.Workbook représente un classeur dans l’application<br />
3. Microsoft.Office.Interop.Excel.Worksheet représente une feuille d’Excel<br />
4. Microsoft.Office.Interop.Excel.Range représente une cellule, une ligne, une colonne, une sélection de cellules contenant un ou plusieurs blocs de cellules. Avant de pouvoir manipuler une zone dans Excel, vous devez la spécifier comme étant un objet Range.<br />
<br />
Dans cet exemple nous allons générer deux feuilles d’Excel. La première feuille contient une liste des notes et la deuxième feuille contient une liste des couleurs. Vous allez voir comment instancier on objet Excel, remplir chaque cellule, faire un formatage sur une cellule ainsi que sur un ensemble des cellules et enfin sauvegarder le fichier.<br />
<br />
<em>// Saisir le nom de fichier Excel à enregistrer<br />
this.sfdExcel.FileName = "notes.xls";<br />
if(this.sfdExcel.ShowDialog() == DialogResult.OK)<br />
{<br />
object Missing = System.Reflection.Missing.Value;<br />
<br />
Excel.Application xlsApp;<br />
Excel.Workbook xlsClasseur;<br />
Excel.Worksheet xlsFeuille;<br />
Excel.Range xlsRange;<br />
<br />
// Créer un document Excel<br />
xlsApp = new Excel.Application();<br />
// Ne pas tenir compte des alertes<br />
xlsApp.DisplayAlerts = false;<br />
<br />
try<br />
{<br />
// Ajout d'un classeur<br />
xlsClasseur = xlsApp.Workbooks.Add(true);<br />
<br />
#region Première feuille<br />
xlsFeuille = (Excel.Worksheet)xlsClasseur.Worksheets[1];<br />
<br />
// Remplir la cellule [1,1] avec un libellé et mettre la couleur de fond gris<br />
xlsFeuille.Cells[1,1] = "Ne pas modifier les données dans des cellules de cette couleur";<br />
xlsRange = xlsFeuille.get_Range(xlsFeuille.Cells[1,1],xlsFeuille.Cells[1,5]);<br />
xlsRange.Interior.ColorIndex = 15;<br />
xlsRange.Merge(Missing);<br />
<br />
// Les entêtes des colonnes<br />
xlsFeuille.Cells[2,1] = "Nom";<br />
xlsFeuille.Cells[2,2] = "Prénom";<br />
xlsFeuille.Cells[2,3] = "Note";<br />
<br />
// Les notes<br />
xlsFeuille.Cells[3,1] = "LAGRANGE";<br />
xlsFeuille.Cells[3,2] = "BERNADETH";<br />
xlsFeuille.Cells[3,3] = 12.13;<br />
<br />
xlsFeuille.Cells[4,1] = "LAMBUPOULOS";<br />
xlsFeuille.Cells[4,2] = "ERIC";<br />
xlsFeuille.Cells[4,3] = 17.51;<br />
<br />
// Mettre la largeur de colonne suivant la longueur de texte<br />
xlsRange = xlsFeuille.get_Range("A3","C3");<br />
xlsRange.EntireColumn.AutoFit();<br />
<br />
// Formatter les notes avec un seul virgule derrière<br />
xlsRange = xlsFeuille.get_Range(xlsFeuille.Cells[3,3],xlsFeuille.Cells[4,3]);<br />
xlsRange.NumberFormat = "0.0";</em><br />
<br />
<em>// Mettre les textes au milieu<br />
xlsRange = xlsFeuille.get_Range(xlsFeuille.Cells[2,1],xlsFeuille.Cells[4,3]);<br />
xlsRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;<br />
<br />
// Mettre le border couleur noir<br />
xlsRange = xlsFeuille.get_Range(xlsFeuille.Cells[2,1],xlsFeuille.Cells[4,3]);<br />
xlsRange.Borders.ColorIndex = 1;<br />
<br />
#endregion<br />
<br />
#region Deuxième feuille<br />
xlsFeuille = (Excel.Worksheet)xlsClasseur.Worksheets.Add(Missing,xlsFeuille,1,Missing);<br />
// Liste des couleurs de fond<br />
for(int i = 1; i <= 56; i++) { xlsFeuille.Cells[i, 1] = i; xlsRange = xlsFeuille.get_Range(xlsFeuille.Cells[i,2],xlsFeuille.Cells[i,2]); xlsRange.Interior.ColorIndex = i; } #endregion // Enregistrer </em></span><br />
<span style="font-family: verdana; font-size: 85%;"><em>xlsApp.ActiveWorkbook.SaveAs(this.sfdExcel.FileName,<br />
Missing, Missing, Missing, Missing, Missing, Excel.XlSaveAsAccessMode.xlNoChange,<br />
Missing, Missing,<br />
Missing, Missing, Missing);<br />
……….</em></span><a href="" name="_Toc215538447"><span style="font-family: verdana; font-size: 85%;"><strong>GENERATION EXCEL VIA XML</strong></span></a><br />
<span style="font-family: verdana; font-size: 85%;">La génération d’Excel enregistre le fichier sous forme de feuille de calcul XML.<br />
<strong>Avantages :</strong>-Il ne nécessite pas qu’Excel soit installé<br />
-La génération est rapide même si la taille de fichier généré est volumineuse<br />
<strong>Inconvénients :</strong><br />
-La taille de fichier généré peut être deux fois plus la taille de fichier Excel par défaut<br />
-Le fichier est généré est un fichier XML qu’on peut ouvrir avec un logiciel de texte (moins sécurisant) </span><a href="" name="_Toc215538449"><span style="font-family: verdana; font-size: 85%;"><strong>Mise en œuvre</strong></span></a><span style="font-family: verdana; font-size: 85%;"><br />
</span><a href="" name="_Exemple_2_:_Génération de PDF à par"></a><span style="font-family: verdana; font-size: 85%;">Il existe un library permettent de générer Excel via XML facilement.<br />
<br />
Ce library est téléchargeable à partir de : </span><a href="http://www.carlosag.net/Tools/ExcelXmlWriter/"><span style="font-family: verdana; font-size: 85%;">http://www.carlosag.net/Tools/ExcelXmlWriter/</span></a><br />
<span style="font-family: verdana; font-size: 85%;"><br />
Il est gratuit et est écrit entièrement en C#. </span><span style="font-family: verdana; font-size: 85%;"></span>Lusiahttp://www.blogger.com/profile/16071452554629164650noreply@blogger.com0