Tuesday, January 28, 2014

How to manage File Extensions in Dotnet Nuke.

In order to add or remove a file extension in dot net nuke you need to follow following steps:
  1. Login as a Superuser (or Host).
  2. Go to the Host Settings page.
  3. Go to the tab "Other Settings".
  4. Find the "Allowable File Extensions" field.
  5. Add or remove file extensions as desired to allow or disallow file types, separated by commas.
  6. Click "Update" at the bottom of the page to save your changes.

Thursday, July 26, 2012

How to drop all objects in a SQL Server Database

Courtesy: Paige C#

/* Drop all non-system stored procs */

DECLARE @name VARCHAR(128)

DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])

WHILE @name is not null

BEGIN

    SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'

    EXEC (@SQL)

    PRINT 'Dropped Procedure: ' + @name

    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 AND [name] > @name ORDER BY [name])

END

GO

 

/* Drop all views */

DECLARE @name VARCHAR(128)

DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL

BEGIN

    SELECT @SQL = 'DROP VIEW [dbo].[' + RTRIM(@name) +']'

    EXEC (@SQL)

    PRINT 'Dropped View: ' + @name

    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 AND [name] > @name ORDER BY [name])

END

GO

 

 

/* Drop all functions */

DECLARE @name VARCHAR(128)

DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL

BEGIN

    SELECT @SQL = 'DROP FUNCTION [dbo].[' + RTRIM(@name) +']'

    EXEC (@SQL)

    PRINT 'Dropped Function: ' + @name

    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 AND [name] > @name ORDER BY [name])

END

GO

 

/* Drop all Foreign Key constraints */

DECLARE @name VARCHAR(128)

DECLARE @constraint VARCHAR(254)

DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)

WHILE @name is not null

BEGIN

    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)

    WHILE @constraint IS NOT NULL

    BEGIN

        SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT ' + RTRIM(@constraint)

        EXEC (@SQL)

        PRINT 'Dropped FK Constraint: ' + @constraint + ' on ' + @name

        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND CONSTRAINT_NAME <> @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)

    END

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)

END

GO

 

/* Drop all Primary Key constraints */

DECLARE @name VARCHAR(128)

DECLARE @constraint VARCHAR(254)

DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)

WHILE @name IS NOT NULL

BEGIN

    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)

    WHILE @constraint is not null

    BEGIN

        SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT ' + RTRIM(@constraint)

        EXEC (@SQL)

        PRINT 'Dropped PK Constraint: ' + @constraint + ' on ' + @name

        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND CONSTRAINT_NAME <> @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)

    END

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)

END

GO

 

/* Drop all tables */

DECLARE @name VARCHAR(128)

DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL

BEGIN

    SELECT @SQL = 'DROP TABLE [dbo].[' + RTRIM(@name) +']'

    EXEC (@SQL)

    PRINT 'Dropped Table: ' + @name

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 AND [name] > @name ORDER BY [name])

END

GO

 

 

How to update skin through Dotnet Nuke database

update [dbo].[PortalSettings] set SettingValue='[G]Skins/YourSkin.ascx' where SettingName='DefaultPortalSkin'

Monday, September 26, 2011

How to get the current screen resolution in Silverlight

To get the screen resultion in silverlight we can use the browser's window object. The browser window object is HtmlPage.Window. The namespace under which the HtmlPage comes is System.Windows.Browser.
Here is the code to find out the width and height according to current screen resolution.

string width = HtmlPage.Window.Eval("screen.width").ToString();
string height = HtmlPage.Window.Eval("screen.height").ToString();

Monday, May 30, 2011

How to delete files in a directory

Just write one line code to delete the files from the directory.

string dirPath = "C://XMLFiles";
//search for the xml files in the directory and delete all files
new List(Directory.GetFiles(dirPath,@"*.xml")).ForEach(file => { File.Delete(file); });

Here, I am deleting all the XML files from the dirPath directory.

Monday, March 14, 2011

Module Definitions tab missing in DNN host navigation

Sometimes you have to face the negative consequences of working in a team. Well this is not the case for everyone. But, I faced the same problem, the module definitions was deleted by some of the team member and I was scratching my head to figure out where it disappeared?
Well, after track back I figured out that the tabs appearance settings are stored in the DNN's Tabs table in database.
So, I investigated that the IsDeleted value was set to true for the Module Definitions tab. Setting the value back to false worked for me :)

Tuesday, December 7, 2010

Install missing templates in the installed Visual Studio templates

One day I tried to create new WCF Service Application and when i opened the Visual studio and clicked on Add new project I found that this project option is missing from my Visual studio templates. To add missing templates to your current installed templates you need to run following command on Visual studio command prompt after closing all the instances of the Visual studio.
devenv/installvstemplates
Press Enter.
Let the processing to be completed and then open visual studio. Now all the missing templates would be visible under Visual Studio installed templates.

Wednesday, December 1, 2010

Custom Assembly in Sql Server Reporting Services (SSRS).

Most of the times we need to write code in our SSRS reports. So, the goal of this article, to show you how easy it really is to write custom code for SQL Server Reporting Services. We can write the code in two ways:
1. Embedded code
2. Custom Assemblies

Embedded Code:
So let's get started and add some embedded code to a report. Open Visual Studio and create a new report project and a new report (Right click the project -> Add New Item -> Report).

Follow the steps:

1. Go to Report menu and click Report Properties.
(If the Report menu is not available, click within the report design area.)
2. On the Code tab, in Custom Code, type the code.
e.g
Public Function Hello() as String
Return "Hello All"
End Function

Now add a textbox to the report and add the code =Code.Hello() to the expression of the textbox. When you will preview the report you can see "Hello All" on the report. That is as far as we are going to take embedded code.

Custom Assemblies:
This is a much more useful feature since you aren't constrained to writing code in VB.Net on a small dialog in the report designer. The need for custom assemblies lies when we need to write code in such a way that is not possible in the embedded code. e.g. In my code I was trying to use the dynamic connection string for my reports. Firstly i tried to write the code as embedded but that had very limited functionality. So, I used custom asseblies to achieve this. It is not a big deal to write a custom assebly in own way. but the only thing is that we need to cope with the Code Access Security (CAS).

Firstly let me explain you how to create a custom assembly.

1. Open the Visual Studio and Create a Class library project in C# or VB (either of the langauages you are comfortable with). Say it CustomAssembly and rename Class1.cs to MyCustomClass.cs
2. Write the code in the class file e.g.
public static string LoadXML(string strenv, string Path)
{
XmlDocument xmldoc = new XmlDocument();
XmlNode node = default(XmlNode);
string XMLFilePath = Path;
XmlUrlResolver objResolver = new XmlUrlResolver();
objResolver.Credentials = CredentialCache.DefaultCredentials;
xmldoc.XmlResolver = objResolver;
xmldoc.Load(XMLFilePath);
if (strenv.ToLower() == "development")
      {
         node = xmldoc.SelectSingleNode("ConnectionString/Development");
      }
if (node != null)
                {
                    con = node.InnerXml;
                }
return con;
}
3. Now you are done with the code part for the custom assembly.
4. Copy the assembly from the bin folder to the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies and C:\Program Files\Microsoft SQL Server\MSRS10_50.SQLSERVER2008R2\Reporting Services\ReportServer\bin
Note: I am using SQLServer 2008 R2 here so my folder is MSRS10_50.SQLSERVER2008R2, please check your folder and place the assembly file there.
4. The next step is to use this assembly within you SSRS. To acheive this Open Visual Studio and create a new report project and a new report (Right click the project -> Add New Item -> Report). Go to Report menu and click Report Properties.On the references tab, locate the assembly and add the assembly.
5. On the code tab write the code =CustomAssembly.MyCustomClass.LoadXML("development","some path")
This is the last step of custom assembly.
Now comes the Code Access Security part
Code Access Security
This code would not work until we dont have some permissions to run the DLL. The permissions could be IO permissions, environment permissions and security permissions. Add the following lines for the assert permissions.
System.Net.WebPermission webPermission;
webPermission = new System.Net.WebPermission(System.Net.NetworkAccess.Connect, Path);
webPermission.Assert();

For security permissions you can use the following method just after the class name.

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]

Also, we need to change the rssrvpolicy configuration file. This file can be located under the Report server installation folder.

Open the file and add the following code snippet under the code group tag.
  
<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="NewCodeGroup" Description="A special code group for my custom assembly.">
<IMembershipCondition class="UrlMembershipCondition" version="1"  Url="C:\Program Files\Microsoft SQL Server\MSRS10_50.SQLSERVER2008R2\Reporting Services\ReportServer\bin\CustomAssembly.dll" />
</CodeGroup>

This code generally provides the Full Trust permission to our custom assembly and enables it to override any permission barrier.