Showing posts with label How To. Show all posts
Showing posts with label How To. Show all posts

Monday, 26 September 2011

Batch file with non-MSDOS coding

Sometimes it needs to run Batch file with non-MSDOS coding. Have spent a lot of time on it until found a way how to convert it. Just had to use Standard->WordPad, it allows to open file with any encoding and convert it to MSDOS encoding. Easy and fast.

Sunday, 8 May 2011

Create User Programmatically in DotNetNuke

One colleague asked about example on how to create user in DotNetNuke programmatically. Here is simple example on C# how to do this:

Friday, 29 April 2011

Configure Users Online in DotNetNuke

Users Online is very good module to display number of users at the site. Also it allows to show usernames of users at the site. To configure Users Online the module it needs to do few steps:

Thursday, 21 April 2011

Number of versions in HTML module (DotNetNuke)

By default HTML module for DotNetNuke has deep of versions equal 5. And there is no way to change it with user interface. This is not good, because sometimes we need more versions to save.

We can fix it easy. Number of versions located in the Portal Settings table and can be easy changed with query like this:

UPDATE {databaseOwner}{objectQualifier}PortalSettings
SET SettingValue = '5'
WHERE (SettingName = 'MaximumVersionHistory') AND (PortalID=0);

All you need is just replace '5' with number of versions you need and PortalID with ID of your portal (usually 0).

Do not forget after this query restart Application Pool (Host/Host Settings/ Restart Application). It should update a cache.

Hope this helps!

Tuesday, 19 April 2011

How to add break to the ModuleActions for DotNetNuke module

Sometimes in the module for DotNetNuke there are a lot of Actions, like this:


It is not good for usability. Would be better to group items somehow with small breaks between Actions in the list, like this:
As you see breaks between items in the menu makes it more user friendly and grouped. it is very easy to add breaks like this, just need to pass special character "~" for Title for ModuleAction object. Here is example of code (C#):


Actions.Add(GetNextActionID(),
"Suppliers",
DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent,
"", "", EditUrl("Currency"), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);


Actions.Add(new DotNetNuke.Entities.Modules.Actions.ModuleAction(GetNextActionID(), "~", ""));


Hope this helps!

Saturday, 9 April 2011

How to refresh favicon.ico in the browser

Got small problem. After changing favicon.ico it has no affect for browser (Google Chrome). Both F5 and Ctrl+F5 do not help. The most popular recommendation in the web is to clear all history and cache in Google Chrome. This is not good solution for me, because a lot of settings for my work.

After small research i found a way how to do this easy. Just need to type in the address line 

http://yoursite.com/favicon.ico

it shows your old icon, then click Ctrl+F5 and it shows correct one now. Then back to the site. See? Icon has been updated.

Hope this helps!

Thursday, 31 March 2011

Force file download instead showing in browser

Sometimes we would like to start attachment downloading instead showing in browser, for example for images (like PNG, JPG, GIF, etc). But usually browser displays content instead to prompt for saving. To fix this issue we just need to add one line of the code:

Response.AddHeader("Content-disposition", "attachment; filename=\"photo.png\"");

It adds header to the response and browser will prompt client for file saving.

Hope this helps.

Sunday, 27 March 2011

How to upgrade DotNetNuke module or SQL scripts for new versions

DotNetNuke (DNN) is very good CMS. It allows easy and fast build new modules without any problems. Furthermore it allows to do an upgrade of old modules with beautiful and perfect process. For example, we have Module with version 01.00.00. During installation all SQL scripts locate in the 01.00.00.SqlDataProvider. This file contains all required SQL for correct Module functionality.

In case you need to upgrade your module, then all what you do is add to your module new file, like 01.00.01.SqlDataProvider. During installation DNN framework checks current version and runs all scripts above current version. It allows to do cumulative upgrade without any problems.

But some clients do an upgrade manually and it can be a lot of headache. So here is a way how to protect your SQL script:

IF(
NOT EXISTS(
SELECT sc.name 
FROM syscolumns sc
WHERE (sc.id IN 
(SELECT so.id
FROM sysobjects so
WHERE so.name='{objectQualifier}Survey'))
AND
(sc.name='CategoryID')
)
)
BEGIN
ALTER TABLE {databaseOwner}{objectQualifier}Survey ADD CategoryID int NOT NULL DEFAULT(0)
END

As you see, this script checks for field before creation. So, do not need to worry customer runs it twice or more times.

PS: My old teacher said: Good code allows to remove half of lines and continues to work :)

Friday, 25 March 2011

How to Delete Multiple Pages at One Time at DotNetNuke

Sometimes we have to remove several tabs/pages from the portal in DotNetNuke. With standard tools it can take some time, but with Pages Admin - Tabs Manager it can be done in few seconds and just 3 steps. Just look at these screenshots:

Thursday, 24 March 2011

How to send POST in background

Sometimes it needs to send POST in the background and get some info. In our case we had to send POST to the Protx (UK payment gateway - now its SagePay). Here is quick C# script how to do this:


private string ChargeProtx(CreditCardInfo objCardInfo)
{
    System.Net.HttpWebRequest request = 
(System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create("https://ukvpstest.protx.com/VSPSimulator/VSPDirectGateway.asp");


    request.Method = "POST";
    
string postData = "VPSProtocol=2.22&" +
"TxType=PAYMENT&" +
"Vendor=vendorname&" +
"VendorTxCode=" + objCardInfo.OrderID + "&" +
"Amount=" + objCardInfo.Amount.ToString().Replace(",",".")+"&"+
"Currency=GBP&" +
"Description=Direct_payment&" +
"CardHolder=" + objCardInfo.FirstName + " " + objCardInfo.LastName + "&" +
"CardNumber=" + objCardInfo.Number + "&";


    byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
    request.ContentLength = byteArray.Length;
    System.IO.Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();


    System.Net.HttpWebResponse responseX = (System.Net.HttpWebResponse) request.GetResponse();
    dataStream = responseX.GetResponseStream();
    System.IO.StreamReader reader = new System.IO.StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();


    reader.Close();
    dataStream.Close();
    responseX.Close();


return responseFromServer;
}

Hope this helps!

Wednesday, 23 March 2011

How to insert one DNN module into another

This is not common task between different modules. But it is good to use controls inside of single project and this is very popular. So, to add one module to another you just need to know name of the primary control. Then your form will be like this:
<%@ Register TagPrefix="dnn" TagName="MultiEdit" Src="~/DesktopModules/dnn.MultiEdit/MultiEdit.ascx" %>
<dnn:multiedit id="objMultiEdit" runat="server"></dnn:multiedit>

Hope this helps!

How to rotate SQL Table

There was very good customer from Australia. He always had interesting projects. One of this project was to show report on products sales. At start it looks like simple project, but there were two issues:
1) Customer had very big amounts of data in MS SQL.
2) He would like to show data grouped in columns, not rows.

First version of project does grouping in the columns at the C# code, but with such big amount of data it was crazy slow and takes a lot of memory. This is why grouping has been moved to the MS SQL side. Here is a beautiful script (sorry, but can't remember original source):