Saturday, December 27, 2008

Customize the SendTo Windows Extension in Vista

Start run, and this is the place...

%APPDATA%\Microsoft\Windows\SendTo

Router Madness - it's not that hard

So I recently signed up for Comcast, and I went out and bought a motorolla modem and a router.
The comcast tech support guy reminded me of a very basic troubleshooting step to get everything working.

1-Unplug both the router and the cable modem from the power.

2-Unplug all ethernet connections from both the router and the cable modem.

3-Plug the power back into the cable modem. Connect the internet cable back into the cable modem.

4-Plug in the router's power. Connect the cable modem to the router.

5-Start connecting each PC to the router. This allows the DCHP to give each PC a valid IP address and thus be able to get on the network.

Friday, December 19, 2008

C# Hello World Console

//Built using VS 2005, C# Console
// A simple hello world in C#


using System;
using System.Collections.Generic;
using System.Text;
namespace CSharpConsoleCodeTesting
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World"); // output text to the console.
Console.ReadLine(); // wait for user to hit enter to close console.
}
}
}

Left margins on controls in webpages

Sometimes, you want to place a left margin on a control on a webpage that is in flow layout.
Here is something that works nicely. Example....

style="margin-left: 20px"

I noticed that this style does not work inside the tr's and td's of a table.
I could be wrong though.

Selecting the column names of a sql table

Order defaults to alpha..

SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name= 'MyTable')

Order set to column order..

SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name= 'MyTable')ORDER by colorder

Selecting an item in an asp.net dropdownlist programmatically

myDropDownList.SelectedIndex = myDropDownList.Items.IndexOf(myDropDownList.Items.FindByValue(value))

It might even be easier to do this...

myDropDownList.Items.FindByValue(value).Selected = True

Reseting the increment id back to 1 in SQL

Let's say you have a summary table, and everynight you have either an executable or a sql job that deletes all rows and then inserts new ones. If that table has an increment id column, you may want to reset it back to 1. Here is how you do that. Just replace 'mytable' with the actuall table.

DBCC CHECKIDENT('mytable', RESEED, 0);

Closing your app during a certain time range

Here is how you check a time range. Example, say you want your webpage to be closed during certain times of the night...

I got it at some forum, but honestly, It should be more straight forward.

Dim StartDateTime As DateTime = DateTime.Parse("3:00:00 AM")
Dim EndDateTime As DateTime = DateTime.Parse("4:30:00 AM")

If (DateTime.Now.CompareTo(StartDateTime) >= 0 AndAlso DateTime.Now.CompareTo(EndDateTime) <= 0) Then Response.Redirect("maintn.aspx") End If

Getting sql column names for a table

This is good if say you have like 100 columns or more and you need to reference each one in your code. Just run this select and copy and paste the column names into your code...

SELECT column_name FROM INFORMATION_SCHEMA.Columns
where TABLE_NAME = 'mytable'


Just replace mytable with the actual table name.

And if you want to take that to another level, then do this...

SELECT 'Dim ' + column_name + ' As Object' FROM INFORMATION_SCHEMA.Columns
where TABLE_NAME = 'myTable'

Navigate through functions in Visual Studio 2005

Man, I just discovered that I can hold down the control key and use arrow up or arrow down keys to navigate through functions in code. This freaking rocks man!

Getting a handle to a dropdownlists event that is inside a template column

Real easy. It's the sender in the function.....

Protected Sub myDRD_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Dim myDRD As New DropDownList
myDRD = CType(sender, DropDownList)

End Sub

Access another control in a datagrid based on an event from a different control

Say you have a dropdownlist that pops up in a datagrid when you click on the edit link and launch the edit command. And say there is another control in that row that you need a handle to when you change the index of that dropdownlist. Here is how you do it.

I have noticed that it's okay to use Cells(0) regardless of where the column is located.
As long as its in the same row.

Protected Sub drd1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Dim drd1 As New DropDownList drd1= CType(sender, DropDownList)
Dim drd2 As New DropDownList drd2 = CType(DataGrid1.Items.Item(DataGrid1.EditItemIndex).Cells(0).FindControl("drd2"), DropDownList)


End Sub

A SQL Server connection string that uses windows authentication

"Server=mySQLServerName;Database=MyDBName;persist security info=False;integrated security=SSPI;"

Just replace "mySQLServerName" with the name of the SQL server, and "MyDBName" with the name of the database.

Get the user name, machine name, and domain, via vbscript

Most of what I'm typing below I got from....
http://www.codeproject.com/KB/vbscript/userinfo.aspx

Open a text file, past the the text below and save it as a .vbs file.....

Dim objNet
Set objNet = CreateObject("WScript.NetWork")

Dim strInfoUserName
strInfoUserName = "User Name is " & objNet.UserName

Dim strInfoMachineName
strInfoMachineName = "Computer Name is " & objNet.ComputerName

Dim strInfoDomainName
strInfoDomainName = "Domain Name is " & objNet.UserDomain

MsgBox strInfoUserName
MsgBox strInfoMachineName
MsgBox strInfoDomainName



Here are the properties of the Network Object of WScrip.

Computer Name A string representation of the computer name.

UserDomain A string representation of the user's domain.

UserName A string representation of the user name.

These are the methods of Network Object of WScript.

AddPrinterConnection Maps a remote printer to a local resource name.

EnumNetworkDrives Returns the current network drive mappings.

EnumPrinterConnections Returns the current network drive mappings.

MapNetworkDrive Maps a share point to a local resource name.

RemoveNetworkDrive Removes the current resource connection.

RemovePrinterConnection Removes a current resource connection.

SetDefaultPrinter Sets the default printer.

Publishing VS projects via frontpage extensions

Did you know that you can do this? Simply just type the address that the site will have and the files will be copied and a virtual directory will be created as well.

Dependency Walker

Dependency Walker is an awesome freaking tool. Especially after you load a program and start profiling. You can see all the DLL and function calls, and it will also tell you if it can't find a dll. This is a great tool if you are troubleshooting a 3rd party application.

http://www.dependencywalker.com/

RegDllView

RegDllView is a great tool to see what dlls are registered on a machine.
It can also help you troubleshoot a 3rd party application.

Example, say you installed MyABCXYZ program in your program files and you want to see the dlls that the program registered during installation. Simply just look at the date that the MyABCXYZ program was installed.

Then open up RegDllView and sort by date. You can even export the report or part of it.

http://www.nirsoft.net/utils/registered_dll_view.html

Writing to a new file in VBA - Ms Access Module

Dim outFile 'Dim outFileOpen

outFile = FreeFile
'Merely VBs way of returning you the next available file handle

Open "C:\AccessDBInfo.txt" For Output As #outFile
'using the file handle and tying it with a path

Print #outFile, "Test1" + vbTab + "Test2"
'Writing to the file

Close #outFile
'Closing file handle


If you want to append to an existing file, simply use...
Open "C:\AccessDBInfo.txt" For Append Access Write Lock Write As #outFile
instead.

Getting the column and row count of all tables in an MS Access database via VBA module

For Each tempTable In CurrentDb.TableDefs
'for each table in the database

If tempTable.Name <> "MSysAccessObjects" _
And tempTable.Name <> "MSysAccessXML" _
And tempTable.Name <> "MSysACEs" _
And tempTable.Name <> "MSysObjects" _
And tempTable.Name <> "MSysQueries" _
And tempTable.Name <> "MSysRelationships" _
Then
'Avoid system tables

ColumnCount = CurrentDb.TableDefs(tempTable.Name).Fields.Count
' get the column count

RowCount = CurrentDb.TableDefs(tempTable.Name).RecordCount
'get the row count

MsgBox(tempTable.Name + vbTab + Str(ColumnCount) + _
vbTab + Str(RowCount))

End If

Next
'end of each table loop

Getting the column and row count of all queries in an MS Access database via VBA module

For Each tempQuery In CurrentDb.QueryDefs
'for each query in the database

If InStr(tempQuery.Name, "TMP") = 0 Then
'avoid picking up temp queries,
'via substring check


ColumnCount = CurrentDb.QueryDefs(tempQuery.Name).Fields.Count
'get the column count for the query

RowCount = DCount("*", tempQuery.Name)
'get the row count for the query

MsgBox(tempQuery.Name + vbTab + _
Str(ColumnCount) + vbTab + Str(RowCount))

End If

Next

Reading a text file stream asp.net

'You must first select a file with the browse button
'before you can run the code below.


Dim TempFile As String = System.IO.Path.GetTempFileName()
'Creates a uniquely named, zero-byte temporary file on
'disk and returns the full path of that file.

'This method creates a temporary file with a .TMP file extension.

File1.PostedFile.SaveAs(TempFile)
'File1 is my html input file object after using the browse
'button and selecting a file.

Dim TextSTR As String
TextSTR = My.Computer.FileSystem.ReadAllText(TempFile)

'My.Computer.FileSystem.ReadAllText returns the
'contents of a text file as a String


Response.Write(TextSTR)

System.IO.File.Delete(TempFile)

'Deletes the file

RadioButtonList

'When you want to make sure that they select something from a group
'of radiobuttons, use a radionbuttonlist, and check the selectedindex.
'Add the radio buttons to the items collections.


If (RadioButtonList1.SelectedIndex <= -1) Then
Response.Write("Please select something")

Else

Response.Write("You have selected: " + RadioButtonList1.SelectedItem.Text)

End If

Iterating through a string

'String.GetEnumerator Method
'Retrieves an object that can iterate
'through the individual characters in the string


Dim mystring As String = "Madness123"

Dim myCharEnumerator As CharEnumerator

myCharEnumerator = mystring.GetEnumerator()

While myCharEnumerator.MoveNext
Console.WriteLine(myCharEnumerator.Current.ToString())
End While




'Will display...

'M
'a
'd
'n
'e
's
's
'1
'2
'3


Console.ReadLine()

Getting the current day of the week in string format

This is how you get the current day of the week in a string format in csharp. Example... Monday, Tuesday, etc.....

string dayoftheweek = DateTime.Today.DayOfWeek.ToString();

Access methods after converting to another type - C#

So this below was not working because the compiler could not find the ToLower() method....

object myvalue;
// do other stuff here
myvalue = (string) value.ToLower();


But wrapping it up a little more exposes those methods.....

((string) value).ToLower();

Get current time of the day, non-military

Say you wanted to get the current time of the day into a string in the format of something like 05:19 PM. This is how you do it….

DateTime.Now.ToString("hh:mm tt")

Visual Studio 2005 - Form Designer problem, project from source safe from other machines

The other day, I tried opening a project from source safe that was originally created on another computer. After opening the project, I tried to open the Form designer for one of the forms, and I got an error message...... There is no editor available for C:\..\Form1.vb Make sure the application for the file type (.vb) is installed The fix was the build the project at least once. This allowed me to then open up the form.