Test Run deployment issue: The location of the file or directory is not trusted… Error Message

Today I faced small problem while I am building Unit testing project to test my class library. in my class library I was using a DLL file located on a shared folder on my company’s network.. when I tried to run the test project I got this error message:
Test Run deployment issue: The location of the file or directory is not trusted

the solution of this issue was about adding the network path to my trusted sites.. to do so I followed the following steps:

1) open "Microsoft .NET Framework 2.0 Configuration" from administrative Tools
2) Go to "Runtime security Policy" –> Machine –> Code Groups –> All Code
3) right click –> New .. then give a name and description for the new group –> click Next
4) in the new form choose "URL" and then type your Network path. you can type it in 2 ways:

a) Y:\* –> for the whole folder
b) y:\AssemblyName.dll –> for single DLL

5) Choose Next… and then choose "Full trust"
6) click Next and then finished
7) finally close you VS and reopen it again
8) have fun in using unit testing 🙂

Thanks Microsoft for such a nice integration between tools:)

How to know the physical path of executing .Net assembly

In some cases you may come to a point where you want to know the physical path on your hard drive for the current assembly.. For example you might want to know the physical path of an Configuration XML file, which you already know that this file should be located on the same folder as the your assemblies. The following pecice of code show how u can know the path of your executing assembly

string executingAssemblyPath = “”;

FileInfo file = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);

executingAssemblyPath = file.DirectoryName;

Maximize MS CRM 4.0 pop-up Windows

Recently a customer asked me how to open the PhoneCall window(any window) form in a larger window.  It’s a simple matter of a little bit of JavaScript.

  • Navigate to the main Account form as follows:
    1. Go to Settings
    2. Choose Customization
    3. Choose Customize Entities
    4. Open PhoneCall Entity ( or any entity you want)
    5. Go to Forms and Views
    6. Open Form window
    7. Open the Form Properties window
    8. On the Events tab make sure that OnLoad is highlighted, then click Edit.  Paste the following Javascript code and make sure that the box for Event is enabled is checked.

//resize window to full screen upon opening Account form
window.moveTo(0,0);
window.resizeTo(screen.availWidth, screen.availHeight);

  • (Below is the screenshot of what this should look like.)
  • Save and close the form, then Publish the entity.

Script Window

How to Hide/Show fields on Advanced Find’s Search Criteria

One of my client requested to hide/Show some fields on MS CRM 4.0 (Microsoft CRM 4.0) Advanced Find search criteria. When this requirement came to me, I thought it is very hard to be implemented. In fact, this is a configuration issue and it is very easy to be implemented. all what you have to do is the followings:

  1. Go to customization area

  2. Open the entity that have those fields

  3. Go to Attributes on the left hand side

  4. Open the attribute (Field) you want to Hide/Show on the search criteria when you use Advance Find
    There is a field Called Searchable ; if you make it True, then you will be able to see this field on advance Find Search criteria, if you make it False, then you will not be able to see it.

  5. Save your changes.

  6. Publish customization

Audit MS CRM 4.0 Record Changes

It is common requirements to audit changes on certain entities on MS CRM 4.0. Unfortunately there is not built-in functionality to do so shipped out of the box. The best solution to solve this issue is to build a plug-in to take care of auditing changes. One of the challenges I faced is: How to implement this plug-in in generic away? So when my client ask me to audit a new entity, I will be ready for that with no Development effort.
The best solution I found to solve the issue is to build a generic entity to hold on your audited information. This entity should be generic enough to hold any kind of info you need…
I found a good plugin on internet and I used it.. It is pretty good to audit the chanag4es on CRM data. Please refer to the below link:
http://code.msdn.microsoft.com/auditing4crm

Decorator Design Pattern

Introduction:
Sometimes you want to add more responsibility to an object dynamically. Decorate Design Pattern provide us a flexible alternative to creating subclasses to extend this functionality. So you will not have to extend functionality by creating a child (Sub class) class.
Example:

DecoratorDesignPattern

class Program
{
static void Main()
{
Book b = new Book();
b.BookName = “Book Name”;
b.AutherName = “Auther Name”;
b.NumCopies = 10;
b.Display();
Movie v = new Movie();
v.VideoName = “Some Video name”;
v.VideoDirector = ” a Director”;
v.PlayTime = “1 hour”;
v.NumCopies = 10;
v.Display();
Console.WriteLine(“———————-“);
Console.WriteLine(“Borrow the book”);
BorrowLibraryItem borrow = new BorrowLibraryItem(b);
borrow.BorrowItem(“Yasser Jaber”);
borrow.BorrowItem(“Salah Jaber”);
borrow.Display();
Console.ReadKey();
}
}
abstract class LibraryItem
{
public int NumCopies{get;set;}
public abstract void Display();
}
class Book:LibraryItem
{
public string BookName { get; set; }
public string AutherName { get; set; }
public override void Display()
{
Console.WriteLine();
Console.WriteLine(“–> Book : “);
Console.WriteLine(” Author: {0}”, this.AutherName);
Console.WriteLine(” Book Name: {0}”, this.BookName);
Console.WriteLine(” Number of Copies: {0}”, base.NumCopies);
}
}
class Movie: LibraryItem
{
public string VideoDirector { get; set; }
public string VideoName { get; set; }
public string PlayTime { get; set; }
public override void Display()
{
Console.WriteLine( );
Console.WriteLine(“–>Movie : “);
Console.WriteLine(” Director: {0}”, VideoDirector);
Console.WriteLine(” Name: {0}”, VideoName);
Console.WriteLine(” Number of Copies: {0}”, NumCopies);
Console.WriteLine(” Playtime: {0}”, PlayTime);
}
}
class BorrowLibraryItem
{
protected List<string> borrowers = new List<string>();
protected LibraryItem item;
public BorrowLibraryItem(LibraryItem item)
{
this.item = item;
}
public void BorrowItem(string borrowerName)
{
borrowers.Add(borrowerName);
item.NumCopies–;
}
public void ReturnItem(string borrowerName)
{
borrowers.Remove(borrowerName);
item.NumCopies++;
}
public void Display()
{
item.Display();
Console.WriteLine();
Console.WriteLine(“Borrowers:”);
for (int i = 1; i <= borrowers.Count; i++)
{
Console.WriteLine(i.ToString() + “. ” + borrowers[i – 1]);
}
}
}

 

Download Code

Strategy Design Pattern

Introduction:
Sometimes you want your object to behave differently if its internal status changed. The strategy Design pattern enables client code to choose which behavior from a family of behaviors and give client code a simple way to enable that behavior.
Example:

Strategy

 

interface ISortStrategy
{
string Sort();
}

public string Sort()
{
return “0 1 2 3 4 5 6 7 8 9 “; //Simulate sorting algorithm
}

public string Sort()
{
return “9 8 7 6 5 4 3 2 1 0”; //Simulate sorting algorithm
}

class DataList
{
public ISortStrategy strategy;
public DataList(ISortStrategy strategy)
{
this.strategy = strategy;
}
public string GetSortedList()
{
return strategy.Sort();
}
}
static void Main()
{
DataList data = new DataList(new SortAcsStrategy());
Console.WriteLine(data.GetSortedList());
data.strategy = new SortDescStrategy();
Console.WriteLine(data.GetSortedList());
Console.ReadKey();
}

 

Download Code

Develop .Net 1.1 Web Application on windows Vista (IIS 7)

To develop Web application using .Net 1.1 and Visual Studio 2003 on Vista OS (IIS 7), follow the below steps:

  •   First of all you have to install Visual Studio 2003. this will install .Net 1.1 also

  •   Install all service packs for .Net framwork 1.1.

  •   Open the IIS Manager and navigate to the server root. (Not a website root, above that – the machine name.) and double click on "ISAPI and CGI restrictions."

  •   Add the v1.1 aspnet_isapi.dll to "Allowed" restrictions

                  (it’ll be at %WinDir%\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll)

  •   Navigate to the website root in IIS manager and double-click "ISAPI Filters."

  •   Add the ASP.NET 1.1 ISAPI filter from %WinDir%\Microsoft.NET\Framework\v1.1.4322\aspnet_filter.dll

  •   Go to the website root again in IIS manager and loo at "Advanced Settings."

  •   Ensure the website is using an ASP.NET 1.1 Application Pool (Vista created one for me when I installed .NET 1.1 – you may need to create one yourself.)

    Done.. Now you can develop and debug .Net 1.1 Web Applications on Vista OS and IIS 7.0

    Autocomplete (IntelliSense) While Writing SQL Statements; How Nice is SQL Prompt

    As a .Net developer who using Visual Studio from early morning till late evening, I like the way MS designed the IntelliSense feature there. and I was so disappointed because there is no such a feature while you are using SQL Server Management Studio.

    In version 2008 of SQL server Management Studio, MS solved the IntelliSense issue there but that was specifically if you are connecting to SQL Server 2008 backend engine.But I still need to use this feature while I am using SQL server 2000 and 2005 SQL server engines.

    I found a very good software from Red-Gate called SQL Prompt, this software is doing a very nice job for me and solved all of my issues related to IntelliSense.

    I have been using this software for 3 years till the moment I am writing this article, and I am still believe on it and if I start writing SQL statement without using it, I feel my life like a hell.

    For me the IntelliSense feature of  SQL Prompt is much better than the one that MS developed on SQL server 2008. and Red-Gate is keeping enhancing it and making it much better everyday.

    Code snap it on SQL prompt is amazing and saving my time a lot. You can define a keyword and its related SQL statements, once you type this keyword and then tab out, SQL Prompt will place the related SQL statements for you. For example, if you type “ssf” and tab out, SQL prompt will replace it by “SELECT * FROM “

    As a conclusion, I would strongly recommend to you to use it during your daily development day.