smart developer’s blog

This is a C# resource library! Free how to’s and best practices…

Visual Studio .NET 2005 Keyboard Shortcuts

leave a comment »

No comments on this. Just use them:

Class Diagram


Num +

ClassDiagram

Expand

Shift + Alt + B

Edit

ExpandCollapseBaseTypeList

Ctrl + Del

Edit

Delete

Del

Edit

RemovefromDiagram

Enter

View

ViewCode

Shift + Alt + L

Edit

NavigateToLollipop

Num –

ClassDiagram

Collapse

DataSet Editor


Ins

Data

InsertColumn

Ctrl + L

Data

Column

Deployment Designer


Shift + Alt + D

Diagram

RedrawConnection

Shift + Alt + T

Diagram

RerouteConnection

Global


Ctrl + –

View

NavigateBackward

Ctrl + Shift + –

View

NavigateForward

Ctrl + .

View

ShowSmartTag

Ctrl + /

Tools

GoToCommandLine

Ctrl + \ , D

View

CodeDefinitionWindow

Ctrl + \ , E

View

ErrorList

Ctrl + \ , T

View

TaskList

Ctrl + Shift + 1

View

BrowseNext

Ctrl + Shift + 2

View

BrowsePrevious

Ctrl + Shift + 7

View

ForwardBrowseContext

Ctrl + Shift + 8

View

PopBrowseContext

Ctrl + A

Edit

SelectAll

Ctrl + Alt + A

View

CommandWindow

Ctrl + Shift + A

Project

AddNewItem

Shift + Alt + A

Project

AddExistingItem

Ctrl + Alt + B

Debug

Breakpoints

Ctrl + B

Debug

BreakatFunction

Ctrl + Shift + B

Build

BuildSolution

Alt + Bkspce

Edit

Undo

Ctrl + Alt + Break

Debug

BreakAll

Ctrl + Break

Build

Cancel

Ctrl + Alt + C

Debug

CallStack

Ctrl + Shift + C

View

ClassView

Ctrl + Alt + D

Debug

Disassembly

Ctrl + D

Edit

GoToFindCombo

Shift + Alt + D

Data

ShowDataSources

Shift + Del

Edit

Cut

Ctrl + Alt + Down Arrow

Window

ShowEzMDIFileList

Down Arrow

Edit

MoveControlDownGrid

Shift + Down Arrow

Edit

SizeControlDownGrid

Ctrl + Alt + E

Debug

Exceptions

Ctrl + Shift + E

View

ResourceView

Alt + Enter

Diagram

Properties

Enter

Edit

ShowTileGrid

Shift + Alt + Enter

View

FullScreen

Esc

Window

ActivateDocumentWindow

Shift + Esc

Window

CloseToolWindow

Ctrl + F

Edit

Find

Ctrl + Shift + F

Edit

FindinFiles

Ctrl + Alt + F1

Help

Contents

Ctrl + F1

Help

HowDoI

F1

Help

F1Help

Shift + F1

Help

WindowHelp

Alt + F10

Debug

ApplyCodeChanges

Ctrl + Alt + F10

Debug

StepOverCurrentProcess

Ctrl + F10

Debug

RunToCursor

Ctrl + Shift + F10

Debug

SetNextStatement

F10

Debug

StepOver

Alt + F11

Tools

MacrosIDE

Ctrl + Alt + F11

Debug

StepIntoCurrentProcess

Ctrl + F11

Debug

ToggleDisassembly

Ctrl + Shift + Alt + F11

Debug

StepOutCurrentProcess

F11

Debug

StepInto

Shift + F11

Debug

StepOut

Alt + F12

Edit

FindSymbol

Ctrl + Alt + F12

View

FindSymbolResults

Ctrl + F12

Edit

GoToDeclaration

Ctrl + Shift + F12

View

NextError

F12

Edit

GoToDefinition

Shift + Alt + F12

Edit

QuickFindSymbol

Shift + F12

Edit

FindAllReferences

Ctrl + Alt + F2

Help

Index

Ctrl + F2

Window

MovetoNavigationBar

F2

View

EditLabel

Alt + F3 , S

Edit

StopSearch

Ctrl + Alt + F3

Help

Search

Ctrl + F3

Edit

FindNextSelected

Ctrl + Shift + F3

Edit

FindPreviousSelected

F3

Edit

FindNext

Shift + Alt + F3

Help

SearchResults

Shift + F3

Edit

FindPrevious

Ctrl + F4

Window

CloseDocumentWindow

F4

View

PropertiesWindow

Shift + F4

View

PropertyPages

Alt + F5

Data

StepInto

Ctrl + Alt + F5

Data

Execute

Ctrl + F5

Debug

StartWithoutDebugging

Ctrl + Shift + F5

Debug

Restart

F5

Debug

Start

Shift + Alt + F5

Debug

StartWithApplicationVerifier

Shift + F5

Debug

StopDebugging

Alt + F6

Window

NextPane

Ctrl + F6

Window

NextDocumentWindow

Ctrl + Shift + F6

Window

PreviousDocumentWindow

F6

Window

NextSplitPane

Shift + Alt + F6

Window

PreviousPane

Shift + F6

Window

PreviousSplitPane

Alt + F7

Window

NextToolWindowNav

Ctrl + F7

Build

Compile

F7

View

ToggleDesigner

Shift + Alt + F7

Window

PreviousToolWindowNav

Alt + F8

View

MacroExplorer

F8

Edit

GoToNextLocation

Shift + F8

Edit

GoToPrevLocation

Alt + F9 , A

DebuggerContextMenus

BreakpointsWindow

Alt + F9 , D

DebuggerContextMenus

BreakpointsWindow

Alt + F9 , S

DebuggerContextMenus

BreakpointsWindow

Ctrl + F9

Debug

EnableBreakpoint

Ctrl + Shift + F9

Debug

DeleteAllBreakpoints

F9

Debug

ToggleBreakpoint

Shift + F9

Debug

QuickWatch

Ctrl + Alt + G

Debug

Registers

Ctrl + G

Edit

GoTo

Ctrl + Shift + G

Edit

OpenFile

Ctrl + Alt + H

Debug

Threads

Ctrl + H

Edit

Replace

Ctrl + Shift + H

Edit

ReplaceinFiles

Ctrl + Alt + I

Debug

Immediate

Ctrl + Alt + Ins

Project

Override

Ctrl + Ins

Edit

Copy

Ctrl + Shift + Ins

Edit

CycleClipboardRing

Shift + Ins

Edit

Paste

Ctrl + Alt + J

View

ObjectBrowser

Ctrl + K , Ctrl + B

Tools

CodeSnippetsManager

Ctrl + K , Ctrl + F

NewFolder

Ctrl + K , Ctrl + M

Edit

GenerateMethodStub

Ctrl + K , Ctrl + N

Edit

NextBookmark

Ctrl + K , Ctrl + P

Edit

PreviousBookmark

Ctrl + K , Ctrl + R

View

ObjectBrowserGoToSearchCombo

Ctrl + K , Ctrl + S

Edit

SurroundWith

Ctrl + K , Ctrl + V

View

ClassViewGoToSearchCombo

Ctrl + K , Ctrl + W

View

BookmarkWindow

Ctrl + K , Ctrl + X

Edit

InsertSnippet

Ctrl + Shift + K , Ctrl + Shift + N

Edit

NextBookmarkInFolder

Ctrl + Shift + K , Ctrl + Shift + P

Edit

PreviousBookmarkInFolder

Ctrl + Alt + L

View

SolutionExplorer

Alt + Left Arrow

View

Backward

Left Arrow

Edit

MoveControlLeftGrid

Shift + Left Arrow

Edit

SizeControlLeftGrid

Ctrl + Alt + M , 1

Debug

Memory1

Ctrl + Alt + M , 2

Debug

Memory2

Ctrl + Alt + M , 3

Debug

Memory3

Ctrl + Alt + M , 4

Debug

Memory4

Ctrl + Alt + N

Debug

ScriptExplorer

Ctrl + N

File

NewFile

Ctrl + Shift + N

File

NewProject

Alt + Num *

Debug

ShowNextStatement

Ctrl + Alt + O

View

Output

Ctrl + O

File

OpenFile

Ctrl + Shift + O

File

OpenProject

Ctrl + Alt + P

Tools

AttachtoProcess

Ctrl + P

File

Print

Ctrl + Shift + P

Tools

RunTemporaryMacro

Ctrl + PgDn

Window

NextTab

Ctrl + Q

Data

RunSelection

Ctrl + Alt + R

View

WebBrowser

Ctrl + R , Ctrl + E

Refactor

EncapsulateField

Ctrl + R , Ctrl + I

Refactor

ExtractInterface

Ctrl + R , Ctrl + M

Refactor

ExtractMethod

Ctrl + R , Ctrl + O

Refactor

ReorderParameters

Ctrl + R , Ctrl + P

Refactor

PromoteLocalVariable

Ctrl + R , Ctrl + R

Refactor

Rename

Ctrl + R , Ctrl + V

Refactor

RemoveParameters

Ctrl + Shift + R

Tools

RecordTemporaryMacro

Alt + Right Arrow

View

Forward

Right Arrow

Edit

MoveControlRightGrid

Shift + Right Arrow

Edit

SizeControlRightGrid

Ctrl + Alt + S

View

ServerExplorer

Ctrl + S

File

SaveSelectedItems

Ctrl + Shift + S

File

SaveAll

Ctrl + Alt + T

View

DocumentOutline

Ctrl + Shift + Tab

Window

PreviousDocumentWindowNav

Ctrl + Tab

Window

NextDocumentWindowNav

Shift + Tab

Edit

SelectPreviousControl

Tab

Edit

SelectNextControl

Ctrl + Alt + U

Debug

Modules

Shift + Up Arrow

Edit

SizeControlUpGrid

Up Arrow

Edit

MoveControlUpGrid

Ctrl + Alt + V , A

Debug

Autos

Ctrl + Alt + V , L

Debug

Locals

Ctrl + Alt + W , 1

Debug

Watch

Ctrl + Alt + W , 2

Debug

Watch2

Ctrl + Alt + W , 3

Debug

Watch3

Ctrl + Alt + W , 4

Debug

Watch4

Ctrl + Shift + W

File

ViewinBrowser

Ctrl + Alt + X

View

Toolbox

Ctrl + Shift + X

Test

StartSelectedTestProjectwithoutDebugger

Shift + Alt + X

Test

StartSelectedTestProjectwithDebugger

Ctrl + Alt + Z

Debug

Processes

Ctrl + Shift + Z

Edit

Redo

HTML Editor Design View


Ctrl + B

Format

Bold

Ctrl + Alt + Down Arrow

Layout

InsertRowBelow

Shift + F7

View

ViewMarkup

Ctrl + I

Format

Italic

Ctrl + L

Format

ConverttoHyperlink

Ctrl + Shift + L

Format

InsertBookmark

Ctrl + Alt + Left Arrow

Layout

InsertColumntotheLeft

Ctrl + M , Ctrl + C

Project

AddContentPage

Ctrl + M , Ctrl + M

View

EditMaster

Ctrl + Alt + Q

View

NonVisualControls

Ctrl + Q

View

VisibleBorders

Ctrl + Shift + Q

View

Details

Ctrl + Alt + Right Arrow

Layout

InsertColumntotheRight

Ctrl + U

Format

Underline

Ctrl + Alt + Up Arrow

Layout

InsertRowAbove

HTML Editor Source View


Ctrl + Shift + .

View

AutoCloseTagOverride

Shift + F7

View

ViewDesigner

Ctrl + PgDn

View

NextView

Ctrl + PgUp

Window

PreviousTab

Managed Resources Editor


Ctrl + 1

Resources

Strings

Ctrl + 2

Resources

Images

Ctrl + 3

Resources

Icons

Ctrl + 4

Resources

Audio

Ctrl + 5

Resources

Files

Ctrl + 6

Resources

Other

Del

Edit

Remove

Report Designer


Ctrl + Alt + D

View

Datasets

Ctrl + Down Arrow

Edit

MoveControlDown

Ctrl + Shift + Down Arrow

Edit

SizeControlDown

Down Arrow

Edit

LineDown

Shift + Down Arrow

Edit

LineDownExtend

Enter

Edit

BreakLine

Ctrl + Left Arrow

Edit

MoveControlLeft

Ctrl + Shift + Left Arrow

Edit

SizeControlLeft

Left Arrow

Edit

CharLeft

Shift + Left Arrow

Edit

CharLeftExtend

Ctrl + Right Arrow

Edit

MoveControlRight

Ctrl + Shift + Right Arrow

Edit

SizeControlRight

Right Arrow

Edit

CharRight

Shift + Right Arrow

Edit

CharRightExtend

Shift + Tab

Edit

TabLeft

Tab

Edit

InsertTab

Ctrl + Shift + Up Arrow

Edit

SizeControlUp

Ctrl + Up Arrow

Edit

MoveControlUp

Shift + Up Arrow

Edit

LineUpExtend

Up Arrow

Edit

LineUp

Settings Designer


Ctrl + Del

Edit

RemoveRow

Esc

Edit

SelectionCancel

F2

Edit

EditCell

Text Editor


Alt + ,

Edit

DecreaseFilterLevel

Alt + .

Edit

IncreaseFilterLevel

Ctrl + ]

Edit

GotoBrace

Ctrl + Shift + ]

Edit

GotoBraceExtend

Ctrl + =

Edit

SelectToLastGoBack

Bkspce

Edit

DeleteBackwards

Ctrl + Bkspce

Edit

WordDeleteToStart

Ctrl + Shift + Alt + C

Edit

CopyParameterTip

Ctrl + Del

Edit

WordDeleteToEnd

Ctrl + Down Arrow

Edit

ScrollLineDown

Shift + Alt + Down Arrow

Edit

LineDownExtendColumn

Ctrl + E , Ctrl + W

Edit

ToggleWordWrap

End

Edit

LineEnd

Shift + Alt + End

Edit

LineEndExtendColumn

Shift + End

Edit

LineEndExtend

Ctrl + Enter

Edit

LineOpenAbove

Ctrl + Shift + Enter

Edit

LineOpenBelow

Home

Edit

LineStart

Shift + Alt + Home

Edit

LineStartExtendColumn

Shift + Home

Edit

LineStartExtend

Ctrl + I

Edit

IncrementalSearch

Ctrl + Shift + I

Edit

ReverseIncrementalSearch

Ins

Edit

OvertypeMode

Ctrl + J

Edit

ListMembers

Ctrl + K , Ctrl + \

Edit

DeleteHorizontalWhiteSpace

Ctrl + K , Ctrl + A

Edit

SwapAnchor

Ctrl + K , Ctrl + C

Edit

CommentSelection

Ctrl + K , Ctrl + D

Edit

FormatDocument

Ctrl + K , Ctrl + F

Edit

FormatSelection

Ctrl + K , Ctrl + H

Edit

ToggleTaskListShortcut

Ctrl + K , Ctrl + I

Edit

QuickInfo

Ctrl + K , Ctrl + K

Edit

ToggleBookmark

Ctrl + K , Ctrl + L

Edit

ClearBookmarks

Ctrl + K , Ctrl + U

Edit

UncommentSelection

Ctrl + L

Edit

LineCut

Ctrl + Shift + L

Edit

LineDelete

Ctrl + Left Arrow

Edit

WordPrevious

Ctrl + Shift + Alt + Left Arrow

Edit

WordPreviousExtendColumn

Ctrl + Shift + Left Arrow

Edit

WordPreviousExtend

Shift + Alt + Left Arrow

Edit

CharLeftExtendColumn

Ctrl + M , Ctrl + H

Edit

HideSelection

Ctrl + M , Ctrl + L

Edit

ToggleAllOutlining

Ctrl + M , Ctrl + M

Edit

ToggleOutliningExpansion

Ctrl + M , Ctrl + O

Edit

CollapsetoDefinitions

Ctrl + M , Ctrl + P

Edit

StopOutlining

Ctrl + M , Ctrl + T

Edit

CollapseTag

Ctrl + M , Ctrl + U

Edit

StopHidingCurrent

Ctrl + Shift + Alt + P

Edit

PasteParameterTip

Ctrl + PgDn

Edit

ViewBottom

Ctrl + Shift + PgDn

Edit

ViewBottomExtend

PgDn

Edit

PageDown

Shift + PgDn

Edit

PageDownExtend

Ctrl + PgUp

Edit

ViewTop

Ctrl + Shift + PgUp

Edit

ViewTopExtend

PgUp

Edit

PageUp

Shift + PgUp

Edit

PageUpExtend

Ctrl + R , Ctrl + W

Edit

ViewWhiteSpace

Ctrl + Right Arrow

Edit

WordNext

Ctrl + Shift + Alt + Right Arrow

Edit

WordNextExtendColumn

Ctrl + Shift + Right Arrow

Edit

WordNextExtend

Shift + Alt + Right Arrow

Edit

CharRightExtendColumn

Ctrl + Shift + Space

Edit

ParameterInfo

Ctrl + Space

Edit

CompleteWord

Ctrl + Shift + T

Edit

WordTranspose

Ctrl + T

Edit

CharTranspose

Shift + Alt + T

Edit

LineTranspose

Ctrl + Shift + U

Edit

MakeUppercase

Ctrl + U

Edit

MakeLowercase

Ctrl + Up Arrow

Edit

ScrollLineUp

Shift + Alt + Up Arrow

Edit

LineUpExtendColumn

Ctrl + W

Edit

SelectCurrentWord

VC Accelerator Editor


Ins

Edit

NewAccelerator

Ctrl + W

Edit

NextKeyTyped

VC Dialog Editor


Ctrl + B

Format

ButtonBottom

Ctrl + D

Format

TabOrder

Ctrl + Shift + Down Arrow

Format

AlignBottoms

Shift + F7

Format

SizetoContent

Ctrl + F9

Format

CenterVertical

Ctrl + Shift + F9

Format

CenterHorizontal

F9

Format

AlignMiddles

Shift + F9

Format

AlignCenters

Ctrl + G

Format

ToggleGuides

Ctrl + Left Arrow

Edit

ScrollColumnLeft

Ctrl + Shift + Left Arrow

Format

AlignLefts

Ctrl + M

Format

CheckMnemonics

Ctrl + R

Format

ButtonRight

Alt + Right Arrow

Format

SpaceAcross

Ctrl + Right Arrow

Edit

ScrollColumnRight

Ctrl + Shift + Right Arrow

Format

AlignRights

Ctrl + T

Format

TestDialog

Alt + Up Arrow

Format

SpaceDown

Ctrl + Shift + Up Arrow

Format

AlignTops

VC Image Editor


Ctrl + –

Image

SmallerBrush

Ctrl + Shift + ,

Image

ZoomOut

Ctrl + .

Image

SmallBrush

Ctrl + Shift + .

Image

ZoomIn

Ctrl + [

Image

PreviousColor

Ctrl + Shift + [

Image

PreviousRightColor

Ctrl + ]

Image

NextColor

Ctrl + Shift + ]

Image

NextRightColor

Ctrl + =

Image

LargerBrush

Ctrl + A

Image

AirbrushTool

Ctrl + B

Image

BrushTool

Ctrl + F

Image

FillTool

Ctrl + H

Image

FlipHorizontal

Ctrl + Shift + H

Image

Rotate90Degrees

Shift + Alt + H

Image

FlipVertical

Ctrl + I

Image

PencilTool

Ctrl + Shift + I

Image

EraseTool

Ins

Image

NewImageType

Ctrl + J

Image

DrawOpaque

Ctrl + L

Image

LineTool

Ctrl + M

Image

MagnificationTool

Ctrl + Shift + M

Image

Magnify

Alt + P

Image

EllipseTool

Ctrl + Shift + Alt + P

Image

FilledEllipseTool

Shift + Alt + P

Image

OutlinedEllipseTool

Alt + R

Image

RectangleTool

Ctrl + Shift + Alt + R

Image

FilledRectangleTool

Shift + Alt + R

Image

OutlinedRectangleTool

Ctrl + Alt + S

Image

ShowGrid

Ctrl + Shift + Alt + S

Image

ShowTileGrid

Shift + Alt + S

Image

RectangleSelectionTool

Ctrl + T

Image

TextTool

Ctrl + Shift + U

Image

CopyandOutlineSelection

Ctrl + U

Image

UseSelectionasBrush

Alt + W

Image

RoundedRectangleTool

Ctrl + Shift + Alt + W

Image

FilledRoundedRectangleTool

Shift + Alt + W

Image

OutlinedRoundedRectangleTool

VC String Editor


Ins

Edit

NewString

View Designer


Ctrl + 1

QueryDesigner

Diagram

Ctrl + 2

QueryDesigner

Criteria

Ctrl + 3

QueryDesigner

SQL

Ctrl + 4

QueryDesigner

Results

Ctrl + G

QueryDesigner

GotoRow

Ctrl + Shift + J

QueryDesigner

JoinMode

Ctrl + R

QueryDesigner

ExecuteSQL

Ctrl + T

QueryDesigner

CancelRetrievingData

WebBrowser


Alt + Down Arrow

Help

Nexttopic

Alt + Up Arrow

Help

Previoustopic

Windows Forms Designer


End

Edit

DocumentEnd

Shift + End

Edit

DocumentEndExtend

Home

Edit

DocumentStart

Shift + Home

Edit

DocumentStartExtend

XML Editor Schema View


Ctrl + –

Schema

Collapse

Ctrl + =

Schema

Expand
Advertisements

Written by smartdev

April 8, 2009 at 1:50 pm

Posted in Visual Studio

Tagged with ,

How to generate a vCard file

with 6 comments

Ever needed to dinamically generate a vCard file? The syntax is very simple. Just generate a .vcf text file and open it!

You can find many link resources here. Also, you can find a nice generator here: http://www.vicintl.com/vcf/.

I managed to create a simple C# script that generates this file. The result was as expected:


BEGIN:VCARD
FN:Mr. John P. Smith, Jr.
TITLE:General Manager
ORG:XYZ Corp.;North American Division;Manufacturing
ADR;POSTAL;WORK:;;P.O. Box 10010;AnyCity;AnyState;00000;U.S.A.
LABEL;POSTAL;WORK;ENCODING=QUOTED-PRINTABLE:P.O. Box 10010=0D=0A=
Anywhere, TN  37849=0D=0A=U.S.A.
ADR;PARCEL;WORK:;133 Anywhere St.;Suite 360;AnyCity;AnyState;00000;U.S.A.
LABEL;POSTAL;WORK;ENCODING=QUOTED-PRINTABLE:133 Anywhere St.=0D=0A=
Anywhere, TN  37849=0D=0A=U.S.A.
TEL;Work;VOICE;MESG;PREF:+1-234-456-7891 x56473
TEL;Home:+1-234-456-7891
TEL;Pager:+1-234-456-7891
TEL;Cell:+1-234-456-7891
TEL;Modem;FAX:+1-234-456-7891,,*3
EMAIL;Internet:webmaster@anywhere.com
URL:http://www.anywhere.com/mrh.vcf
UID:http://www.anywhere.com/mrh.vcf
TZ:-0500
BDAY:1997-11-29
REV:20090401T065518
VERSION:2.1
END:VCARD

generated this:

vcard_noimage

The real challenge camed when I treid to add a image to my vCard file. I couldn’t fint it on the Internet to a quick Export using the Outlook 2007 revealed the secret: all you have to do is to add a new line to your .vcf file:


PHOTO;TYPE=JPEG;ENCODING=BASE64:
YOUR BASE64 ENCODED IMAGE HERE

In order to generate the “YOUR BASE64 ENCODED IMAGE HERE” string in C# you can use the following method:


private string EncodeWithString(string ImagePath)
	{
		System.IO.FileStream inFile;
		byte[] binaryData;

		try
		{
			inFile = new System.IO.FileStream(ImagePath,
											  System.IO.FileMode.Open,
											  System.IO.FileAccess.Read);
			binaryData = new Byte[inFile.Length];
			long bytesRead = inFile.Read(binaryData, 0,
										(int)inFile.Length);
			inFile.Close();
		}
		catch (System.Exception exp)
		{
			// Error creating stream or reading from it.
			//System.Console.WriteLine("{0}", exp.Message);
			//return;
			return exp.Message;
		}

		// Convert the binary input into Base64 UUEncoded output.
		string base64String;
		try
		{
			base64String =
			   System.Convert.ToBase64String(binaryData,
											 0,
											 binaryData.Length);
		}
		catch (System.ArgumentNullException)
		{
			//System.Console.WriteLine("Binary data array is null.");
			//return;
			return "Binary data array is null.";
		}

		// Write the UUEncoded version to the output file.

		return base64String;
	}

Now, the new result is real magic:

vcard_image

Written by smartdev

April 6, 2009 at 3:20 pm

Posted in .Net, Programming

Tagged with ,

How to make a CheckBox fire the ItemCommand Event of a Repeater

leave a comment »

Today I needed to add a check box control to a repeater’s item template and have it fire the ItemCommand event on the repeater.  I could’t do that, because this control (Checkbox) does not trigger this event. So, I searched the Internet and I found this cool new control:


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace smartdev.web.Controls
{
    public class CheckBoxRepeaterAware : CheckBox
    {
        #region Properties

        #region CommandName

        public string CommandName
        {
            get
            {
                if (this.ViewState["CommandName"] == null)
                {
                    return string.Empty;
                }
                else
                {
                    return this.ViewState["CommandName"] as string;
                }
            }
            set
            {
                this.ViewState["CommandName"] = value;
            }
        }

        #endregion

        #region CommandArgument

        public string CommandArgument
        {
            get
            {
                if (this.ViewState["CommandArgument"] == null)
                {
                    return string.Empty;
                }
                else
                {
                    return this.ViewState["CommandArgument"] as string;
                }
            }
            set
            {
                this.ViewState["CommandArgument"] = value;
            }
        }

        #endregion

        #endregion

        #region Procedures

        #region On Checked Changed

        protected override void OnCheckedChanged(EventArgs e)
        {
            //create a new event args of type command event args
            CommandEventArgs ce = new CommandEventArgs(this.CommandName, this.CommandArgument);

            //allow the base checkbox to handle the event as normal
            base.OnCheckedChanged(e);

            //raise the contorls method RaiseBubbleEvent
            base.RaiseBubbleEvent(this, ce);
        }
        #endregion

        #endregion
    }
}

I hope you will find this usefull.

Written by smartdev

April 4, 2009 at 1:17 pm

Serialize Linq objects

leave a comment »

If you are trying to serialize Linq objects then you will have to foolow these steps:

1. First, you have to mark your data context as serializable:

serialization_mode

2. Then, in order to avoid errors like “circular reference was detected while serializing an object of type…”, you will have to set “Access” to “Internal” on your object’s relations (It is a compromise, but it needs to be done):

step2_1        step2_2

3. You can now use these methods:


public static string Serialize(object o)
	{
		XmlSerializer serizer = new XmlSerializer(o.GetType());
		StringBuilder sb = new StringBuilder();
		StringWriter sw = new StringWriter(sb);
		serizer.Serialize(sw, o);
		sw.Close();
		return sb.ToString();
	}

public static T Deserialize<T>(string xml)
	{
		XmlSerializer serizer = new XmlSerializer(typeof(T));
		StringReader sr = new StringReader(xml);
		return (T)serizer.Deserialize(sr);
	}

like this (example):


AddressBookDataContext data = new AddressBookDataContext();
string xml = LINQHelper.Serialize(data.AB_Offices.ToList());
//..
List< AB_Offices>list = LINQHelper. Deserialize<List<AB_Offices>>(xml);

It works!

Written by smartdev

April 3, 2009 at 4:01 pm

Posted in .Net

Tagged with , ,

SQL strip HTML tags

leave a comment »

I used many versions of the function below in order to strip HTML from a string in SQL. But no matter how much I tried, I always had some cases in witch it failed. I never found a perfect one on the Internet either. So, find below my latest version (it almost never fails :)):


ALTER function [dbo].[stripHTML]
	(
	@Content nvarchar(4000)
	)
returns nvarchar(4000)
as 
begin

	declare @it int
	set @it = 0

	declare @ind1 int
	set @ind1 = -1
	declare @ind2 int
	set @ind2 = -1

	declare @plaintext nvarchar(4000)
	declare @htmltext nvarchar(4000)
	set @plaintext = ''
	set @htmltext = ''

	declare @strippedContent nvarchar(4000)
	set @strippedContent = ''

	while @ind1 <> 0 or @ind2 <> 0
		begin
			set @ind1 = PATINDEX('%<%', @Content)
			set @ind2 = PATINDEX('%>%', @Content)

			if not @ind2 > @ind1
				set @ind2 = @ind1

			if @ind1 > 0
				set @plaintext = left(@Content, @ind1 - 1)
			else
				set @plaintext = ''
			
			if len(@Content) = @ind2 - @ind1 + 1
				set @htmltext = @Content
			else
				set @htmltext = substring(@Content, @ind1, @ind2 - @ind1 + 1)

			if @ind1 = 0 and @ind2 = 0 and len(@Content) > 0
				begin
					set @htmltext = ''
					set @plaintext = @Content	
				end	

			set @strippedContent = @strippedContent + @plaintext
			--set @Content =  right(@Content, len(@Content) - @ind2)
			SET @Content = SUBSTRING(@Content, @ind2 + 1, LEN(@Content)) -- whatever, until the end

			set @it = @it + 1
			if (@it > 2000)
				break
			else
				continue
		end

	set @strippedContent = replace(@strippedContent, '&nbsp;', ' ')
	set @strippedContent = replace(@strippedContent, '

	', '
	')
	set @strippedContent = replace(@strippedContent, '  ', ' ')
	set @strippedContent = replace(@strippedContent, '  ', ' ')
	set @strippedContent = replace(@strippedContent, '  ', ' ')

	return @strippedContent
end

Note: there is something to notice here. I have found out that

set @htmltext = substring(@Content, @ind1, @ind2 - @ind1 + 1)

is not the same as:

set @htmltext = right(@Content, len(@Content) - @ind2)

I am not sure how to explain this, but I am sure it has something to do with the size of unicode characters.

Written by smartdev

April 3, 2009 at 3:32 pm

Posted in SQL

Tagged with

Validate email address

leave a comment »

Here is some nice code to help you validate a email address in C#:

public static bool IsValidEmailAddress(string sEmail)
{
if (sEmail == null)
return false;

int nFirstAT = sEmail.IndexOf(‘@’);
int nLastAT = sEmail.LastIndexOf(‘@’);

if ((nFirstAT > 0) && (nLastAT == nFirstAT) && (nFirstAT < (sEmail.Length - 1))) { // address is ok regarding the single @ sign return (Regex.IsMatch(sEmail, @"(\w+)@(\w+)\.(\w+)")); } else { return false; } } [/sourcecode]

Written by smartdev

March 19, 2009 at 1:13 pm

Posted in .Net

Tagged with ,