Archives de juillet 2005
Set ValueToCompare at run time
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)
Server unavailable fixup
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)
Générer une chaine aléatoire
///
/// 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)
Encoder une chaine en SHA1 et hexa
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)
Encoder une chaine en MD5 et hexa
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)
Fonction upperCase à la française
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();
}
object.innerText for IE and FF
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.