Unable to create the store directory while using Excel.Package dll

I have a web component that using Excel.Package dll to generate excel sheet. When I deployed my system to a new windows server 2003; I start getting strange error which is “Unable to create the store directory” .. after spending good amount of time doing research and making sure the deployment was completed correctly, I figured out what is the issue.. it is basically the Excel.Package couldn’t create special file while saving data to excel file. To fix this, all what you need to do is 2 steps:

1. make sure you have the following folder: C:\Documents and Settings\Default User\Local Settings\Application Data\IsolatedStorage
2. make sure you have the proper Read/Write permission for your user on above path. It is important to make sure the permission is correct and it is not inherited from the parent directory. Thus you need to copy the permission from parent directory and adjust the permission to make sure the proper user have the needed Read/Write permission.

Doing above 2 steps fixed the issue that I faced and made things working fine.. I want to emphasis on making sure the directory have the correct permission to read/write and its permissions is not inherited from parent directory.

Manage System.Transaction timeout

When using System.Transaction in .net framework; you may came across a timeout problem where you code needs longer time to run than the default timeout duration for System.Transaction.. this is because the System.Transaction will be aborted after few seconds which will rollback your changes.. to make the timeout longer than the default timeout duration, you need to adjust your code to do this, there is no configuration on IIS/appconfig level to accomplish that. the following code sample showing how to accomplish this from code perspective

TimeSpan timeoutDuration = TimeSpan.FromSeconds(180);
using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, timeoutDuration))
{


Scope.Complete();
}

The timeout default value is 60 seconds; if you want to have an infinite timeout; just set it to be 0.

You need also to change values on machine.config in case you made the timeout value more than 10 minutes. Because the machine.config has a configurable value to limit TransactionManager’s timeout to be 10 minutes at max.

TransactionManager is setting on top of the transaction object; thus it has the upper hand on it if you exceed the 10 minutes limit. The problem with TransactionManager is you can’t change the timeout default value programmatically and you need to update the machine.config to accomplish this. To do so change the following tag value on machine.config

<configuration>
   <system.transactions>
        <machineSettings maxTimeout="00:30:00" />
   </system.transactions>
</configuration>

Use Windows Phone Personal Assistant (Cortana) Outside US

Microsoft recently push windows phone 8.1 updates to all windows 8.0 devices. The major feature of this update was to include an interactive personal assistant software; Cortana.. it is like Siri on IPhone an Google Now on Andriod devices.. Cortana is Beta release now and it is enabled only for US area.. the good news is you can still use cotana while you are a non-US resident by following few steps to adjust the regional settings on your device. to accomplish that you need to do the followings:

1. your phone language should be English (united State); to do so, go to Settings > Language and make sure the first item on the list to be English (United States). your phone may ask for restart; if so, please do restart for your phone.

2. your region should be United state. to do so; go to Settings > Region and make sure the region is US and regional format to be US… your phone might require a restart, if so, please do a restart for your phone.

3. the last step is to make sure that you set the Location Services to be ON; this will enable GPS on your phone Cortana will use it in order to accomplish your commands. To do that; go to Settings > Location and make sure it is set to ON.

 

after restarting your phone, you should see cortana on your App list. swap to the left and search for Cortana and you are there.. to start it; you can use the search button on your  mobile devise..

 

similar article: http://www.wpcentral.com/want-cortana-outside-us-heres-how

 

Responsive Web Design

Responsive web design is a web design approach that is aimed at crafting sites to provide an optimal viewing experience, easy reading and navigation with minimal efforts of resizing, panning, and scrolling – across wide range of devices including mobile, tablets and desktop devices. Mainly the Responsive web design position the page content in a fluid, proportion-based grids, flexible images, and CSS3 media queries, an extension of the @media rule.

Mobile and tablet devices adoption is rapidly grow all over the world; thus it is becoming more critical to have websites that looking good in those devises and make users feel comfortable while using your website on small screens as well as on large screens. Based on recent stats on the market, the sales for mobile and tablet devices overtake the sales for desktop devices which is making to have your website looking good on those devices essential for your organization success.

When you start thinking of having website that looks good on mobile and tablet devices , you will have 2 options;

  • Build a separated website for mobile devices and another one for desktop.
  • Using responsive design technique to have single website that works on both desktop and mobile devices.

Both options are valid and debatable… each of these options has its own pros and cons. Which one to adopt and go with depends on your business and what factors to consider. It is not the target

 

Google in general is recommending to go with Responsive web design approach… it will help you a lot in many areas.. For me, I hate code duplication. For the marketing guys they hate to duplicate the marketing content in many places.. Responsive web design will help on solving both problems and make those things centralized in one place and get rid of the headache of duplicated code/contents.

SOLID Object-Oriented-Design Principles

One of the main principles of OOD (Object Oriented Design) is SOLID principles. SOLID is stands for :

1. Single Responsibility Principle:

This means the class has to have one and only one reason to responsibility. This responsibility should be encapsulated by the class.

2. Open/closed principle:

The open/closed principle states that software entities (classes, modules, functions, …etc) should be open for extension, but not for (closed) modification

This will be very helpful on the production environment where fixing and enhancing certain area is required without affecting other areas. thus you will go with extending the class and its behaviors without modifying the current existing code/methods

3. Liskov substitution principle:

means Substitute-ability; It states that, if SubclassA is a sub-type of MainTypeA, then objects of type MainTypeA may be replaced with objects of type SubclassA without altering any of the properties of that program

4. Interface segregation principle:

The main goal from this point is to make the software more maintainable and loosely coupled; thus easier to re-factor and change. Basically, we need to split the large interfaces into smaller interfaces so that the client classes will be aware of the methods/properties they concern about

5. Dependency inversion principle:

It is about decoupling software layers and making sure the software is loosely coupled. Basically this principle states 2 things:

– High-level modules/layers should NOT depend on low-level modules/layers. communication between modules and layers should go through abstractions.

– Abstractions should NOT depend on details and the Details should depend on abstractions.

 

 

IIS 7 – How to Resolve Error HTTPs 413: Request Entity Too Large

couple of days ago, I came across an issue where when user leave the web page idle and try to upload a file using JQuery-FileUpload; user was getting error 413. and sometimes users were getting “The page was not displayed because the request entity is too large.” error.

I increased the uploadReadAheadSize  value on IIS and that was enough to fix the issue; I did the followings:

  1. Launch “Internet Information Services (IIS) Manager”
  2. Select the site that you are hosting your web application under it.
  3. In the Features section, double click “Configuration Editor”
  4. Under “Section” select: system.webServer  then serverRuntime
  5. Modify the “uploadReadAheadSize” section to be like 20MB (the value there is in Bytes)
  6. Click Apply

The error is happening as during renegotiation step between your web browser and the IIS Server; the entity should be preloaded using SSL. and result is being larger than the default value which is ~49K

GPG Encryption with a trust keys

before I start describing the issue, I want to give you a quick introduction about GPG and why we need to use it

GPG is one of the great tools/algorithms to do encryption and it is one of the commonly used algorithms to secure data and files. GPG allowing you to use public/private keys to encrypt/decrypt files on both Windows and Linux Operating Systems. Public key is used to encrypt files ONLY, and you can’t use it to Decrypt files; to be able to decrypt files, you need to have the private key pair to the public key used in encryption. if so, you will be able to decrypt the files.

How to generate keys and how to use them is outside the scope of this article; so I’ll not describe them here and I assume you are familiar with these commands.

the main issue that I faced while trying to encrypt files is getting the following prompt message:

“It is not certain that the key belong to the person named in the user ID. if you *really* know what you are doing, you may answer the next question with yes.

while you are doing encryption manually, it is easy to do YES. but when you are using this inside a background process that doesn’t work and you need to let the GPG tool do encryption silently. to do this you need to trust public key that you are using. it is easy thing to do; follow the below steps:

gpg – edit-key <KeyName>

GPG will output some information, and show a line like:
trust: undefined     validity: unknown

then you need to use trust command; type “trust”:
trust

GPG will output below message:

Please decide how far you trust this user to correctly verify other users’ keys
(by looking at passports, checking fingerprints from different sources, etc.)

1 = I don’t know or won’t say
2 = I do NOT trust
3 = I trust marginally
4 = I trust fully
5 = I trust ultimately
m = back to the main menu

Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y

and we are done.. you need to quit from the command by type q then hit enter.

Fix Installer issue – FIX IT

while I was developing windows service using visual studio 2010, I came a cross an issue that prevent me from continue working. I wasn’t able to uninstall or install my service any more.  I was using windows installation project within Visual Studio on windows 7 PC.

I tried so many things with no luck. I even tried to use the command prompt commands trying to uninstall/install the service; but nothing could solve the issue. till I found a tool from MS that could successfully scan and fix the problem for me. The tool took like 10 min scanning my machine; but at the end it fixed the issue for me. here is the link to the tool http://support.microsoft.com/mats/Program_Install_and_Uninstall

Please let me know if this tool fix the issue for you as well or not?

Value Injector – How to Use

One of the main tasks that you may face during development is how to translate from one object to another that is very similar in term of properties and attributes. There are many ready to use code to be downloaded from Internet and use.

I tried Value Injector DLL; it was good enough for my needs and it satisfy my needs in very good way. you can download the Value Injector DLL from this link.

The overall performance of this component was very good and it didn’t hit the performance of the system that I’m working on.

The Basic usage of this component is as follow.

using Omu.ValueInjecter;
public class DemoClass { 
 public void MethodInjector(mySourceClass source)
  {
   MyClass destination = new MyClass();
   destination.InjectFrom(source);
   //inject using your own injector calss.
   destination.InjectFrom < MyInjection > (source);
  }
}

The good thing about ValueInjector is that you can build your own Injector class and use it; that is needed if the current implementation for ValueInjector is not satisfying your needs.

for more information about value injector, please visit this link

Creating Required Literal for MVC with Razor rendering engine

In web applications, It is became a standard to have a symbol indicating if the field is required or not. This symbol maight be a star, icon or any verbiage that a client ma requested to have. It is a good practice to have the logic that render this symbol in one place and have all of your views using it. You can do that easily in standard ASPX pages, and it is the same on MVC using Razer rendering engine (cshtml/vbhtml). For MVC you need to create a custom HTML helper that do the job for you, and using it in your views cross the board. Below is a sample HTML helper method

 

public static MvcHtmlString RequiredFieldIcon(this HtmlHelper helper)
{
TagBuilder tag = new TagBuilder(“span”);
tag.AddCssClass(“color-color-text”);
tag.Attributes.Add(“title”, “Field is required”);
tag.SetInnerText(“>> “);
return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
}

In above method, the symbol is as simple as ‘>>’ in red color; using CSS class for that. it might be more complicated UI control and you can customize it based on your requirement. You can use this method just as if it is one of the out of the box HTML helpers that shipped with MVC; you just need to make sure you are including the namespace of the class that hosting this HTML helper method.

@Html.RequiredFieldIcon()