Wednesday, January 28, 2009

Fix Version Increment in Visual Studio 2008

Visual Studio 2008's version increment doesn't work properly. Here's an add-in to fix it: http://www.codeplex.com/autobuildversion.

So if want the assembly version to be the same, but the file number to be incremented, this tool will allow you to easily configure these settings.

Tuesday, January 20, 2009

Return HTML from a Web page (VB.NET & PHP)

If you need to get the HTML from a Web page to rip it, process it, and/or display it in the way you want, the following function is key:

Public Function GetHTML(ByVal sURL As String, ByVal e As Integer) As String
   Dim oHttpWebRequest As System.Net.HttpWebRequest
   Dim oStream As System.IO.Stream
   Dim sChunk As String
   oHttpWebRequest = (System.Net.HttpWebRequest.Create(sURL))
   Dim oHttpWebResponse As System.Net.WebResponse = oHttpWebRequest.GetResponse()
   oStream = oHttpWebResponse.GetResponseStream
   sChunk = New System.IO.StreamReader(oStream).ReadToEnd()
   oStream.Close()
   oHttpWebResponse.Close()
   If e = 0 Then
      Return Server.HtmlEncode(sChunk)
   Else
      Return Server.HtmlDecode(sChunk)
   End If
End Function

And here's how to do it in PHP

$file = file_get_contents('http://www.yoururl.com');

*snicker*

Simple String Encryption

Public Function EncryptString(ByVal InSeed As Integer, ByVal InString As String) As String
   Dim c1 As Integer
   Dim NewEncryptString As String
   Dim EncryptSeed As Integer
   Dim EncryptChar As String

   NewEncryptString = ""
   EncryptSeed = InSeed
   For c1 = 1 To Len(InString)
      EncryptChar = Mid(InString, c1, 1)
      EncryptChar = Chr(Asc(EncryptChar) Xor EncryptSeed)
      EncryptSeed = EncryptSeed Xor c1
      NewEncryptString = NewEncryptString & EncryptChar
   Next

   EncryptString = NewEncryptString
End Function

Passing in a seed and your string will return an encrypted string. Pass in the same seed and the encrypted string again and it will return the original unencrypted string.

Wednesday, January 7, 2009

Loop Through Web AppSettings

For Each appSetting As String In ConfigurationManager.AppSettings.AllKeys
   Dim appSettingValue = ConfigurationManager.AppSettings.Get(appSetting)
Next


In this case, appSetting would be returning the key, where as appSettingValue is the value.

Friday, January 2, 2009

Use Temporary Tables in MSSQL

Create
CREATE TABLE #TempTable(FieldName1 VarChar(50), DateField1 DateTime, FieldName2 Int)
Inserting into the temp table is executed like any other table:
INSERT INTO #TempTable () VALUES ()
The table is dropped when the session is dropped. Otherwise:
DROP TABLE #TempTable