Thursday, 14 May 2015

Import design Package from one environment to another environment using design manager

In this post I am going to import design package from one environment to another environment like development server to SIT server. Based on Microsoft recommended “the deployment user must have the Designers permission level in site collection to use Design Manager and import design packages.”
The previous post already I have explained for how to created design manager package WSP file. In this post I have reuse the WSP file for importing the same.

Step 1: Open the site then click design manager link from right top corner "Settings" menu.
clip_image002[4]

Step 2: Once open the design manager click the “Import a complete design package”
clip_image004[4]
Step 3: Browse and select the WSP file and click open then click import button. It will take some time.
clip_image006[4]
Step 4: Once import process completed get the following status
“Import of package "DesignManger-1.0.wsp" succeeded.”
Step 5: Again click the design manager and click “Edit master page” link. You will see the “HTMLpage” – Master page is available in the list in Draft status.
clip_image008[4]


Step 6: Select the Master Page and publish a major version.

clip_image010[4]
Step 7: After publishing the page click setting menu and select “Site setting” link
clip_image012[4]

Step 9:  Click Master Page link and select the HTMLPage in site master page category drop down menu then click ok button.

clip_image014[4]


clip_image016[4]

Step 10:Click the home page the Htmlpage converted to SharePoint Master Page with default menu.

Saturday, 19 January 2013

SQL SERVER – 2008 – Introduction to Merge Statement – One Statement for INSERT, UPDATE, DELETE


MERGE is a new feature that provides an efficient way to perform multiple DML operations. In previous versions of SQL Server, we had to write separate statements to INSERT, UPDATE, or DELETE data based on certain conditions, but now, using MERGE statement we can include the logic of such data modifications in one statement that even checks when the data is matched then just update it and when unmatched then insert it.

One of the most important advantage of MERGE statement is all the data is read and processed only once. In previous versions three different statement has to be written to process three different activity (INSERT, UPDATE or DELETE), however using MERGE statement all update activity can be done inone pass of database table. This is quite an improvement in performance of database query.
Syntax of MERGE statement is as following:
MERGE
[ TOP ( expression ) [ PERCENT ] ]
[ INTO ] target_table [ WITH ( <merge_hint> ) ] [ [ AS ] table_alias]
USING <table_source>
ON <merge_search_condition>
[ WHEN MATCHED [ AND <clause_search_condition> ]
THEN <merge_matched> ]
[ WHEN NOT MATCHED [ BY TARGET ] [ AND <clause_search_condition> ]
THEN <merge_not_matched> ]
[ WHEN NOT MATCHED BY SOURCE [ AND <clause_search_condition> ]
THEN <merge_matched> ]
[ <output_clause> ]
[ OPTION ( <query_hint> [ ,...n ] ) ]
;
Example:
Let’s create Student Details and StudentTotalMarks and inserted some records.
Student Details:
USE AdventureWorks
GO

CREATE TABLE StudentDetails(StudentID INTEGER PRIMARY KEY,StudentName VARCHAR(15)
)
GO

INSERT INTO StudentDetailsVALUES(1,'SMITH')
INSERT INTO StudentDetailsVALUES(2,'ALLEN')
INSERT INTO StudentDetailsVALUES(3,'JONES')
INSERT INTO StudentDetailsVALUES(4,'MARTIN')
INSERT INTO StudentDetailsVALUES(5,'JAMES')
GO
StudentTotalMarks:
CREATE TABLE StudentTotalMarks(StudentID INTEGER REFERENCES StudentDetails,StudentMarks INTEGER)
GO
INSERT INTO StudentTotalMarksVALUES(1,230)
INSERT INTO StudentTotalMarksVALUES(2,255)
INSERT INTO StudentTotalMarksVALUES(3,200)
GO
In our example we will consider three main conditions while we merge this two tables.
  1. Delete the records whose marks are more than 250.
  2. Update marks and add 25 to each as internals if records exist.
  3. Insert the records if record does not exists.
Now we will write MERGE process for tables created earlier. We will make sure that we will have our three conditions discussed above are satisfied.
MERGE StudentTotalMarks AS stm
USING 
(SELECT StudentID,StudentName FROM StudentDetails

AS sd ON stm.StudentID sd.StudentID
WHEN MATCHED AND stm.StudentMarks 250 THEN DELETE
WHEN 
MATCHED THEN UPDATE SET stm.StudentMarks stm.StudentMarks 25

WHEN NOT MATCHED THEN
INSERT
(StudentID,StudentMarks)VALUES(sd.StudentID,25);GO
There are two very important points to remember while using MERGE statement.
  • Semicolon is mandatory after the merge statement.
  • When there is a MATCH clause used along with some condition, it has to be specified first amongst all other WHEN MATCH clause.
After the MERGE statement has been executed, we should compare previous resultset and new resultset to verify if our three conditions are carried out.
AS we can see there are 5 rows updated. StudentID 2 is deleted as it is more than 250, 25 marks have been added to all records that exists i.e StudentID 1,3 and the records that did not exists i.e. 4 and 5 are now inserted in StudentTotalMarks .
MERGE statement is very handy improvement for T-SQL developers who have to update database tables with complicated logic. MERGE statement also improves the performance of database as it passes through data only 

Deleting Duplicate records in SQL Server

As I have mentioned in one of my previous tips that using ROW_NUMBER() we can get the serial number which is here.
Using the same ROW_NUMBER() function you can also easily delete the Duplicate Records present inside a table.
Lets say I have a Users Table which is having duplicate records. I need to delete the duplicate records which are having both the FirstName and LastName same.

Table: UsersList

 
FirstName       LastName       PhoneNumber       Address
------------    ------------     ----------------    -------------
Rashmita        Devi                987554437           NULL
Rashmita        Devi                446576578           NULL
Adwin            Ratzz              222222222           NULL
Charle            Hardwick         343534545           NULL
Adwin            Ratzz              576767688           NULL
Charle            Hardwick         877778777           NULL

 

 
So, with the help of ROW_NUMBER() all the duplicate records present in the above table can be removed easily.
The query will be composed this way:-

 
WITH TempUsers (FirstName,LastName, duplicateRecordCount)
AS
(
SELECT FirstName,LastName,
ROW_NUMBER()OVER(PARTITION BY FirstNameLastName ORDER BYFirstNameAS duplicateRecordCount
FROM dbo.Users
)
DELETE
FROM TempUsers
WHERE duplicateRecordCount > 1
GO

 
Instead of TempUsers you can give any name. Because this is used only for Temporary purpose.
After the execution of the above query, Users table will have the following records.

 
FirstName          LastName        PhoneNumber         Address
------------       ------------      ----------------      -------------
Rashmita           Devi                987554437              NULL
Adwin               Ratzz              222222222             NULL
Charle               Hardwick         877778777             NULL
Note: Row_Number() function is present in SQL Server 2005 and in later version(s).

Wednesday, 16 January 2013

Disabling browser caching for all browsers from ASP.NET


Disabling browser caching for all browsers from ASP.NET

This is what we use in ASP.NET:
// Stop Caching in IE
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

// Stop Caching in Firefox
Response.Cache.SetNoStore();
It stops caching in Firefox and IE, but we haven't tried other browsers. The following response headers are added by these statements:
Cache-Control: no-cache, no-store
Pragma: no-cache

Tuesday, 25 December 2012

SQL SERVER – Introduction and Explanation to SYNONYM – Helpful T-SQL Feature for Developer


I learned about SYNONYM feature in SQL Server 2005.
DBA have been referencing database objects in four part names. SQL Server 2005 introduces the concept of a synonym. A synonyms is a single-part name which can replace multi part name in SQL Statement. Use of synonyms cuts down typing long multi part server name and can replace it with one synonyms. It also provides an abstractions layer which will protect SQL statement using synonyms from changes in underlying objects (tables etc).
Create Synonyms :
USE AdventureWorks;GOCREATE SYNONYM MyLocationFOR AdventureWorks.Production.Location;GO
Use Synonyms :
USE AdventureWorks;GOSELECT TOP *FROM MyLocation;GO
Drop Synonyms :
USE AdventureWorks;GODROP SYNONYM MyLocation;GO
Synonyms can be created on only following objects.
  • Assembly (CLR) Stored Procedure
  • Assembly (CLR) Table-valued Function
  • Assembly (CLR) Scalar Function
  • Assembly Aggregate (CLR) Aggregate Functions
  • Replication-filter-procedure
  • Extended Stored Procedure
  • SQL Scalar Function
  • SQL Table-valued Function
  • SQL Inline-table-valued Function
  • SQL Stored Procedure
  • View
  • Table (User-defined)
Additionally SYNONYMS can be used only to change data of object not the schema of the object. SYNONYMS can be used with only SELECT, UPDATE, INSERT, DELETE, EXECUTE commands.
Following is image demonstrates use of SYNONYMS.
An example of the usefulness of this might be if you had a stored procedure on a Users database that needed to access a Clients table on another production server. Assuming you created the stored procedure in the database Users, you might want to set up a synonym such as the following:
USE Users;GOCREATE SYNONYM ClientsFOR Offsite01.Production.dbo.Clients;GO
Now when writing the stored procedure instead of having to write out that entire alias every time you accessed the table you can just use the alias Clients. Furthermore, if you ever change the location or the name of the production database location all you need to do is modify one synonym instead of having to modify all of the stored procedures which reference the old server.

Dashboard plugin -- switching dashboards

Excellent Dashboard plugin:
http://connect.gxsoftware.com/dashboardplugin/demo/dashboard.html

for asp.net Application
you just need to add MIME Type for .json file
add following line in web.config

  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json"/>
    </staticContent>
  </system.webServer> 

Saturday, 22 December 2012

ASP.NET 4.0 Client ID Feature


Why Client Ids

Client Ids have always been a problem for us. But now a days, in new age applications, we are moving more towards the client side programming in new Rich Internet applications. Many new technologies and the way of programming have evolved in the last few years to make very rich UI like JQuery, JSon, Dojo.
In DOM, to access a control, client id plays a pivotal role. So Microsoft is also trying to make our life easier by providing the capability to have control over the client id generation which will ensure easy, simple and less error prone RIA development.

Client Ids Earlier

So let's discuss how the ClientIds were generated earlier. First, I will start with normal control, say textbox control or a label. So here the client Ids that are generated were starting with prefix of all the naming containers from top to bottom separated as underscore. And actually this was a good idea to generate the unique id at client side. But as I discussed, ClientIds are the key part of new age development. Let's look at the example for a simple textbox server control. My aspx looks like:
Normal Page
Fig: Normal Page
So from the above picture, we can see that my label and textbox are inside a contentplaceholder. Now let's look at the ClientId:
View Source - Normal Page
Fig: View Source - Normal Page
Now here client Id is ctl00_ContentPlaceHolder1_myTextBox. If we go one by one, the ctl00 is the counter, the next one is ID of contentplaceholder and next id of textbox.
So one thing, as you move the control to some other part, the Client Id will get changed as well.
So although we know the ID is going to be unique on the page, but still you don't have any control over itFrown. .NET engine will generate the ClientIds according to its algorithm for you ).
So this is all about of the simple controls. Now lets talk about some data controls, like gridviewlistview,dropdown, etc. Here in these controls, what we do is we just bind the datasource to the control. And at runtime based on the data, the number of rows(controls) are generated. So what about the client Ids here. Here also, the Client Ids are being generated in the same way as I already discussed with prefix of rownumber. So let's have a look at the example.
This is my aspx code for GridView. Here I am showing ID, Book Name and Price:
Page with data control
Fig: Page with data control
So in the above example, I have taken a gridview. And in this, I have three labels in different ItemTemplates. Thegridview is in contentplaceholder.
Now look to the ClientIds:
View Source - Page with data control
Fig: View Source - Page with data control
You can see the id is like ctl00_ContentPlaceHolder1_gridviewBooks_ctl02_lblID. So here if we go one by one, first the counter the contentplaceholder id again rowcounter generated in sequence for every row by .NET engine to make it unique and last label ID.
So it becomes very uneasy to use.
But as in new era web development, when we doing lots of work at client side, the Client ids become a key part in web development.

Control Client Ids Generation with ASP.NET 4.0

ASP.NET 4.0 provides the power to control Client Ids generation. For that, it provides the new propertyClientIDMode property to handle this. This property enables us to specify how the Client Ids will be generated for the controls. This provides four options:
  • AutoID
  • Static
  • Predictable
  • Inherit
We'll discuss them one by one.
AutoID: This property is the same as the earlier version of .NET. Specify this value if you don't want any changes in the Client Id generation from the earlier version as I discussed in ClientIDs in earlier versions.
Static: This means the you want the static id of your control. You should use this property when you know the ID is going to be unique on the page. Here .NET engine will generate the Client Ids as it is, without adding any suffixes or prefixes in it. This mode is mainly used for normal single control. Let's look at the example.
Normal page with ASP.NET 4.0
Fig: Normal page with ASP.NET 4.0
Here as you seen in the picture, I set the ClientIDMode for Label AutoID and for TextBox I set it Static. Now let's see the generated Client Ids:
Brij_634099931624398203_normalpage4.jpg
Fig: View Source: Normal page with ASP.NET 4.0
Now if you see the client ID of Label, it is the same as the earlier one because here I set it to Auto.
But for the TextBox, I set it static. So here the Client Id is the same as the ID that we set it on aspx page. This is the beauty of ASP.NET 4.0. So if we set it to static, the .NET engine won't generate a new client id for the control; it will use the ID of the control as Client ID.
Note: One thing needs to be made sure here, if we set the mode to static then there should be no control on the page with the same id because it will have the same client id on the page and it may be disastrous when we access it from Clientside.
Predictable: This is another mode that I liked for the ClientId generation. When you exactly don't know whether the Id is unique on the page or not, then you can use this property. This value enables us to the predict the client ids on the rendered page. When you set mode to this, you need to set some more properties according to your own choice.
Now I will take the example as above. Now here the aspx code would be like:
Data control page with ASP.NET 4.0
Fig: Data control page with ASP.NET 4.0
Here one thing is we are using datacontrol, then we cannot set it as static because there are going to be multiple controls generated based on the data.
So here we will be using mode as Predictable so that we can predict what will be the id of the control. We need to set one more property ClientIDRowSuffix here. I set it ID means the ID column.
Now let's look at the generated Client Ids:
View Source: Data control page with ASP.NET 4.0
Fig: View Source: Data control page with ASP.NET 4.0
Now here if we look at the ClientID, here it is MainContent_gridviewBooks_lblName_1. So if we look at it deeply, then we find that there is no counter like thing. Here we have first id of contentplaceholder, the id of gridview, the id of label, the suffix id that we set. So it's really predictable Smile and similarly for other rows.
Inherit: This is also value to set to this property. As the name suggests, it means the Id generation of the control will be the same as the parent control. This is the default behavior of the control.

Setting the Property at Various Levels

There are various places where we can set the ClientIDMode property.This can be set at control level, page level as well as application. The behavior will be the same. We can set it at page directive as below:
ClientIDMode at Page level
Fig: ClientIDMode at Page level
To set it at Application level, we need to set it in config file as:
and that will be applied across all the pages in the application.
ClientIDMode at Application level
Fig: ClientIDMode at Application level

Feedback and Suggestions

Feedback is key for improvement. I would request you all to share your feedback and give me some suggestions, which would encourage and help in more and quality writing.