Visual Studio LightSwitch

Yesterday, I had a look at something new!

It was Microsoft LightSwitch for Visual Studio 2010. Its an amazing thing to do more with your data. You can do CRUD operations with automatically generated UI without writing single line of code. Isn`t this amazing… :D

Have a look at this with your own eyes.

Note: You will need to have Visual Studio 2010 SP1 installed on your system.

Form Selector with Email Configuration – Sitefinity 4.1

No need to say much!
George Saadeh did a great job on modifying/extending the Form Selector widget to get the submit event in order to send email with posted values.

You can download the control from here.

Content Designer Widget – Sitefinity 4.x

  • Content Designer Installation Guide
    • Make a folder named Common on the root of your web application.
    • Make a folder named Widgets and copy folder ContentDesigner into it (/Common/Widgets/ContentDesigner).
    • Download Images and Styles folders and copy them in /Common as well.
    • Structure should look like below after you copy necessary files for the sample:

    Common
    - Widgets
    - ContentDesigner
    - ContentDesigner.ascx
    - ContentDesigner.ascx.cs
    - ContentDesigner.ascx.designer.cs
    - Designer.cs
    - Designer.js
    - Template.ascx
    - Images
    - (All images in attached Images folder)
    - Styles
    - jquery-ui-1.8.14.custom.css

    • Now browse to your Sitefinity Backend and goto Administration > Settings > Advanced > Toolboxes > Toolboxes > PageControls > Sections > ContentToolboxSection > Tools > (Create New).
    • Enter the fields with the values as shown below:

    • Save the settings and edit your any existing page or create a new one.
    • Drag and drop your widget which we named ‘Tabs designer’ in the configuration on to your page.
    • Click Edit to customize the tabs view.
    • You will see the designer like this:

    • Click ‘Add Tab’ to add a new tab on the control.

    • Under ‘Put up some content’, you will see couple of fields to put up your desired content into a newly added tab.
    • Select a style for your tabs container in the CSS Style field.
    • Simple copy/paste some content or write it in Content field.
    • Select an image for the tab to be shown as normal state and for the hover/selected state under Image and Hover Image fields.
    • You can add and/or delete as many tabs as you want with inner content and tab images for each.
    • Here is the final result with ‘Fun’ style selected:

How to retrieve data but by shortening up its length

SELECT

 

dataCol1, case when len(dataCol1) - charindex(@urKeyWord , dataCol1 ) > 50 then substring(dataCol1,charindex(@urKeyWord , dataCol1 ),charindex(@urKeyWord , dataCol1 ) + 50 ) else substring(dataCol1,charindex(@urKeyWord , dataCol1 ),len(@urKeyWord) ) end

FROM

 

myTable

WHERE

 

dataCol2 NOT IN (SELECT col FROM anotherTable)

How to edit/update xml column using XQuery

ALTER PROCEDURE [UpdateUnitsLocations]
   @varUnitId [uniqueidentifier],
   @varLat [varchar](100),
   @varLng [varchar](100)
AS
BEGIN
   SET NOCOUNT ON;

   UPDATE [UnitsLocations]
   SET LocationXML.modify('
   insert <point lat="{sql:variable("@varLat")}" lng="{sql:variable("@varLng")}" />
   as last
   into (/markers/line)[1]
   ')
   WHERE UnitId = @varUnitId
END

How can I detect changes in a row of some table

It is possible to use a trigger check for changes made to a column, but a few obstacles are present as the column you are looking to verify is of a data type xml.  The below code shows the difficulty in comparing the xml data type to another xml data type:
\
DECLARE @data1 XML,
@data2 XML
SET @data1 = '<root />'
SET @data2 = '<empty />'
IF @data1 <> @data2
BEGIN
PRINT 'Different'
END
ELSE
PRINT 'Same'
--Msg 305, Level 16, State 1, Line 8
The xml data type cannot be compared or sorted, except when using the IS NULL operator.
That being said it is possible to convert the xml data type to a more flexible type, but there is overhead involved in this also, the conversion.  The below code gives an example of using a trigger to compare an xml column:
USE tempdb;
GO
CREATE TABLE changetbl(
id UNIQUEIDENTIFIER,
data XML
);
GO
CREATE TRIGGER change
ON changetbl
FOR UPDATE, DELETE
AS
IF (SELECT CONVERT(VARCHAR(MAX), data) FROM INSERTED) <> (SELECT CONVERT(VARCHAR(MAX), data) FROM DELETED)
BEGIN
PRINT 'Different'
END
ELSE
PRINT 'Same'
DROP TRIGGER change;
GO
DROP TABLE changetbl;
GO
USE tempdb;
GO
CREATE TABLE changetbl(
id UNIQUEIDENTIFIER,
data XML
);
GO
CREATE TRIGGER change
ON changetbl
FOR UPDATE, DELETE
AS
IF (SELECT CONVERT(VARCHAR(MAX), data) FROM INSERTED) <> (SELECT CONVERT(VARCHAR(MAX), data) FROM DELETED)
BEGIN
PRINT 'Different'
END
ELSE
PRINT 'Same'
DROP TRIGGER change;
GO
DROP TABLE changetbl;
GO
Triggers are an awesome and powerful tool in sql, but it comes with overhead and risk.  The trigger fires automatically specific to the traansaction(s) that you specify, INSERT, UPDATE, DELETE.  In an OLTP database this can cause substantial overhead on a table that has frequent and numerous transactions.  There is also the danger of if the trigger fails so will the transaction that fired the trigger resulting in the transaction being rolled back and losing that information.
It is possible to use a trigger check for changes made to a column, but a few obstacles are present as the column you are looking to verify is of a data type xml.  The below code shows the difficulty in comparing the xml data type to another xml data type: DECLARE @data1 XML,    @data2 XML    SET @data1 = '<root />'SET @data2 = '<empty />' IF @data1 <> @data2BEGIN PRINT 'Different'ENDELSEPRINT 'Same' --Msg 305, Level 16, State 1, Line 8The xml data type cannot be compared or sorted, except when using the IS NULL operator.That being said it is possible to convert the xml data type to a more flexible type, but there is overhead involved in this also, the conversion.  The below code gives an example of using a trigger to compare an xml column: USE tempdb;GO CREATE TABLE changetbl(id UNIQUEIDENTIFIER,data XML);GO CREATE TRIGGER changeON changetblFOR UPDATE, DELETEAS IF (SELECT CONVERT(VARCHAR(MAX), data) FROM INSERTED) <> (SELECT CONVERT(VARCHAR(MAX), data) FROM DELETED)BEGINPRINT 'Different'END ELSEPRINT 'Same' DROP TRIGGER change;GO DROP TABLE changetbl;GO USE tempdb;GO CREATE TABLE changetbl(id UNIQUEIDENTIFIER,data XML);GO CREATE TRIGGER changeON changetblFOR UPDATE, DELETEAS IF (SELECT CONVERT(VARCHAR(MAX), data) FROM INSERTED) <> (SELECT CONVERT(VARCHAR(MAX), data) FROM DELETED)BEGINPRINT 'Different'END ELSEPRINT 'Same' DROP TRIGGER change;GO DROP TABLE changetbl;GOTriggers are an awesome and powerful tool in sql, but it comes with overhead and risk.  The trigger fires automatically specific to the traansaction(s) that you specify, INSERT, UPDATE, DELETE.  In an OLTP database this can cause substantial overhead on a table that has frequent and numerous transactions.  There is also the danger of if the trigger fails so will the transaction that fired the trigger resulting in the transaction being rolled back and losing that information.DECLARE @data1 XML, @data2 XML SET @data1 = '<root />' SET @data2 = '<empty />' IF @data1 <> @data2 BEGIN PRINT 'Different' END ELSE PRINT 'Same' --Msg 305, Level 16, State 1, Line 8 The xml data type cannot be compared or sorted, except when using the IS NULL operator.

Pass parameters to methods while invoking from Dictionary Key

You really need to make a dictionary with delegates as the value, and not a class containing the method you’re wanting to call.
A delegate is nothing more than a type that can represent a method that can be passed around.
You’d make such a list like this:
public class MyClass
{
public delegate void DoSomethingDelegate(string text, int value); // this is the signature of each of the methods.
public void DoSomething(string text, int value)
{
// something here.
}
public void DoSomethingElse(string text, int value)
{
// something else here.
}
public static void Main(string[] args)
{
Dictionary<string, DoSomethingDelegate> dict = new Dictionary<string, DoSomethingDelegate>();
dict.Add(“one”, new DoSomethingDelegate(DoSomething));
dict.Add(“two”, new DoSomethingDelegate(DoSomethingElse));
dict["one"](“Hello”, 1);
dict["two"](“Hola”, 2);
}
}
See this link for more info.

You really need to make a dictionary with delegates as the value, and not a class containing the method you’re wanting to call.
A delegate is nothing more than a type that can represent a method that can be passed around.
You’d make such a list like this:
public class MyClass{    public delegate void DoSomethingDelegate(string text, int value); // this is the signature of each of the methods.
public void DoSomething(string text, int value)    {         // something here.     }         public void DoSomethingElse(string text, int value)    {         // something else here.     }
public static void Main(string[] args)    {        Dictionary<string, DoSomethingDelegate> dict = new Dictionary<string, DoSomethingDelegate>();        dict.Add(“one”, new DoSomethingDelegate(DoSomething));        dict.Add(“two”, new DoSomethingDelegate(DoSomethingElse));        dict["one"](“Hello”, 1);        dict["two"](“Hola”, 2);    }}
See this link for more info.

SELECT only first element using XQuery

Below is the example of how to select only first element from whole bunch of XML in sql server.
declare @x xml;
SET @x=’<Statuses>
<Status DateAndTime=”">
<one State=”" Desc=”" />
<two State=”" Desc=”" />
<three State=”" Desc=”" />
</Status>
<Status DateAndTime=”">
<four State=”" Desc=”" />
<five State=”" Desc=”" />
<six State=”" Desc=”" />
</Status>
</Statuses>’
SELECT @x.query(‘(Statuses/Status)[1]‘)

declare @x xml;SET @x=’<Statuses>        <Status DateAndTime=”">                 <one State=”" Desc=”" />                 <two State=”" Desc=”" />                 <three State=”" Desc=”" />        </Status>        <Status DateAndTime=”">                 <four State=”" Desc=”" />                 <five State=”" Desc=”" />                 <six State=”" Desc=”" />        </Status></Statuses>’
SELECT @x.query(‘(Statuses/Status)[1]‘)

How to install Windows SharePoint Services 3.0 SP1 on Vista x64/x86 or Windows 7

If you are a developer for SharePoint your best friend has been Virtual PC or VMWare. It’s time to introduce a new friend, Bamboo Nation’s SharePointOnVista.
Bamboo have put together an installer that allows you to install WSS3.0 SP1 on Vista, both x86 and x64.  This will allow you to develop on your workstation with all the power of a non virtualized environment. You still need VPC and VMWare so don’t feel sorry.
There’s been much discussion about SharePoint being a “bad” development platform. This will remove the objection that you NEED to develop on a Server OS. I think we all as SharePoint developers have built our “virtualization skills” to a comfortable level now so it’s time to give us a break ;)
You can download the setup helper and try it out.
If you are installing on Windows 7 RC (build 7100) you need to read this post before continuing.

If you are a developer for SharePoint your best friend has been Virtual PC or VMWare. It’s time to introduce a new friend, Bamboo Nation’s SharePointOnVista.

Bamboo have put together an installer that allows you to install WSS3.0 SP1 on Vista, both x86 and x64.  This will allow you to develop on your workstation with all the power of a non virtualized environment. You still need VPC and VMWare so don’t feel sorry.

There’s been much discussion about SharePoint being a “bad” development platform. This will remove the objection that you NEED to develop on a Server OS. I think we all as SharePoint developers have built our “virtualization skills” to a comfortable level now so it’s time to give us a break ;)

You can download the setup helper and try it out.

If you are installing on Windows 7 RC (build 7100) you need to read this post before continuing.

Current limitations:

  • You must select the Advanced option during install.
  • If you want to run on SQLExpress, manually install it first.  Get it here.
  • You have to manually enable IIS7 with the proper options (explained).
Follow

Get every new post delivered to your Inbox.