Wednesday, March 28, 2012

Crystal Report + VS2010 (ASP.NET) -bobj is undefined

Below is the steps copied from this link.

1. You need to use Web Application Project,No Website Project because Web App will combine DLL to project also.
2. Copy C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319\crystalreportviewers13 (you'll got it when you install -CRforVS_redist_install_32bit_13_0.exe)   To your project such as  (ProjectName/crystalreportviewers13)
3. copy this below to your web.config
3.1
<configsections>
    <sectiongroup name="businessObjects">
      <sectiongroup name="crystalReports">
        </sectiongroup></sectiongroup></configsections>

<section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, 
CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, 
PublicKeyToken=692fbea5521e1304, Custom=null">
           <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler">
      
3.2
 <businessobjects>
      <crystalreports>
        <rptbuildprovider>
          <add embedrptinresource="true">
        </add></rptbuildprovider>
        <crystalreportviewer>
              <add key="ResourceUri" value="/crystalreportviewers13">
      </add></crystalreportviewer>
      <crystalreports>
    </businessobjects>
Note: in case "/crystalreportviewers13" is not working, try to add "~" symbol.

3.4 Publish your web application with FTP Mode to your any folder,and copy this publish to your web server then TEST it!

My Note:
Another issue with the CR runtime installer is that it always install the necessary web files (such as javascript, icons, etc) to "C:\inetpub\wwwroot\aspnet_client\system_web\2_0_50727". So, if you changed your default IIS web folder to somewhere else, please make sure that you copy "crystalreportviewers13" from the above mention folder to your new IIS web folder.

Reference:
http://social.msdn.microsoft.com/Forums/en-US/vscrystalreports/thread/ef56f72b-7ede-47d8-ba9e-9e63b9ac0203

Monday, March 26, 2012

WebBrowser control tweak

You may tweak the WebBrowser control in case it does not binding to the latest IE version (ie, different from the installed IE).

Below is the registry to be modify:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"contoso.exe"=dword:00002328

The values for 'contoso.exe':

9999 (0x270F) - Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 (0x2328) - Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
8888 (0x22B8) -Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
8000 (0x1F40) - Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
7000 (0x1B58) - Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.

References:

For discussion, see here:
http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control

For the MSDN reference, see here:
http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation

Thursday, March 8, 2012

Extension method - BETWEEN function

Well, on and off we need to increase the readability of the code and also reduce the typo mistake in the comparison symbols. Here is how you can achieve it:

        public static bool IsBetween(this int value,
            int i,
            int i2)
        {
            return ((value >= i)
                    && (value <= i2));
        }
Now, you may write this code for the integer data type:
        int i = 5;
        if (i.IsBetween(1, 12))
        {
           // the value is between 1 and 12
        }
        else
        {
           // the value is out of range.
        }

By using extension method, you may create IsBetween() method for each data type and also your own data classes.

Tuesday, January 17, 2012

Convert Bitmap to Icon

This is quite easy to achieve by using the following procedure:

        public static Icon ToIcon(Bitmap bmp)
        {
            IntPtr i = bmp.GetHicon();
            Icon ic = Icon.FromHandle(i);

            return ic;
        }

Monday, January 9, 2012

Linq IN operator

Sometimes, you might want to extract the "intersection" of the two object lists but the object types are different. For example, you have a customer list and another one is invoice list. You want to get the customers whose "customer_id" exist in the invoice list. This can be done in the SQL syntax easily by using the IN operator. But, there is none in the Linq. So, I have written my own extension:

public static List<T> In<T, T2>(this List<T> list1,
           List<T2> list2,
           Func<T, T2, bool> predicate)
        {
            List<T> result = new List<T>();

           // exit immediately if list2 is empty or null.
            if ((list2 == null)
                || (list2.Count == 0))
            {
                return result;     // return blank list.
            }

            foreach (var item in list1)
            {
                if (list2.Where(n => predicate(item, n)).Count() > 0)
                {
                    result.Add(item);
                }
            }

            return result;
        }

Wednesday, December 21, 2011

Precompile Web Application Project

If you have a website project, you have the option to precompile the website. So, the website startup (in IIS) will be responsive. But, for Web Application project, you don't have such precompile option and you will have to do it manually.

Steps to precompile your Web Application project:
  1. Publish your project by right click on the project name and choose Publish.
  2. Choose "File System" in the Publish Method and specify the location.
  3. Once the publishing has completed, run the "Visual Studio Command Prompt (2010)" from the Windows Startup menu.
  4. Then, type the following command and press Enter.
                    aspnet_compiler -p WebApp -v / WebAppPrecompile

The above command will precompile the "WebApp" locally without creating the Virtual Directory in the IIS.

Reference:
http://msdn.microsoft.com/en-us/library/ms227976%28v=VS.90%29.aspx

Monday, December 12, 2011

Embedding WebBrowser control in WinForm

This is not something new but very useful in embedding the WebBrowser control in WinForm:

http://notions.okuda.ca/2009/06/11/calling-javascript-in-a-webbrowser-control-from-c/

Pros:

  1. Multi-media mash up without much GDI calls - you can add nice images, sound and video in your WinForm without having to use GDI api to draw the nice effect.
  2. Able to utilize JQuery (or JavaScript) - this allows you to develop application that shares some of the library that you have developed between the WinForm and ASP.net.
  3. Able to do fancy menu without going through the WPF/Silverlight route - just use all the HTML and JavaScript that you have already learned.
  4. No more "can't built nice control" any more.

Cons:

  1. Over-used of the JavaScript and HTML in WinForm might create chaos. It increases the difficulties in debugging.
  2. You must posses HTML, JavaScript and C# skills. Of course, you must have the SQL skill as well.