vendredi 8 août 2008

Valeurs par defaut de contrôles dans un formulaire SharePoint

Besoin récurrent lors de la manipulation de formulaire Sharepoint, pouvoir positionner automatiquement la valeur d'une combobox selon un identifiant présent dans la querystring (exemple au hasard :))

Une méthode fournie par Microsoft SharePoint Team Blog : Using Javascript to Manipulate a List Form Field consiste à utiliser un script Javascript qui va se charger d'analyser la querystring et de retrouver le contrôle pour l'initialiser avec la valeur qui va bien

prévoyez donc un fichier "script.js" avec le code suivant :

// This javascript sets the default value of a lookup field identified
// by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
// identified by <<QUERYSTRING VARIABLE NAME>>

// Customize this javascript by replacing <<FIELD DISPLAY NAME>> and
// <<QUERYSTRING VARIABLE NAME>> with appropriate values.
// Then just paste it into NewForm.aspx inside PlaceHolderMain

_spBodyOnLoadFunctionNames.push("fillDefaultValues");

function fillDefaultValues() {
var qs = location.search.substring(1, location.search.length);
var args = qs.split("&");
var vals = new Object();
for (var i=0; i < args.length; i++) {
var nameVal = args[i].split("=");
var temp = unescape(nameVal[1]).split('+');
nameVal[1] = temp.join(' ');
vals[nameVal[0]] = nameVal[1];
}
setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals["<<QUERYSTRING VARIABLE NAME>>"]);
}

function setLookupFromFieldName(fieldName, value) {
if (value == undefined) return;
var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
// if theSelect is null, it means that the target list has more than
// 20 items, and the Lookup is being rendered with an input element
if (theSelect == null) {
var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
ShowDropdown(theInput.id); //this function is provided by SharePoint
var opt=document.getElementById(theInput.opt);
setSelectedOption(opt, value);
OptLoseFocus(opt); //this function is provided by SharePoint
} else {
setSelectedOption(theSelect, value);
}
}

function setSelectedOption(select, value) {
var opts = select.options;
var l = opts.length;
if (select == null) return;
for (var i=0; i < l; i++) {
if (opts[i].value == value) {
select.selectedIndex = i;
return true;
}
}
return false;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}
Remplacer les valeurs <<FIELD DISPLAY NAME>> et <<QUERYSTRING VARIABLE NAME>> par vos valeurs.
Insérer , via SharePoint designer par exemple, la ligne suivante dans votre page :
<script language="javascript" src="script.js"></script>
Selon les cas cela demandera un d'adaptation mais l'essentiel est là.

jeudi 7 août 2008

Intellisense SharePoint dans Visual Studio

La petite astuce qui mange pas de pain et permet d'augmenter votre intellisense!! :)

Copier
"C:\Program Files\Fichiers communs\Microsoft Shared\web server extensions\12\TEMPLATE\XML\wss.xsd"
dans
"c:\program files\Microsoft Visual Studio 8\XML\Schemas"
Bien sûr, modifier les chemins selon votre configuration

Importer correctement un fichier html

Avec cette petite méthode vous pouvez downloader un fichier HTML avec un encodage correct sans tous les caractères spéciaux et autres entité html

internal string Download(string source, string destination)
{

HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(source);
string chemin = string.Empty;

using (WebResponse Response = WebRequestObject.GetResponse())
{
using (Stream WebStream = Response.GetResponseStream())
{
System.Text.Encoding encod = System.Text.Encoding.GetEncoding("iso-8859-1");
using (StreamReader Reader = new StreamReader(WebStream,encod))
{
string nom = "NomDuFichier";
chemin = Path.Combine(destination, nom);
using (StreamWriter sw = new StreamWriter(chemin))
{
sw.Write(HttpUtility.HtmlDecode(Reader.ReadToEnd()));
}
}

}

}
return chemin;

}

lundi 4 août 2008

LinksList 04

.NET
  1. “How Do I?” Videos — Data Platform Development
  2. LINQ to Objects : l'envers du décor
  3. Développement avec Visual Studio Tools pour Office
  4. LINQ To SQL Tutorial
  5. Utiliser LINQ to SQL (Partie 1)
  6. LINQ to SQL (Partie 2 - Définition de nos classes du modèle de données)
  7. [.NET] Comprendre la philosophie des exceptions sous .NET
  8. [Silverlight] Comment bien débuter avec Silverlight 2.0 ?

SHAREPOINT
  1. SitePoint CSS Reference
  2. Créer une activité personnelle pour les workflows Sharepoint Designer
  3. Introduction to data calculations
  4. Aide de l'Administration centrale (Office SharePoint Server 2007)
  5. Notes: 70-541 MCTS SharePoint Services 3.0 - Application Development
  6. Paul Andrew : MSSharePointDeveloper Content
  7. Docs Table
  8. patterns & practices SharePoint Guidance

Tout pour les Customs Actions...

...et notamment pour créer une Custom Action (CA) uniquement pour une liste précise.
  1. Créer une feature spécifique de la liste concernée à l'aide de SharePoint Solution Generator (option "Définition de liste")
  2. Dans le dossier "12\TEMPLATE\FEATURES\{Votre Feature}\{Votre Feature}", ouvrir le fichier "ListDefinition.xml" et modifier l'argument Type du noeud ListTemplate avec un chiffre supérieur à 10000
  3. Dans le dossier "12\TEMPLATE\FEATURES\{Votre Custom Action}", ouvrir "elements.xml" et modifier l'argument RegistrationId du noeud CustomAction avec le chiffre que vous avez choisi à l'étape numéro 2
  4. iisreset
Quelques liens pour la route :
Creating Menu Item for a Specific List/Document Library Template
Sharepoint 2007 : Les Custom Actions
CustomAction Element (Custom Action)
How to: Add Actions to the User Interface