If you are tired of writing your blog posts in Times New Roman font and don't want to add bloated HTML by choosing the font and size from Blogger's post editor, this post is right place for you. The solution is simple if you know where to look. Below are two ways you can try.
Tuesday, 9 December 2014
Saturday, 6 December 2014
How to get an HttpContextBase object from HttpContext.Current?
I was helping a friend to implement OAuth login for Facebook. He was using DotNetOpenAuth extensions for ASP.NET, downloaded as NuGet package.
Thursday, 27 November 2014
Rendering ASP.NET MVC Views to HTML String
A common need I have in my ASP.NET MVC based projects is to render a complete "View" or "PartialView" to string instead of the HTTP response and then present it or embed it in another rendered view.
You can implement the following code in shared controller or preferably in base Controller so that you can access this function in all controllers across your project. You can access the ControllerContext within controller and pass it to the function. It will return the rendered view in HTML string, the usage is self-explanatory.
You can implement the following code in shared controller or preferably in base Controller so that you can access this function in all controllers across your project. You can access the ControllerContext within controller and pass it to the function. It will return the rendered view in HTML string, the usage is self-explanatory.
Friday, 21 November 2014
Copy Text to Clipboard Using JavaScript
In a recent web project, I needed to create a button that would copy text from textbox onto the user's clipboard. The obvious approach is to use jQuery or JavaScript to trigger onclick() event of the button and copy text to clipboard. It sounds easy and convenient and should be achieved with few lines of code but it is not.
Sunday, 12 October 2014
Get Combination of Rows from Tables in Database
Getting combinations of rows from database tables is simple. First you have to understand the difference between Cartesian product and Permutation before we go any further.
Thursday, 2 October 2014
How to Get Current Page in Dynamic Content Plugin or from Controller in EPiServer
If you want to get the current page in a block controller or from an ActionFilter, you can use EpiServer PageRouteHelper class
Friday, 26 September 2014
Making Conference / Group call Using Rebtel
If you are a Rebtel user and want to make a conference / group call, then this post is the right place for you. Rebtel is a great, cheap way to make international calls to your loved ones with crystal clear voice quality. I love it and I'm sure that you do too. So when you get what you need without much effort you want more, that’s human nature and in Rebtel's case more is possible in the form of Conference / Group calls.
Wednesday, 24 September 2014
Delete Language Branch from all pages and site in EPiServer
Suppose you have large content (e.g. 3000 pages) in your EPiServer CMS project, supporting multiple languages e.g. English (en), French (fr) and Italian (it). Pages might be created using different page types.
You want to delete a language branch e.g. French (fr) from all pages where it’s used and from the website. You don’t know exactly how many pages use French (fr) language.
You want to delete a language branch e.g. French (fr) from all pages where it’s used and from the website. You don’t know exactly how many pages use French (fr) language.
Thursday, 11 September 2014
Get all Page Types in EPiServer
To get all page types in Episerver, use the following code
Get Usage report of EPiServer Page Types & Block Types
Are you are working with a large project build in Episerver? Over the years developers create new page & block types in the system. Editors then create content using new content types and stopped using the old ones. That resulted in piling up a long list of page types, and some of them were not in use.
Tuesday, 9 September 2014
DNN: TreeView File Manager nodes and Module "Action" menu not working
DNN: Change DotNetNuke Username from SQL Server
If you are going to change the username from SQL Server, make it repeatable, you might want to wrap the syntax in a transaction. You don't want want the two tables to be out of sync.
Here is sample series of T-Sql statements. Should be easy to convert to a stored procedure
declare @oldName nvarchar(128) declare @newName nvarchar(128) declare @error_var int, @rowcount_var int declare @newNameCount int select @oldName = 'someUsername' select @newName = 'newUsername' begin transaction select @newNameCount = count(*) from Users where Username = @newName if @newNameCount > 0 begin RAISERROR('Username already exists. @newName=%s', 10, 1, @newName) ROLLBACK TRANSACTION RETURN end update Users set Username = @newName where Username = @oldName SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT IF @rowcount_var <> 1 OR @error_var <> 0 BEGIN RAISERROR('Could not Update User.Username. @oldName=%s', 10, 1, @oldName) ROLLBACK TRANSACTION RETURN END update aspnet_Users set Username = @newName, LoweredUserName = LOWER(@newName) where LoweredUserName = LOWER(@oldName) SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT IF @rowcount_var <> 1 OR @error_var <> 0 BEGIN RAISERROR('Could not Update aspnet_Users.Username. @oldName=%s', 10, 1, @oldName) ROLLBACK TRANSACTION RETURN END Commit transaction go
/Adnan
This post is from my old blog posted on May 2012, that unfortunately no longer exist.
DNN: Programmatically Assign Role to User In Dotnetnuke
Assigning role to user programmatically can easily be done using DotNetNuke's RoleController in your code. It means without storing role info in database, and programmatically assign a role rights to the user. You can call AddUserRole function in RoleController to perform this action the below code might help you in achieving this
DNN: Programmatically login user In DotNetNuke
In DotNetNuke if you end up in a need to login user programmatically. You can use the following code
DNN: Get SMTP Settings from DotNetNuke
Remove Skin and Container from .ascx control in DotNetNuke
SQL Server: Finding duplicate records in database table
Upgrade SQL Server: Security updates for all supported versions of SQL Server
- SQL Server 2005 SP3
- SQL Server 2005 SP4
- SQL Server 2008 SP1
- SQL Server 2008 SP2
- SQL Server 2008 R2
If you are running... | And your build number is... | Your best course of action is probably to... |
---|---|---|
SQL Server 2005 | Less than 9.0.4035 | Upgrade to Service Pack 3 (9.0.4035) or Service Pack 4 (9.0.5000), then come back for the GDR |
Exactly 9.0.4035 (SP3) | Install the SP3 GDR (9.0.4060) from KB #2494113 | |
Between 9.0.4036 and 9.0.4339 | (a) Upgrade to Service Pack 4 (9.0.5000), then come back for the GDR OR (b) Install the SP3 QFE (9.0.4340) from KB #2494112 | |
Exactly 9.0.5000 (SP4) | Install the SP4 GDR (9.0.5057) from KB #2494120 | |
Greater than 9.0.5000 | Install the SP4 QFE (9.0.5292) from KB #2494123 | |
SQL Server 2008 | Less than 10.0.2531 | Upgrade to Service Pack 1 (10.0.2531) or Service Pack 2 (10.0.4000), then come back for the GDR |
Exactly 10.0.2531 (SP1) | Install the SP1 GDR (10.0.2573) from KB #2494096 | |
Between 10.0.2532 and 10.0.2840 | (a) Upgrade to Service Pack 2 (10.0.4000), then come back for the GDR OR (b) Install the SP1 QFE (10.0.2841) from KB #2494100 | |
Exactly 10.0.4000 (SP2) | Install the SP2 GDR (10.0.4064) from KB #2494089 | |
Greater than 10.0.4000 | Install the SP2 QFE (10.0.4311) from KB #2494094 | |
SQL Server 2008 R2 | Exactly 10.50.1600 (RTM) | Install the GDR (10.50.1617) from KB #2494088 |
Between 10.50.1601 and 10.50.1789 | Install the QFE (10.50.1790) from KB #2494086 | |
Greater than 10.50.1790 (e.g. 10.50.2418 or 10.50.2425) | Wait for the final release of Service Pack 1 Watch for cumulative update or updates to MS11-049 At this time there is no fix for the CTP of SQL Server 2008 R2 SP1 |
What is the difference between a GDR and a QFE?
A GDR (general distribution release) is one that Microsoft support deems is necessary for all systems running SQL Server. A QFE (quick fix engineering) is one that does not affect everyone. Why are there two releases for this important fix? Well, one reason is that after a QFE is installed, it is no longer possible to install a GDR. So, if you have a system that has had previous cumulative updates or QFEs applied, the GDR might not work for you. If you have a system that is exactly at one of the levels described above, then the GDR is probably the better choice, because it will allow you to install either a GDR or a QFE in the future, whereas installing a QFE on such a system kind of paints you into a corner.
There is also a GDR available if you are running Management Studio Express 2005 (but none seem to be listed at this time for the 2008 or 2008 R2 versions):
- KB #2546869
/Adnan
This post is from my old blog dated Thursday, October 2011, that unfortunately no longer exist.
SQL Server: Clean Database Records & reset Identity Columns
I had a problem while back to clean up my database and reset identity columns in all tables. But as we all know the chaos of the database, trace relations and delete records from child tables before parent tables because of foreign key constrains. By manually doing it could take so much time even the database is not that huge. Through some research on Google and books I was able to come up with a solution to achieve my target in few steps. The solution was to use built in stored procedure sp_MSforeachtable (which I already discussed in my previous blog post). So here is the following code bellow for how I re-zeroed my Database:
/Adnan
This post is from my old blog posted on February 2011, that unfortunately no longer exist.
/*Disable Constraints & Triggers*/ exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL' /*Perform delete operation on all table for cleanup*/ exec sp_MSforeachtable 'DELETE ?' /*Enable Constraints & Triggers again*/ exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL' exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL' /*Reset Identity on tables with identity column*/ exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
/Adnan
This post is from my old blog posted on February 2011, that unfortunately no longer exist.
SQL Server: List of tables and their rows counts in a database
I was trying to identify which tables were affected by an update though an application (3rd party). There were more than 300+ tables in the Database. I was hoping to avoid checking each of them for changes. To get the list of tables and their rows counts in a database you can use the following SQL query before and after the update.
Note:
The sysindexes table is usually a little bit inaccurate, because it is not updated constantly. It will also include the 'dtproperties' table, which is one of those hybrid tables that falls neither under the 'system' nor 'user' category. It does not appear in Enterprise Manager's "Tables" view if you choose to hide system objects, but it shows up above.
In any case, it is generally not recommended to query against the system objects directly, so please only use the above for rough, ad-hoc guesstimates.
/Adnan
This post is from my old blog posted on February, 2011, that unfortunately no longer exist.
SELECT [TableName] = so.name, [RowCount] = MAX(si.rows) FROM sysobjects so, sysindexes si WHERE so.xtype = 'U' AND si.id = OBJECT_ID(so.name) GROUP BY so.name ORDER BY 2 DESC
Note:
The sysindexes table is usually a little bit inaccurate, because it is not updated constantly. It will also include the 'dtproperties' table, which is one of those hybrid tables that falls neither under the 'system' nor 'user' category. It does not appear in Enterprise Manager's "Tables" view if you choose to hide system objects, but it shows up above.
In any case, it is generally not recommended to query against the system objects directly, so please only use the above for rough, ad-hoc guesstimates.
/Adnan
This post is from my old blog posted on February, 2011, that unfortunately no longer exist.
SQL Server: How to delete/drop/truncate all the tables from Database
Deleting a Team Project from Team Foundation Server 2005/2008/2010
Deleting a team project from team foundation server is bit tricky. As
there is no user interface available to do it in TFS, you have to use
command line with a TfsDeleteProject.exe utility that ships with TFS 2005/2008/2010 to active this. Look complicated but very easy to do :)
You can do this from any computer in the network that has a access to team foundation server .
open Visual studio command prompt or windows command processor (cmd.exe)
and cd to the following path
In 32 Bit windows operating system
%program files%\Microsoft Visual Studio 9.0\Common7\IDE (2008/2010)
%program files%\Microsoft Visual Studio 8\Common7\IDE (2005)
In 64 Bit windows operating system
%Program Files (x86)%\Microsoft Visual Studio 9.0\Common7\IDE (2008/2010)
%Program Files (x86)%\Microsoft Visual Studio 8\Common7\IDE (2005)
then execute the following command
tfsdeleteproject /q /force /server: "
"
Keep in mind: Your team foundation server User must have an Administrator rights to execute the above command successfully.
/Adnan
Note: This post is from my old blog posted on May, 2011, that unfortunately no longer exist
You can do this from any computer in the network that has a access to team foundation server .
open Visual studio command prompt or windows command processor (cmd.exe)
and cd to the following path
In 32 Bit windows operating system
%program files%\Microsoft Visual Studio 9.0\Common7\IDE (2008/2010)
%program files%\Microsoft Visual Studio 8\Common7\IDE (2005)
In 64 Bit windows operating system
%Program Files (x86)%\Microsoft Visual Studio 9.0\Common7\IDE (2008/2010)
%Program Files (x86)%\Microsoft Visual Studio 8\Common7\IDE (2005)
then execute the following command
tfsdeleteproject /q /force /server:
Keep in mind: Your team foundation server User must have an Administrator rights to execute the above command successfully.
/Adnan
Note: This post is from my old blog posted on May, 2011, that unfortunately no longer exist
Monday, 8 September 2014
Function to Convert Decimal to string Culture monetry value and Revert it back to Decimal
C#: Resize An Image While Maintaining Aspect Ratio and Maximum Height
public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider) { System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile); // Prevent using images internal thumbnail FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); if (OnlyResizeIfWider) { if (FullsizeImage.Width <= NewWidth) { NewWidth = FullsizeImage.Width; } } int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width; if (NewHeight > MaxHeight) { // Resize with height instead NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height; NewHeight = MaxHeight; } System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero); // Clear handle to original file so that we can overwrite it if necessary FullsizeImage.Dispose(); // Save resized picture NewImage.Save(NewFile); }
/Adnan
Note: This post is from my old blog dated Thursday, February 17, 2011, that unfortunately no longer exist