michelc Blog

Just <strong>another</strong> WordPress.com weblog

Archives de juillet 2005

Set ValueToCompare at run time

sans commentaires

Lorsque un contrôle CompareValidator est utilisé pour contrôler une date et que la valeur de comparaison est définie côté code, il faut formatter cette date au format de date courte :

myCompareValidator.ValueToCompare = myDateTime.ToShortDateString();

(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/524)

Rédigé par michel

29 juillet 2005 à 5:33

Publié dans Code Snippets, c#

Server unavailable fixup

sans commentaires

Quand IIS fait boum! (généralement lorsqu’on a tué le processus aspnet_wp.exe alors qu’on était en plein débugage), y’a plus qu’à :

REM This batch file addresses "Server unavailable" error
@echo off

REM “Changing to the Framework install directory”
cd /d C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322

echo “Stopping IIS”
iisreset /stop
echo “———————-”

echo “Stopping the ASP.NET state service if it is running”
net stop aspnet_state
echo “———————-”

echo “Re-registering ASP.NET”
aspnet_regiis -i
echo “———————-”

echo “Restarting IIS”
iisreset /start
echo “———————-”

(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/519)

Rédigé par michel

27 juillet 2005 à 5:27

Publié dans Code Snippets

Générer une chaine aléatoire

sans commentaires

///
/// Build a random string (for id, login, password...)
///
public static string randomString() {
int length = new Random().Next(6, 10);
return randomString(length);
}

///
/// Build a random string (for id, login, password...)
///
public static string randomString(int length) {
string tempString = Guid.NewGuid().ToString().ToLower();
tempString = tempString.Replace("-", "");
while (tempString.Length

(Publié à l'origine sur http://www.bigbold.com/snippets/posts/show/518)

Rédigé par michel

27 juillet 2005 à 5:20

Publié dans Code Snippets, c#

Encoder une chaine en SHA1 et hexa

sans commentaires

public static string SHA1_ComputeHexaHash (string text) {
// Gets the SHA1 hash for text
SHA1 sha1 = new SHA1CryptoServiceProvider();
byte[] data = Encoding.Default.GetBytes(text);
byte[] hash = sha1.ComputeHash(data);
// Transforms as hexa
string hexaHash = "";
foreach (byte b in hash) {
hexaHash += String.Format("{0:x2}", b);
}
// Returns SHA1 hexa hash
return hexaHash;
}

(publié à l’origine sur http://www.bigbold.com/snippets/posts/show/517)

Rédigé par michel

27 juillet 2005 à 5:18

Publié dans Code Snippets, c#

Encoder une chaine en MD5 et hexa

sans commentaires

public static string MD5_ComputeHexaHash (string text) {
// Gets the MD5 hash for text
MD5 md5 = new MD5CryptoServiceProvider();
byte[] data = Encoding.Default.GetBytes(text);
byte[] hash = md5.ComputeHash(data);
// Transforms as hexa
string hexaHash = "";
foreach (byte b in hash) {
hexaHash += String.Format("{0:x2}", b);
}
// Returns MD5 hexa hash
return hexaHash;
}

(publié à l’origine sur http://www.bigbold.com/snippets/posts/show/516)

Rédigé par michel

27 juillet 2005 à 4:45

Publié dans Code Snippets, c#

Fonction upperCase à la française

sans commentaires

Fonction upperCase gérant les accents et caratères spéciaux du français :

///
/// Returns a copy of a string in uppercase, without accents
///
/// Valid string expression
/// String converted to uppercase
public static string upperCase (string text) {
const string accents = "ÁÀÄÂÉÈËÊÍÌÏÎÓÒÖÔÚÙÜÛŸÇ";
const string normaux = "AAAAEEEEIIIIOOOOUUUUYC";
string majuscules = text.ToUpper();
for (int i = 0; i

Et la fonction lowerCase correspondante :

///
/// Returns a copy of a string in lowercase, without accents
///
/// Valid string expression
/// String converted to lowercase
public static string lowerCase (string text) {
return upperCase(text).ToLower();
}

Rédigé par michel

27 juillet 2005 à 4:40

Publié dans Code Snippets, c#

object.innerText for IE and FF

sans commentaires

Un système pour émuler la propriété innerText sous Firefox :

function getInnerText(elt) {
var _innerText = elt.innerText;
if (_innerText == undefined) {
_innerText = elt.innerHTML.replace(/<[^>]+>/g,"");
}
return _innerText;
}

Il suffit ensuite de remplacer :

var text = elt.innerText;

par :

var text = getInnerText(elt);

(publié à l’origine sur http://www.bigbold.com/snippets/posts/show/514)

En pratique, la propriété textContent a le même effet que innerText pour Firefox.

Rédigé par michel

27 juillet 2005 à 4:21

Publié dans Code Snippets, javascript