Windows Phone 8 Battery API

The Battery API makes a nice addition to the WP8 SDK. I can see in the near future that some applications will display the battery metrics on a Live Tile or in the application that hides the System Tray. The Battery API is pretty easy to use: Get the Battery instance with Battery.GetDefault() Bind to the event RemainingChargePercentChanged. The battery properties are: RemainingChargePercent: gets a value that indicates the percentage of the charge remaining on the phone’s battery RemainingDischargeTime: gets a value that estimates how much time is left until…

Read More

Privacy policy generator for websites and apps

This post mainly answers the question how and why you should add a privacy policy to your Windows Phone app. If you want to read a more general overview of privacy policies in mobile apps then you can read that here If you want to skip all that and just use our generator to help you make a privacy policy for your Windows Phone app then follow me Since we’ve launched our mobile apps privacy policy generator last week I’ve been wondering how good the documentation was out there regarding…

Read More

Add Rows to a DataTable

To add new records into a dataset, a new data row must be created and added to the DataRow collection (Rows) of a DataTable in the dataset. The following procedures show how to create a new row and insert it into a DataTable. Examples are provided for both typed and untyped datasets. I created this Dataset (view picture). dsOperation dt = new dsOperation(); DataRow opRow = dt.Tables[“Operations”].NewRow(); opRow[“Group”] = “FirstGroup”; opRow[“SubGroup”] = “SecondGroup”; opRow[“Debit”] = 0; opRow[“Credit”] = 10; dt.Tables[0].Rows.Add(opRow);

Read More

Getting error “The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine”

While I was trying to connect to an Access Database from Visual Studio 2010 on my Windows 7 x64 server, I got the following error message, SOLUTION After a detailed research on the above error message, I was able to identify that the 64-bit framework dlls weren’t able to 32-bit versions of the ‘Microsoft.ACE.OLEDB.12.0‘ provider modules. Since I was running Visual Studio on a 64-bit machine, IIS 7 is not (by default) serving 32-bit applications. However, I noticed that the database engine operated on 32-bit. I followed these steps to…

Read More

Accessing SMTP Mail Settings defined in Web.Config File Programmatically

I needed to read my SMTP email settings defined under system.net section in my web.config file. In order to use eNewsLetter and other SiteAdmin CMS modules that sending email notifications; you can setup your web.config to defind SMTP services settings. Below is one example of SMTP email setting defined in web.config file:(Under <configuration> Section)     <system.net>        <mailSettings>            <smtp deliveryMethod=”Network” from=”testuser@domail.com”>                <network defaultCredentials=”true” host=”localhost” port=”25″ userName=”kaushal” password=”testPassword”/>            </smtp>        </mailSettings>    </system.net> To Access, this SMTP Mail Setting Programatically, you need to import below namespaces: using System.Configuration;using System.Web.Configuration;using System.Net.Configuration; The .NET Framework provides…

Read More

Proper MIME types for Embedded @font-face Fonts

After some exhaustive research, I managed to find the best server settings for serving web fonts. There are a number of font formats that one can set MIME types for, on both Apache and IIS servers. I’ve traditionally had luck with the following: svg as “image/svg+xml” ttf as “application/x-font-ttf” or “application/x-font-truetype” otf as “application/x-font-opentype” woff as “application/font-woff” (per my August 16, 2013 update below) eof as “application/vnd.ms-fontobject” According to the Internet Engineering Task Force who maintain the initial document regarding Multipurpose Internet Mail Extensions (MIME types) here: https://tools.ietf.org/html/rfc2045#section-5 … it…

Read More

Create DataTable

Data is read from a database. It is generated in memory from input. DataTable is ideal for storing data from any source. With it we take objects from memory and display the results in controls such as DataGridView. The DataTable type is a powerful way to store data in memory. You may have fetched this data from a database, or dynamically generated it. We get a DataTable with four columns of type int, string and DateTime. This DataTable could be persisted or displayed, stored in memory as any other object,…

Read More

Parse HTML page and capture contents

Here I show a simple class that receives the HTML string and then extracts all the links and their text into structs. It is fairly fast, but I offer some optimization tips further down. It would be better to use a class. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace PSC { public class Finder { public struct LinkItem { public string Href; public string Text; public override string ToString() { return Href + “\n\t” + Text; } } public class LinkFinder { public static…

Read More

DateDiff() function in C#

I have written the following DateDiff() function in C#. VB.NET users already had it using the Micrsoft.VisualBasic.dll assembly. Now you can use it without referencing this ‘ugly’ extra assembly. using System; namespace PureSourceCode.System { public enum DateInterval { Year, Month, Weekday, Day, Hour, Minute, Second } public class DateTimeUtil { public static long DateDiff(DateInterval interval, DateTime date1, DateTime date2) { TimeSpan ts = date2 – date1; switch (interval) { case DateInterval.Year: return date2.Year – date1.Year; case DateInterval.Month: return (date2.Month – date1.Month) + (12 * (date2.Year – date1.Year)); case DateInterval.Weekday: return…

Read More

Create a File or Folder

        // Specify a name for your top-level folder.         string folderName = @”c:\Top-Level Folder”;         // To create a string that specifies the path to a subfolder under your          // top-level folder, add a name for the subfolder to folderName.         string pathString = System.IO.Path.Combine(folderName, “SubFolder”);         // You can write out the path name directly instead of using the Combine         // method. Combine just makes the process easier.         string pathString2 = @”c:\Top-Level Folder\SubFolder2″;         // You can extend the depth of your path if you…

Read More

Populate DropDownList with Selected Value in EditItemTemplate of GridView in ASP.Net

In this article I will explain with an example how to use ASP.Net DropDownList control in the EditItemTemplate of ASP.Net GridView control. I created this GridView with EditItemTemplate. <asp:GridView ID=”GridView1″ runat=”server” AllowPaging=”True” AllowSorting=”True” AutoGenerateColumns=”False” AutoGenerateEditButton=”True” DataKeyNames=”CodeAction” OnRowEditing=”GridView1_RowEditing” OnRowDataBound=”GridView1_RowDataBound” OnRowUpdating=”GridView1_RowUpdating” OnPageIndexChanging=”GridView1_PageIndexChanging” OnRowCancelingEdit=”GridView1_RowCancelingEdit”> <Columns> <asp:CommandField ShowSelectButton=”True” /> <asp:BoundField DataField=”CodeAction” HeaderText=”CodeAction” ReadOnly=”True” SortExpression=”CodeAction” /> <asp:BoundField DataField=”Description” HeaderText=”Description” SortExpression=”Description” /> <asp:TemplateField HeaderText=”Group” SortExpression=”GroupID”> <EditItemTemplate> <asp:Label ID=”Label1″ runat=”server” Text='<%# Eval(“GroupID”) %>’ Visible=”false”></asp:Label> <asp:DropDownList ID=”ddlGroup” runat=”server” DataTextField=”Group” DataValueField=”IDGroup” AutoPostBack=”True” OnSelectedIndexChanged=”ddlGroup_SelectedIndexChanged”> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID=”Label1″ runat=”server” Text='<%# Eval(“GroupID”) %>’></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText=”Subgroup” SortExpression=”SubGroupID”> <EditItemTemplate> <asp:Label…

Read More

ASP.NET Menu and SiteMap Security Trimming

With ASP.NET 2005 Microsoft introduced a pretty solid menu which is integrated with a configuration driven sitemap. The cool part is that the menu can be hooked in with your security roles, so you don’t have to worry about hiding or showing menu options based on the user – the menu options are automatically kept in sync with what the user is allowed to see.   Step one – Define the Sitemap I’m using a static sitemap defined in a Web.sitemap file, and it’s especially simple since there’s no is…

Read More

Working With Share Link Task in Windows Phone 8

In this article we will learn about the Share Link Task. This task enables the user to share a link from the app itself on various social media and other sharing platforms. It can be a very useful feature for promoting your app on various platforms. Let’s see how to use it. Share Link Task This is a kind of launcher provided by Windows Phone to launch the share screen from an app so that the user can share the link. The task can be customized with various properties for…

Read More

Every application needs identity & access control

Nearly every application deals with data and resources that need to be protected. Implementing secure authentication and authorization is therefore an essential requirement in most cases. While historically the solution to that problem has been either Windows authentication or username/password, this might not hold true anymore. In the distributed and mobile application landscape, passwords have become an anti-pattern, and single sign-on, security token services and federation are the prevalent technologies to achieve a seamless security experience for your users. We have worked in this space for several years, and our…

Read More

Five documentation apps for .NET developers

Documentation is a necessary evil for software developers. While C# and VB.NET have basic facilities for commenting code and embedding XML documentation into code, turning that into a more useful form is outside the realm of Visual Studio. These five applications can help you turn your comments and notes into proper documentation.   1: Sandcastle Sandcastle is probably one of the best known documentation generators for .NET, and it has the benefit of being open source. Unfortunately, Sandcastle is difficult to use on its own, prompting a small cottage industry…

Read More

IIS 7.5 error: Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

Today I installed Clean Windows Web Server 2008 R2 64-bit with IIS 7.5. To my surprise opening .NET 4.0 application I received the following error: IIS 7.5 Detailed Error – 500.21 – Internal Server ErrorServer Error in Application “DEFAULT WEB SITE”Internet Information Services 7.5[Error Summary]HTTP Error 500.21 – Internal Server ErrorHandler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list[Detailed Error Information]Module IIS Web CoreNotification ExecuteRequestHandlerHandler PageHandlerFactory-IntegratedError Code 0x8007000dRequested URL https://localhost:80/default.aspxPhysical Path C:\inetpub\wwwroot\default.aspxLogon Method AnonymousLogon User Anonymous[Most likely causes:]•Managed handler is used; however, ASP.NET is not installed or is…

Read More

Linqer (SQL to Linq converter)

Linqer is a SQL to LINQ conversion tool. It helps learning LINQ and convert existing SQL statements. Not every SQL statement can be converted to LINQ, but Linqer covers many different types of SQL expressions. Linqer supports both .NET languages – C# and Visual Basic. Because LINQ is a part of the C# and VB languages, it is sensitive to data type conversion. Linqer performs required type castings in the produced LINQ statements. It can convert the most usable SQL Server functions. The full list of supported MSSQL functions can…

Read More

C# string to Formatted HTML string

Is there a tool out there that can turn a C# string of unformatted HTML (no indentions, no new lines, etc) into a Formatted HTML string?I am in a situation where I am generating an HTML string, and I am outputting it into a multiline textbox. Write now, it is wrapping, but is showing up similar to a paragraph. I would like it to be shown as formatted HTML? It wouldn’t even have to be very nice formatting, but at least not show a paragraph of HTML.For having a good…

Read More

Synchronization Essentials

So far, we’ve described how to start a task on a thread, configure a thread, and pass data in both directions. We’ve also described how local variables are private to a thread and how references can be shared among threads, allowing them to communicate via common fields. The next step is synchronization: coordinating the actions of threads for a predictable outcome. Synchronization is particularly important when threads access the same data; it’s surprisingly easy to run aground in this area. Synchronization constructs can be divided into four categories: Simple blocking…

Read More

Use Sprite Sheets

So you’re a game developer? Then sprite sheets are one of your best friends. Sprite sheets make drawing faster and can even consume less memory than standard screen drawing methods. There are two awesome sprite sheet tutorials about sprite sheets on this site: How To Use Animations and Sprite Sheets in Cocos2D How to Create and Optimize Sprite Sheets in Cocos2D with Texture Packer and Pixel Formats The second tutorial covers pixel formats in detail, which can have a measurable impact on a game’s performance. If you’re not yet familar…

Read More