Sunday, December 30, 2012

Simple Exif Viewer using C++ and Exiv2

Exif or Exchangeable image file format is a variation of JPEG, used by almost all digital cameras to record extra interchange information to image files as they are taken. Camera settings and scene information are recorded by the camera into the image file. Examples of stored information are shutter speed, date and time a photo was taken, focal length, exposure compensation, metering pattern and if a flash was used.

I have build a simple Exif Viewer using Exiv2 and C++ (I have wrote about Exiv2 in a previous post). Since Exiv2 supports command line, from my application I am invoking the Exiv2 commands through the command line and getting the output back to my application. The one of the nicest things in Exiv2 is, it has the capability to read set of commands from a text file and execute those commands on the command line.
Simple Exif Viewer
You can download the source and expand the application using various features Exiv2 supports.

Happy Coding.


Friday, December 21, 2012

Building and Installing Exiv2 on Visual Studio 2010

Exiv2 is a C++ library and a command line utility to manage image metadata. It provides fast and easy read and write access to the Exif (Exchangeable image file format), IPTC and XMP metadata of images in various formats. Exiv2 is available as free software and with a commercial license, and is used in many projects.

I have spent more than 2 hours to build this library on Visual Studio 2010. So I think it's better if I wrote the steps that I have followed to build the libraries.

Exiv2 has two main dependencies. One is expat and the other is zlib. The important thing here is finding the suitable versions of these two dependencies. To successfully compile Exiv2 we need following versions of expat and zlib.
  • First create a folder in any place you like. I have created a folder named “gnu” in “C:\” drive.
  • Put all three folders which you got from extracting and put them inside the folder “gnu”.
My Folder : "C:\gnu"
  • Open the “expat.dsw” inside the folder “expat-2.0.1”. Visual Studio 2010 will convert everything to latest project files and say "Yes" to everything.
  • Go to Batch Build and select the following and Build. Please note that if you try to build the whole solution you will get many errors. So you should only build the following.
    • expat-Debug
    • expat-Release
    • expat_static-Debug
    • expat_static-Release
Batch Build
Batch Build Selection
  • Open the “zlib.dsw” inside the folder “zlib-1.2.3\projects\visualc6”. Again Visual Studio 2010 will convert everything to latest project files and say "Yes" to everything.
  • Go to Batch Build and select the following and Build. Please note that if you try to build the whole solution you will get many errors. So you should only build the following.
    • zlib-DLL Debug
    • zlib-DLL Release
    • zlib-LIB Debug
    • zlib-LIB Release
Batch Build Selection
  • Now open the “exiv2.sln” inside the folder “exiv2\msvc”. Again Visual Studio 2010 will convert everything to latest project files and say "Yes" to everything. when Visual Studio has completed converting, select the project “exiv2lib”. Right click on it and select properties.
exiv2lib Properties
exiv2lib Properties -> General
  • Only for this project, target name should changed as follows.
    • Debug           - exiv2sd
    • DebugDLL    - exiv2d
    • Release         - exiv2s
    • ReleaseDLL  - exiv2
Debug -> exiv2sd
DebugDLL -> exiv2d
Release -> exiv2s
ReleaseDLL -> exiv2
  • Now you can build the project without any errors.
I have uploaded all the needed files to my skydrive and you can download it from there.

Happy Coding.


Monday, December 17, 2012

ASP.NET Web Site in Windows 8 Metro Style

Have you ever wanted to create an ASP.NET web site in Windows 8 Metro Style? But you might already know that, to get started writing Metro style apps you need Windows 8 and Visual Studio 2012.

If you want to create Metro style using Visual Studio 2010, you will have to use third party libraries. I  have came across such a solution which is Metro UI CSS. Metro UI CSS a set of styles to create a site with an interface similar to Windows 8 Metro UI. This set of styles was developed as a self-contained solution. I have already tested it out and it’s really amazing.

Sample Metro Style Web App
I have created a sample web application, you can download and see for yourself the beauty of these css files.

Happy Coding.


Friday, December 7, 2012

Presentation : Windows Communication Foundation (Part 2)

Continued my previous session at iOM World about Windows Communication Foundation (WCF) and today we spent some time learning how to create WCF services and how to configure the endpoints with different bindings etc.

I have uploaded the slide deck and demo source code to my SkyDrive. Do check it out.

Happy Coding.


Tuesday, December 4, 2012

Forms Authentication with MS Access Database

I recently had a requirement to provide Forms Authentication to a web application which has a Microsoft Access database. If you are thinking that Forms authentication only supports with Microsoft SQL Server databases, No it’s not. ASP.NET supports variety of custom Membership and Roles providers including,
  • SQL Database Support for ASP.NET Membership, Roles and Personalization
  • Access Database Support for ASP.NET Membership, Roles and Personalization
  • MySQL Support for ASP.NET Membership and Roles
  • SQLLite3 Support for ASP.NET Membership and Roles
  • Oracle Support for ASP.NET Membership, Roles and Personalization
Today I am going to show you how to configure Forms Authentication with Microsoft Access. If you have used Forms Authentication with Microsoft SQL Server, you know that we run following command to create “aspnetdb” database in the SQL Server first.

Create aspnetdb in SQL Server
But since here we are using MS Access database, we should have some kind of a access database similar to “aspnetdb”. So for that Microsft has provided us a MS Access .mdb file and some set of classes to implement Forms Authentication with the provided MS Access database file. So let’s see how this works. (I am hoping to upload a sample project to SkyDrive, so you can get all the database files and class files.)

First I will create a new web application and I will add a new class library to the solution.

Solution Explorer : Add Class Library Project
In the class library I will add a folder called “AccessProviders” and I will add the Microsoft provided class files to that folder. Then I am building “MyAccessProvides” class library and to compile I need to add following references to the class library project.
  • System.Web
  • System.Web.ApplicationServices
  • System.configuration
Solution Explorer : AccessProviders
Now I am moving to my Web Application project and in that project I am adding a reference to my class library project. Then to the “App_Data” folder, I am adding the MS Access .mdb file.

Add Project Reference
Solution Explorer : App_Data Folder
Then I am modifying the web.config file as follows.

I am adding new a connection string which will point to the Access .mdb file.
  <add name="AccessFileName" connectionString="~/App_Data/ASPNetDB.mdb" providerName="System.Data.OleDb"/>

Then I am further modifying the web.config file as follows.
<membership defaultProvider="AccessMembershipProvider" >
    <add name="AccessMembershipProvider"
        connectionStringName="AccessFileName" requiresQuestionAndAnswer="false"/>

<profile enabled="true" defaultProvider="AccessProfileProvider">
    <add name="AccessProfileProvider" type="MyAccessProviders.AccessProviders.AccessProfileProvider,MyAccessProviders"
        connectionStringName="AccessFileName" />

<roleManager enabled="true" defaultProvider="AccessRoleProvider">
    <add name="AccessRoleProvider"
        connectionStringName="AccessFileName" />

Now that’s it. A can create a new account and I can see it in the “ASPNetDB.mdb”.

Create New Account
Logged In
User created in the database
I have uploaded a sample of all the class files and the database to SkyDrive. Do check it out and hope this helps.
     Download the Sample

Happy Coding.


Monday, December 3, 2012

SharePoint 2010 : How to Create a Custom List Definition and a Instance

I will start by creating an Empty SharePoint project and I am going to deploy it as a Farm solution.
Empty SharePoint Project
Trust Level - Farm Solution
Then I am adding a SharePoint Mapped Folder to Images and I am adding a image to use as Feature Image Url.
SharePoint "Images" Mapped Folder
SharePoint "Images" Mapped Folder created
Then I am right clicking on my Project and add a new item which is a “List Definition”.
Add List Definition
Now I am setting the Display name of my list definition and setting up the list type as a “Custom List”.
List Display Name & Type

A Feature will be created in addition to my list definition. I am double clicking on the feature and in the properties I am setting up the Image Url.
Feature Image Url

Now I am modifying the Schema.xml file in the list definition. I am adding fields which should be included in my list.

        <Field Name="EmpId" DisplayName="Employee Id" Type="Text"></Field>
        <Field Name="EmpName" DisplayName="Employee Name" Type="Text"></Field>

Since I have created an instance of my list, I am going to put some default values. I am modifying the Elements.xml of the instance.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <ListInstance Title="MySharePointProject - MyListInstance"
                Description="My List Instance">
                  <Field Name="EmpId">1</Field>
                  <Field Name="EmpName">Jaliya Udagedara</Field>

                  <Field Name="EmpId">2</Field>
                  <Field Name="EmpName">John Doe</Field>

                  <Field Name="EmpId">3</Field>
                  <Field Name="EmpName">Jane Doe</Field>

Now I am deploying the solution and once it is activated, I can see my List definition is available.
Create New List

And I can see a quick launch item is created.
Created List Instance

I am getting the default view of the list instance. But as you can see the two fields I have added is not displaying here. So I am again modifying the Schema.xml file in the list definition as follows. I am deploying the solution again and now the fields are displaying.

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
    <Toolbar Type="Standard" />
    <XslLink Default="TRUE">main.xsl</XslLink>
    <RowLimit Paged="TRUE">30</RowLimit>
      <FieldRef Name="Attachments"></FieldRef>
      <FieldRef Name="LinkTitle"></FieldRef> <!--if you don’t want to see title, comment this line-->
      <FieldRef Name="EmpId"></FieldRef>
      <FieldRef Name="EmpName"></FieldRef>
        <FieldRef Name="ID"></FieldRef>
      <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
      <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />

Created List Instance
Now when I click on Add new item, only Title field is displayed and not my created fields.
Created List Instance
For that, I am commenting the following part in the Schema.xml file in the list definition as follows.

      <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      <ContentTypeRef ID="0x0120" />

Now I can see the fully completed output.
Created List Instance
Happy Coding.