Archive for November, 2008

Setting up session state database on sql server

Just a quick reminder for myself- if you have a fresh sql database that you want to install the default asp.net session database on for use by your applications, the command line value you want is;

aspnet_regsql.exe -S <server> -U <dbuser> -P <password> -ssadd -sstype p

To then set your application up to use sql server for state maintenance, add the following to your web.config file;

ASP.net 1.1.4x:

Under the <system.web> section

<sessionState
mode="SQLServer"
timeout="20"
cookieless="false"
sqlConnectionString="Data Source=WEBSQL; User
Id=xxx;Password=xxx;"”
/>

ASP.net 2.0.5x

Again under the <system.web> section (not using the standard state database name)

<sessionState
mode="SQLServer"
allowCustomSqlDatabase="true"
sqlConnectionString="Data Source=WebSQL;
database=ASPStateDotNet2;user id=xxx;password=xxx"
cookieless="false"
timeout="40"
/>

We had a 1.1 session store already setup and setup the .net 2 seession store on the same server under a different database name. To do this just append a “-d ” parameter to the end of the command line.

No Comments

Automatically creating outlook signatures using LDAP and a VB Login script

This is a nice way of automatically building up outlook email signatures- the example given doesn’t include an image though, and it needs accurate LDAP data!  This code originated here and i copy it here incase that article ever dissapears!

 Set objUser = CreateObject("WScript.Network")
userName = objUser.UserName
domainName = objUser.UserDomain

FUNCTION GetUserDN(BYVAL UN, BYVAL DN)
Set ObjTrans = CreateObject("NameTranslate")
objTrans.init 1, DN
objTrans.set 3, DN & "\" & UN
strUserDN = objTrans.Get(1)
GetUserDN = strUserDN
END FUNCTION

Set objLDAPUser = GetObject("LDAP://" & GetUserDN(userName,domainName))

'Prepare to create some files
Dim objFSO, objWsh, appDataPath, pathToCopyTo, plainTextFile,
plainTextFilePath, richTextFile, richTextFilePath, htmlFile,
htmlFilePath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWsh = CreateObject("WScript.Shell")
appDataPath = objWsh.ExpandEnvironmentStrings("%APPDATA%")
pathToCopyTo = appDataPath & "\Microsoft\Signatures\"

'Let's create the plain text signature
plainTextFilePath = pathToCopyTo & "Default.txt"
Set plainTextFile = objFSO.CreateTextFile(plainTextFilePath, TRUE)
plainTextFile.WriteLine("-- ")
plainTextFile.WriteLine(objLDAPUser.DisplayName)
plainTextFile.WriteLine(objLDAPUser.title)
plainTextFile.WriteLine(objLDAPUser.company)
plainTextFile.WriteLine("t: " & objLDAPUser.telephoneNumber)
plainTextFile.WriteLine("f: " & objLDAPUser.facsimileTelephoneNumber)
plainTextFile.WriteLine("e: " & objLDAPUser.mail)
plainTextFile.Write("w: " & objLDAPUser.wWWHomePage)
plainTextFile.Close

'Now we create the Rich Text signature
richTextFilePath = pathToCopyTo & "Default.rtf"
Set richTextFile = objFSO.CreateTextFile(richTextFilePath, TRUE)
richTextFile.WriteLine("{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0
Arial;}}")
richTextFile.WriteLine("\viewkind4\uc1\pard\f0\fs20 -- \par")
richTextFile.WriteLine(objLDAPUser.DisplayName & "\par")
richTextFile.WriteLine(objLDAPUser.title & "\par")
richTextFile.WriteLine(objLDAPUser.company & "\par")
richTextFile.WriteLine("t: " & objLDAPUser.telephoneNumber & "\par")
richTextFile.WriteLine("f: " & objLDAPUser.facsimileTelephoneNumber & "\par")
richTextFile.WriteLine("e: " & objLDAPUser.mail & "\par")
richTextFile.WriteLine("w: " & objLDAPUser.wWWHomePage & "\par")
richTextFile.Write("}")
richTextFile.Close

'And finally, the HTML signature
htmlFilePath = pathToCopyTo & "Default.htm"
Set htmlFile = objFSO.CreateTextFile(htmlFilePath, TRUE)
htmlfile.WriteLine("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0
Transitional//EN""
""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">")
htmlfile.WriteLine("<html xmlns=""http://www.w3.org/1999/xhtml"" >")
htmlfile.WriteLine("<body>")
htmlfile.WriteLine("<div style=""font-size:10pt;
font-family:'Arial','helvetica';"">")
htmlfile.WriteLine("<div>-- </div>")
htmlfile.WriteLine("<div>" & objLDAPUser.DisplayName & "</div>")
htmlfile.WriteLine("<div>" & objLDAPUser.title & "</div>")
htmlfile.WriteLine("<div>" & objLDAPUser.company & "</div>")
htmlfile.WriteLine("<div>t: " & objLDAPUser.telephoneNumber & "</div>")
htmlfile.WriteLine("<div>f: " & objLDAPUser.facsimileTelephoneNumber & "</div>")
htmlfile.WriteLine("<div>e: <a href="" & objLDAPUser.mail & "">" &
objLDAPUser.mail & "</a></div>")
htmlfile.WriteLine("<div>w: <a href=""http://" &
objLDAPUser.wWWHomePage & """>" & objLDAPUser.wWWHomePage &
"</a></div>")
htmlfile.WriteLine("</div>")
htmlfile.WriteLine("</body>")
htmlfile.Write("</html>")

No Comments

Useful commonly used C# functions

Another useful site- i was after a Proper Case (PCase) style function for c# and found this online;

  public static String PCase(String strParam)
{
String strProper = strParam.Substring(0, 1).ToUpper();
strParam = strParam.Substring(1).ToLower();
String strPrev = "";
for (int iIndex = 0; iIndex < strParam.Length; iIndex++)
{
if (iIndex > 1)
{
strPrev = strParam.Substring(iIndex - 1, 1);
}
if (strPrev.Equals(" ") ||
strPrev.Equals("\t") ||
strPrev.Equals("\n") ||
strPrev.Equals("."))
{
strProper += strParam.Substring(iIndex, 1).ToUpper();
}
else
{
strProper += strParam.Substring(iIndex, 1);
}
}
return strProper;
}

This and a whole bunch of other useful functions can be found here.

No Comments

VB to C# Code Converter

Just found a cool tool online for converting vb code to c#, and vice-versa.  It's not 100% perfect so make sure you have a look through what it turfs out, but it's handy for converting small code snippets of example functions you find online.  It's up on the DeveloperFusion website here.

No Comments