Open a web page in outlook through Add-Ins

March 30, 2010 Leave a comment

The following code snippet shows how to open a web site (webpage)  inside Microsoft Outlook using Office Development with Visual Studio (VSTO). This code is tested using Outlook 2003.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Office.CommandBarComboBox control = (Office.CommandBarComboBox) this.Application.ActiveExplorer().CommandBars.FindControl(26,1740, missing, missing);
control.Text = "www.msn.com";
}

More references about VSTO and Outlook:

Advertisements

Font size problem in exporting Crystal Report to PDF using ASP.Net

March 25, 2010 1 comment

http://forums.asp.net/t/1212106.aspx

I noticed a font size problem in exporting Crystal Report using Crystal 11.5 and ASP.Net 3.5.  In this case I needed to export a Crystal Report contains some barcodes.  The barcodes in the exported PDF had a very small font size. Searching web, I found that this issue can be fixed using to registry keys:

SAP Knowledge Base Article:

To resolve the behavior

  1. Set the resolution of the default printer of the local computer experiencing the issue to 1200 DPI. Most printers have a default setting of 600 DPI.
  2. Create two registry keys to prevent the crxf_pdf.dll from decreasing in font size.
  3. Click StartRun. Type “regedit”. The Registry Editor appears.
  4. Create the following keys for Crystal Reports XI with the defined values:HKEY_CURRENT_USER\Software\Business Objects\Suite 11.0\Crystal Reports\Export\PDF\ForceLargerFonts
    Type: DWORD
    Recognized Values: 0,1
    Default Value: 1
    Creation Method: manual

    HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 11.0\Crystal Reports\Export\PDF\ForceLargerFonts
    Type: DWORD
    Recognized Values: 0,1
    Default Value: 1
    Creation Method: manual

  5. Set both registry key values to 1 to turn them on.
  6. Create the following keys for Crystal Reports XI Release 2 with the defined values:HKEY_CURRENT_USER\Software\Business Objects\Suite 11.5\Crystal Reports\Export\PDF\ForceLargerFonts
    Type: DWORD
    Recognized Values: 0,1
    Default Value: 1
    Creation Method: manual

    HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 11.5\Crystal Reports\Export\PDF\ForceLargerFonts
    Type: DWORD
    Recognized Values: 0,1
    Default Value: 1
    Creation Method: manual

  7. Set both registry key values to 1 to turn them on.
  8. Restart the Crystal Reports Page, Job and Cache Servers

and for the Unix server:

UNIX, an X server client such as x-win32 must be installed. Add the keys as follows:

  1. Launch the X server client (alternatively use xming on the client machine and export the display to the client machine.
  2. Login as business Objects user
  3. Go to the business objects installation folder: cd  <bobje install>/bobje/setup/
  4. Sorce env.sh (for example: . ./env.sh).
  5. Type regedit
  6. Create the registry keys as detailed below.
    1. Create the following keys for Crystal Reports XI Release 2 with the defined values:
    2. Create a new key under ‘HKEY_CURRENT_USER\Software\Business Objects\Suite 11.5\Crystal Reports’ called ‘Export’
    3. Create a new key under ‘HKEY_CURRENT_USER\Software\Business Objects\Suite 11.5\Crystal Reports\Export’ called ‘PDF’
    4. Create a new Dword value called ‘ForceLargerFonts’ under ‘HKEY_CURRENT_USER\Software\Business Objects\Suite 11.5\Crystal Reports\Export\PDF’
    5. Set the value to 1 (just double click on the name you just created)
    6. Create a new key under ‘HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 11.5\Crystal Reports’ called ‘Export’
    7. Create a new key under ‘HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 11.5\Crystal Reports\Export’ called ‘PDF’
    8. Create a new Dword value called ‘ForceLargerFonts’ under ‘HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 11.5\Crystal Reports\Export’
    9. Set the value to 1 (just double click on the name you just created).
  7. Restart the Crystal Reports Page, Job and Cache Servers.

I followed the provided instruction in SAP knowledge base but it did not work for me. I set the registry at HKEY_LOCAL_MACHINE which I expected to affect IIS, and then I set the HKEY_CURRENT_USER registry (which to me is not relevant as IIS uses different profile), then restarted the web server. The result was still barcode printing in small font.

Further search on the web I found a new solution in SAP community forum: https://forums.sdn.sap.com/thread.jspa?threadID=1161804

1. Press Ctrl-Alt-Del on your keyboard, then click the Task Manager button. Click the Processes tab. The security account is listed beside your process name (for IIS 5 the process name is aspnet_wp.exe and for IIS 6 it is w3wp.exe).

2. Open the registry editor. On the Start menu, click Run then type “regedit” and click OK.

3. Navigate to the following registry sub key:

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

There will be a number of keys here that start with “S-1-5”. Inspect each one and look for your security account name in the ProfileImagePath entry. Take note of the key (folder) you are on when you find your process.

4. Go to the following registry sub key:

HKEY_USERS[your security profile]\Software\Crystal Decisions\10.2\Crystal Reports\Export\Pdf

5. Right-click the sub key and click New > DWORD Value. Name the DWORD value “ForceLargerFonts” and set it to the value of 1.

6. Restart IIS, and try the application again.

My experience:

The IIS running on a XP machine where the Process Name (Image Name) equals to aspnet_wp.exe and the User Name equals to  ASPNET.   Looked at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList and found that  S-1-5-21-1085031214-562591055-839522115-1004 has the value of

Value Name: ProfileImagePath

Value data: %SystemDrive%\Documents and Settings\TESTXP17908\ASPNET

Next step: I added ForceLargerFonts value to HKEY_USERS\S-1-5-21-1085031214-562591055-839522115-1004\Software\Business Objects\Suite 11.5\Crystal Reports\Export\PDF.

Restarted IIS

Result: Problem solved :)

Other web links and references:

How to create a lookup window in Silverlight

I am looking for a nice way to create a lookup window in Silverlight. What is needed, is a Control Library + a Modal Window + a back end service to perform the query on the database and return the results.

The target is the Silverlight 4 which at this time (4 March 2010) is in Beta version.

1. Control Library:  I could not find any project template for Silverlight Control Library in Visual Studio 2010 but there is a Silverlight Control Library project template for Expression Blend .Net4.  So that is the way to go.

2. Modal Window:  Silverlight 3 (and 4) includes a cool item template called Silverlight Child Window which is a modal window. It is very easy to use:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      ChildWindow1 dialog = new ChildWindow1();
      dialog.Show();
    }

The following article gives a nice walk-through on how to create a modal dialogue using Silverlight Child Window:

http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/29/silverlight-3-s-new-child-windows.aspx

3. Back end service:  This can be done using a WCF service, but there is a simpler solution. Using the WCF RIA Services helps to simplified the details around creating a WCF service. For the purpose of our look up we need a service library which provides us a single service to return the data as a IQuerable so it can be bind to the grid and the paging and sorting will be managed automatically. The following article is a walkthrough on Creating a RIA Services Class Library.

http://msdn.microsoft.com/en-us/library/ee707351(VS.91).aspx

Using ResourceDictionary in Silverlight

February 16, 2010 Leave a comment

One of the new useful features of Silverlight 3 is the ResourceDictionary. The following is the list of useful links about ResourceDictionary:

  1. Resource Dictionary in Silverlight 3 Using Blend 3
  2. What’s New In Silverlight 3 – Merged Resources
  3. Use a ResourceDictionay and an external resources located in an assembly
  4. Error using ResourceDictionary in Silverlight
Categories: Silverlight Tags:

Stop auto closing after ipconfig command

January 28, 2010 Leave a comment

Some minor things can be annoying if you do not know the trick to do it in an easy way. One of them is getting the system IP address using ipconfig, or  executing other Windows commands directly from the Start -> Run. The problem is that the command prompt window will close automatically after execution of the command. So to avoid closing the windows automatically you have two options:

  1. Go to Start -> Run
  2. Type cmd and hit enter.
  3. Type the command (e.g ipconfig) in the opened window.

alternatively you can

  1. Go to Start -> Run
  2. Type cmd /K command and hit enter. (e.g cmd /k ipconfig)

CMD /K will stop the command window from closing after the command.

Categories: IT Support

Microsoft Prism

December 14, 2009 Leave a comment

I just learned about Prism as a way for developing composite applications using WPF.

Prism as a guideline:

This guidance will help you design and build flexible client applications using loosely coupled, independently evolvable pieces that work together and are integrated into the overall application. This type of application is known as a composite application.

Ref: http://msdn.microsoft.com/en-us/library/dd458941.aspx

To answer the question why using Prism, refer to http://msdn.microsoft.com/en-us/library/dd490815.aspx

Composite applications provide many benefits, including the following:

  • They allow modules to be individually developed, tested, and deployed by different individuals or sub-teams…
  • They provide a common shell composed of UI components contributed from various modules that interact in a loosely coupled way…
  • They promote re-use and a clean separation of concerns between the application’s horizontal capabilities…
  • They help maintain a separation of roles by allowing different individuals or sub-teams to focus on a specific task or piece of functionality according to their focus or expertise…

Other resources:

Categories: Silverlight, WPF

Entity Framework assications (Independent vs FK)

November 8, 2009 Leave a comment

Entity Framework association is a different concept to FKs in the database schema.  Supporting or not supporting the Schema FKs has been a topic for debate in the community until now. Faisal Mohamood (Program Manager of Entity Framework) believes in the following prons and cons of using FKs in a model (Ref 1):

Benefits of Foreign Keys

  1. Keeps it simple (for the simple cases)  and allows you to deal with relationship like you deal with them in the database
  2. Technically, you can update relationships without having both ends loaded/materialized. This is however in reality not always interesting since you will likely load both ends but this feature is definitely useful.

Disadvantages of Foreign Keys in the Model

  1. It is a part of the impedance mismatch problem.
  2. It doesn’t allow the concepts that you would expect from relationships in objects (easily getting from one end to the other) for instance.
  3. Having foreign keys as well as object references for relationship navigation presents the problem of two different artifacts representing relationships – this introduces complexity and now you have to make sure that you keep these two in sync.

I think the biggest disadvantage of FKs (stated in number 2) is the conflict with the object model pattern.

However, it seems that Microsoft decided that both sides of this discussion have their valid points. So in Entity Framework .Net 4, Fks are supported and it is up to the software architects to make their decision to just use  independent associations (.Net 3.5 SP1) or add the FKs to the model.

The following code snippets form ADO.Net blog illustrate the implication of using Fks as part of the model (Ref 2). In our model there are two entities Product and Category, with the association one to many where each Product belongs to one Category.

First:  Using the independent association between Product and Category.

public void Create_new_Product_in_existing_Category_by_reference()
{
    using (var context = new Context())
    {
        //Create a new product and relate to an existing category
        Product p = new Product
        {
            ID = 1,
            Name = "Bovril",
            Category = context.Categories
                        .Single(c => c.Name == "Food")
        };
        // Note: no need to add the product, because relating
        // to an existing category does that automatically.
        // Also notice the use of the Single() query operator
        // this is new to EF in .NET 4.0 too.
        context.SaveChanges();
    }
}

Second: Using the Foreign Key.

using (var context = new Context())
{
    //Create a product and a relationship to a known category by ID
    Product p = new Product
    {
        ID = 1,
        Name = "Bovril",
        CategoryID = 13
    };
    //Add the product (and create the relationship by FK value)
    context.Products.AddObject(p);
    context.SaveChanges();
}

Further Reading:

References:

  1. [blogs.msdn.com/EFDesign]Foreign Keys in the Conceptual and Object Models
  2. [blogs.msdn.com/EFDesign]Foreign Keys in the Entity Framework
Categories: Entity Framework, LINQ