Tuesday, 9 September 2014

DNN: TreeView File Manager nodes and Module "Action" menu not working

I upgraded a client's DotNetNuke version to DotNetNuke 5.1 to 5.6.3. The DNN Portal which was running DotNetNuke Version 5.6.3, while I was working on it, all of a sudden the filemanager stopped working properly "Spinner in the Root TreeView". Same problem was with the modules "Action" menu. It was a mess to do anything on the website in edit mode.


The problem for DNN file manager treeview looks like this:





The treeview of the folder control seems to be in a endless loop and the treeview does not open the folder structure.

In some cases, an error message displayed, other wise there was no error message.
.
"Runtime error in Microsoft JScript: Sys.ArgumentException: Cannot deserialize empty string. Parameter name: data"


The problem seemed to be in any case the same.

So If you are experiencing this problem check the Compression Setting which you can find in the "Performance Settings" section under the host setting.




If the GZip Compression is selected, you must change the setting to "no compression"

Save the change, and try the file manager, I'm pretty sure, it will work :)

Hope that helps.

As far as I know,  the problem is already exists for a long time in the various different versions of DotNetNuke.

So if you have this problem in an older version, check the setting and look what happens.

September 09, 2014

How to Change a DNN Username Using SQL Server

Sometime users request to change their usernames, the reason could be they don't want to lose their activities in the system. There can be many other reasons but the fact is I have deal with these request time to time.So here is a solutions.

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 
September 09, 2014

How to Programmatically Assign a Role to a User in DNN

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

RoleController objRoles = new RoleController();
RoleInfo objRole = new RoleInfo;

// autoassign user to portal roles

var arrRoles = objRoles.GetPortalRoles(user.PortalID);

foreach (var obJrole in arrRoles) {
if (objRole.AutoAssignment == true) {
objRoles.AddUserRole(user.PortalID, user.UserID, objRole.RoleID, Null.NullDate, Null.NullDate); }
}

objRoles.AddUserRole(user.PortalID, user.UserID, 5, Null.NullDate, Null.NullDate); 
September 09, 2014

How to Programmatically Log In a User in DNN


In DotNetNuke if  you end up in a need to login user programmatically. You can use the following code
var loginStatus = new UserLoginStatus();

var objUser = UserController.ValidateUser(0, "host", "dnnhost", "", "", "0.0.0.0", ref loginStatus);

if (loginStatus != UserLoginStatus.LOGIN_FAILURE || loginStatus != UserLoginStatus.LOGIN_USERNOTAPPROVED)
{
   UserController.UserLogin
   (this.PortalId,
    objUser, PortalSettings.PortalName,
    HttpContext.Current.Request.UserHostAddress, false);
}

September 09, 2014

How to Get SMTP Settings from DNN

In your module, if you need to access to the SMTP settings specified in the HOST settings of the DNN portal, you can use the following function to retrieve it and use it in your code.
You can pass the following parameters in the function to retrieved the required setting value

- SMTPAuthentication
- SMTPEnableSSL
- SMTPPassword
- SMTPServer
- SMTPUsername

var hostSettings = DotNetNuke.Entities.Host.Host.GetHostSettingsDictionary();
string SMTPServer = hostSettings["SMTPServer"];
string SMTPAuthentication = hostSettings["SMTPAuthentication"];
September 09, 2014

How to Remove Skin and Container from an ASCX Control in DNN

I was stuck in an annoying problem while working of one of my modules in DNN. The Ideas was to load a usercontrol while click on button, But instead of clean skinless form, DNN automatically add the container and skin into it. That bugged me a lot. So how can you open a .ascx user control in a popup/ new window in DotNetNuke without a Skin and Container. 


Here is the solution of the problem.

On the button onClick server side action use the following code

Globals.NavigateURL(
 TabId,
 "ControlName", "Param1", ParamValue,
 "SkinSrc=[G]" + Globals.QueryStringEncode( DotNetNuke.UI.Skins.SkinInfo.RootSkin + "/" + 
 Globals.glbHostSkinFolder + "/" + "No Skin" ),
 "ContainerSrc=[G]" + Globals.QueryStringEncode( DotNetNuke.UI.Skins.SkinInfo.RootContainer +
 "/" + Globals.glbHostSkinFolder + "/" + "No Container" )
);
or for simple not showing skin you can use

NavigateURL(
 TabId,
 "ControlName",  
 "Param1", 
 ParamValue,
 SkinSrc=[G]" + Globals.QueryStringEncode( DotNetNuke.UI.Skins.SkinInfo.RootSkin +
 "/" + Globals.glbHostSkinFolder + "/" + "No Skin" )
)


Explanation: [G] is used in Dotnetnuke as a placeholder for current portal location of the specific folder. No Skin is a skin file (No Skin.ascx) in Skin folder in path \portals. There is even a No Container.ascx in container folder if you dont want to use Container.
September 09, 2014