Tuesday, 31 December 2013

DNN - NB_Store - Backoffice Pagination "Not Found" error

In the DotNetNuke - NB_Store Backoffice, whenever the list (example: catalog list) is longer to have a pagination, navigating to the new page gives exception with "Not Found" message.
This is the link to the catalog list :
http://mywebsite.com/BACK-OFFICE/ctl/AdminProduct/mid/..... 
When I click the "Next" or "2" (second page link), it gives the above mentioned exception.

This was the question I had asked on DNN NB_Store codeplex discussion forum:
http://nbstore.codeplex.com/discussions/473805
I am repeating it here with a temporary solution, so that I can also add screenshots here for better clarity.

Solution:
The catalog list link is as below:
http://mywebsite.com/BACK-OFFICE/ctl/AdminProduct/mid/475?SkinSrc=%2fDesktopModules%2fNB_Store%2fSkins%2fDark%2fDark
If you notice in the url, it has a parameter "SkinSrc" which has the path to the skin file. This basically overrides the default skin of your website.
If you click the "Next" page link at the bottom of the page, you will get an error as below:
This is the link to the next page:
http://sandapple.com/BACK-OFFICE/ctl/AdminProduct/mid/475/CatID/-1/currentpage/2?SkinSrc=/DesktopModules/NB_Store/Skins/Dark/Dark
You can get the next page by removing the "SkinSrc" parameter. This will show you the next page with the default skin of the website.

Monday, 25 November 2013

Winforms - Update UI for Long running processes

If you have a long running process in your windows forms application you might try to update a message label in the UI to say "Processing. Please wait...". But as a matter or fact, the UI doesn't get updated till the process is completed. in this case it doesn't serve your purpose of notifying the user by updating a UI element.
private void btnAzerbaijanReportJob_Click(object sender, EventArgs e)
{
lblMessage.Text = "Please wait..";
IneedTime(); // Long running process.
lblMessage.Text = "Done.";
}
In the above case, lblMessage will never display the text "Please wait..", because IneedTime() method executes on the UI thread and UI will not be updated until IneedTime() methods finish executing.
To overcome this, there are 2 methods.
1) Run long running process (IneedTime() in the above code) in a separate thread. In case you dislike to make your app a multi thread app, you have a second option.
2) Second option is to force the UI to redraw the UI even before your long running method executes. For this you need to call the
Application.DoEvents() method. What this method does it that it will process all the windows messages currently in the message queue. So this queue will already have the paint message which was issued when we set the label (lblMessage) text.
private void btnAzerbaijanReportJob_Click(object sender, EventArgs e)
{
lblMessage.Text = "Please wait..";
Application.DoEvents();
IneedTime(); // Long running process.
lblMessage.Text = "Done.";
}
In case you see the UI is not updated as expected, you can also use the below code.
lbl.Invalidate();
lbl.Update();
Application.DoEvents();
or even
lbl.Refresh();
Application.DoEvents();
to redraw the label UI.

Monday, 18 November 2013

Windows Phone - How to use Resource Files

Resource Files in Windows phone has the similar concepts as it was in Web Forms. It can be used for localization as well as store string values to be used across your apps. Resource files are a nice way to reduce hardcoding strings inside your application code.
The default resource file added to your solution when the project is created is "AppResources.resx" which is in the "Resources" folder at the root of your project folder hierarchy. This default file is called the "neutral language resource" because it is the fallback resource file even in localization scenarios.

Note: As in web forms and win forms, each culture has its own resource file, with the culture suffixed to the filename (AppResources.en-US.resx). We will discuss more on localization scenarios in another post.

Below is the code to dynamically bind your resource to XAML page element's properties.
"{Binding Path=LocalizedResources.ApplicationHeader, Source={StaticResource LocalizedStrings}}"
For example if we want to bind a string resource to the Text property of TextBlock Control:

<TextBlock Text="{Binding Path=LocalizedResources.ApplicationHeader, Source={StaticResource LocalizedStrings}}" />

Monday, 4 November 2013

C# Remove Invalid filename characters from string

Ever wanted to remove invalid filename characters from a string while dealing with file related code?
Here is a pretty easy solution using C# Regex class.
The funda is to find any invalid character/characters from the string and remove it.
Here is the method which does the trick.
private static string GetValidFileName(string fileName)
{
// remove any invalid character from the filename.
return Regex.Replace(fileName.Trim(), "[^A-Za-z0-9_. ]+", "");
}
The code even preserves white spaces and removes only invalid special characters. The Regex patter can also be replaced by "[^a-zA-Z 0-9'.@]" A better solution which I prefer is using LINQ:
private static string GetValidFileName(string fileName)
{
return Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty));
}
There is a solution mentioned in MSDN which personally I do not find very appealing.
static string CleanInput(string strIn)
{
 // Replace invalid characters with empty strings. 
 try {
    return Regex.Replace(strIn, @"[^\w\.@-]", "", 
       RegexOptions.None, TimeSpan.FromSeconds(1.5)); 
 }
 // If we timeout when replacing invalid characters,  
 // we should return Empty. 
 catch (RegexMatchTimeoutException) {
    return String.Empty;   
 }
}

Saturday, 26 October 2013

Windows Phone - The name “LocalizedStrings” does not exist in the namespace

The name "LocalizedStrings" does not exist in the namespace

Today morning all of a sudden, my windows phone project that I had been working on for months started showing up this compile time error message at:
<Application.Resources>
    <local:LocalizedStrings xmlns:local="clr-namespace:Bins" x:Key="LocalizedStrings"/>
</Application.Resources>
It was not a show stopper as I was able to force VS2012 to ignore this error and continue with the build. But I some how wanted to take some time to fix the issue. The error message starting showing up after my machine had an unexpected crash. So the most probable reason for it is a corrupted file.
It was fixed by cleaning up some visual studio chach files.
Steps:

  1. Close Visual Studio.
  2. Go to the folder location : "%LOCALAPPDATA%\Microsoft\Phone Tools\CoreCon\".
  3. Delete the contents of the folders: 10.0 and 11.0.

Open up your project and compile. The error must have disappeared now.

Wednesday, 23 October 2013

Windows 8 Essential Shortcuts

Agreed upon the fact that Windows 8 is a very Touch friendly OS, its not that partial to its keyboard fan boys either. Windows 8 has a very rich set of keyboard shortcuts to boost your productivity if your hands are resting upon keyboard most of the time. Below are a selected list of 15 shortcuts which I found useful.
Caution: All the shortcuts are Windows Key centric.

  1. Windows Key + C : Displays Charms menu.
  2. Windows Key + X : Brings up a menu of advanced system options, including Windows Control Panel, Command Prompt, Task Manager and File Explorer.
  3. Windows Key + I : Displays the Settings menu for the current app. For example, if you’re in Internet Explorer 10, this key shows Internet options. If you’re on the Start menu, it shows general OS settings.
  4. Windows Key + Q : Brings up the apps search menu that allows you to search your list of installed programs.
  5. Windows Key + D : Activates desktop mode.
  6. Windows Key + Tab : Brings up the Task Switcher and toggles between Windows 8-style apps.
  7. Windows Key + H : Brings up Share menu for the current app. For example, hitting Windows Key + H in Bing Maps, lets you email or share map information on social networks.
  8. Windows Key + M : Opens desktop mode and minimizes all windows.
  9. Windows Key + W : Opens universal search menu and sets it to search settings.
  10. Windows Key + F : Opens universal search menu and sets it to search files.
  11. Windows Key + R : Opens Run menu where you can launch programs by typing in their executable file names.
  12. Windows Key + E : Opens File Explorer to the “My Computer” view which shows all your drives.
  13. Windows Key + Number Key (1-9) : Switch to desktop mode and make the Nth application on the task bar active where N is the number key you hit and 1 is the furthest taskbar icon to the left.
  14. Windows Key + . (period key) : Docks the current Windows 8-style application to the right or left, depending on how many times you hit it.
  15. Windows Key + Z : Brings up app menu, which shows contextual options for the active app.
Happy keyboarding.

Monday, 21 October 2013

Windows 8.1 - Blurry Text Fix

My first sight of desktop after upgrading to Windows 8.1 Pro was very disappointing.
All the icons and fonts appeared blurry and weird on my decent resolution (1600x900) Lenovo Yoga 13 monitor. For a moment I regretted for having upgraded the OS without going through enough reviews online.
But there is no going back, I want the lastest OS update on my machine.
I "Binged" and could find this issue was reported since the preview release of Windows 8. But there was no proper resolution mentioned even on Microsoft forums (of course they are not the best knowledge centers). Finally determined to play around with the settings, the solution to the issue was pretty straight forward. I will reproduce the steps I followed:

Step 1) Right Click Desktop and click "Screen Resolution" from the menu.
Step 2) On the Screen Resolution Window, click the "Make text and other items larger or smaller" link.
Step 3) Select the "Let me choose one scale level for all my displays".
Step 4) Select "Smaller - 100%" option and click Apply.
It will prompt you for a re login and proceed with it. Hopefully this should fix your blurry text issue.
On the Screen Resolution Window, click the "Make text and other items larger or smaller" link
Select "Let me choose one scale level for all my displays". Select "Smaller - 100%" option.