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

Enable GZIP Compression

A significant and growing number of apps rely on external data from remote servers or other external APIs. At some point you’ll be developing an app that downloads data in XML, JSON, HTML or some other text format. The problem is that the network condition cannot be relied upon when it comes to mobile devices. A user can be on an EDGE network one minute, and the a 3G network the next. Whatever the scenario, you don’t want to keep your user waiting! One option to reduce the file size…

Read More

Choose the Correct Collection

Learning to use the most appropriate class or object for the task at hand is fundamental to writing efficient code. This is especially true when dealing with collections. Happily, there’s a document named Collections Programming Topics on Apple’s Developer Library that explains in detail the differences between the available classes, as well as which situations suit each class. It’s a must read document for anyone looking to work with collections.TLDR? Here’s a quick synopsis of the most common collection types: Arrays: Ordered list of values. Quick lookup by index, slow…

Read More

Come reinizializzare, reimpostare o ripristinare il PC

Se hai problemi con il PC, puoi provare a reinizializzarlo, reimpostarlo o ripristinarlo. La reinizializzazione del PC comporta la reinstallazione di Windows mantenendo le tue impostazioni e i tuoi file personali, nonché le app fornite con il PC e le app installate da Windows Store. La reimpostazione del PC comporta la reinstallazione di Windows, con l’eliminazione di file, impostazioni e app, ad eccezione delle app fornite con il PC. Il ripristino del PC consente di annullare le modifiche apportate recentemente al sistema. Se vuoi eseguire il backup e il ripristino…

Read More

Use a reuseIdentifier Where Appropriate

A common mistake in app development is not setting the correct reuseIdentifier for UITableViewCells, for UICollectionViewCells, or even UITableViewHeaderFooterViews. For maximum performance, a table view’€™s data source should generally reuse UITableViewCell objects when it assigns cells to rows in tableView:cellForRowAtIndexPath:. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.What happens if you don’t use a reuseIdentifier? If you don’t, your table view will configure a brand-new cell each time a row is displayed. This is an expensive operation and will…

Read More

Xcode 5: general info

Xcode is the most used IDE for iOS development. Apple is doing a great job in updating and adding features to it. Knowing how to take advantage of its capabilities can help you code faster and more efficiently. Check out this Guide for Xcode 5 shortcuts, tips and tricks. Xcode’s workspace window is split into 5 main areas: the toolbar, the navigation area, the editing area, the debug area and the utility area: Navigating in Xcode The navigation area has a toolbar as well. It has 8 tabs: project navigator,…

Read More

Using report parameters in local mode

What are report parameters used for? The most common use of report parameters is to specify a criterion for subsetting data. The value of the parameter may be set programmatically by the host application, or one report may pass a parameter to another report. When you drillthrough from one report to another, the main report passes the id of the item the user clicked on to the drillthrough report as a report parameter. The drillthrough report then uses the parameter value to only display data corresponding to the item the…

Read More

TDD Kata | String Calculator

Kata is a Japanese word describing detailed choreographed patterns of movements practiced either solo or in pairs. most commonly known for the presence in the martial arts. The idea is if you practice something regularly, at some point it will be come natural. (As they call it “Muscle memory” :)). Even though Test Driven Development has been preached as best practice for years now, there is still resistance in many IT shops to adapt TDD (Test Driven Developer). So the best way to teach your team to start making TDD…

Read More

Building of an organizational chart for AdventureWorks & AdventureWorks2008

— SQL recursive CTE to find subordinates of executive, manager & supervisor– Tree processing – find all descendants – find children – self-referencing tableDECLARE @EmployeeID INT SET @EmployeeID = 109 USE AdventureWorks; WITH cteEmployeeName AS (SELECT FullName = FirstName + ‘ ‘ + LastName, EmployeeID FROM HumanResources.Employee e INNER JOIN Person.Contact c ON e.ContactID = c.ContactID), cteSubordinates AS (SELECT EmployeeID, LEVEL = 0 FROM HumanResources.Employee WHERE EmployeeID = @EmployeeID UNION ALL SELECT e.EmployeeID, LEVEL + 1 FROM cteSubordinates cte INNER JOIN HumanResources.Employee e ON cte.EmployeeID = e.ManagerID) SELECT FullName, s.EmployeeID,…

Read More