Thursday, November 29, 2012

How to read database connection string from web.config?

 System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

How to generate ASPX dynamically?

By Razor engine
http://razorengine.codeplex.com/

  string template = @"<%@ Control Language="C#" ClassName="@Model.Name" %>";
  string result = Razor.Parse(template, new { Name = "Classname" });

Wednesday, November 28, 2012

How to add dynamic field in OTRS?


1. Cretae dynamic field first
Admin->Ticket->Dynamic Field

2. Change configuration to make avaiblae in different view
Goto Admin -> SysConfig
search by ###DynamicField
Enable the dynamic field just created
There are a lot of setting for different views.

RavenDB and DataTables.Ne

http://antjanus.com/blog/web-development-tutorials/how-to-with-ravendb-and-datatables-net/

directory alt by brujo 1024x768 How To with RavenDB and DataTables.Net

Friday, November 23, 2012

ASP.NET web SQL Utility

http://www.codeproject.com/Articles/15408/Web-SQL-Utility

A nice and small tool to show the query result for MS SQL Server and Access database

Thursday, November 22, 2012

Make a Captcha Image Validation with Jquery and MVC

 http://www.codeproject.com/Tips/494536/Make-a-Captcha-Image-Validation-with-Jquery-and-MV

   <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            loadCaptcha();
        });
        function loadCaptcha() {
            $.ajax({
                type: 'GET', url: 'Home/generateCaptcha',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                success: function (data) { $("#m_imgCaptcha").attr('src', data); },
                error: function (data) { alert("Error while loading captcha image") }
            });
        }
    </script> 


public ActionResult generateCaptcha()
        {
            System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
            CaptchaImage img = new CaptchaImage(150, 50, family);
            string text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);
            img.SetText(text);
            img.GenerateImage();
            img.Image.Save(Server.MapPath("~") + this.Session.SessionID.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
            Session["captchaText"] = text;
            return Json(this.Session.SessionID.ToString() + ".png?t=" + DateTime.Now.Ticks, JsonRequestBehavior.AllowGet);
        } 

Wednesday, November 21, 2012

What is OTRS?

OTRS is an Open-source Ticket Request System, developed by Perl, default database is MySQL.
http://www.otrs.com

Following link is a group of tips for integrating OTRS into .Net project
http://rayaspnet.blogspot.ca/search/label/OTRS

Tuesday, November 20, 2012

How to call OTRS web service in C#?

There are two ways for calling web service to create/get/search ticket in OTRS:
First way: call RPC.pl
Second way: GenericInterface

Follwoing are the steps for RPC:
1. Setup SOAP user in OTRS:
Log in OTRS with FULL admin permission
Admin -> SysConfig -> Framework -> Core: SOAP
Add and enable SOAP user and password
2. In C# project, prepare SOAP request like following
Then make Webrequest for URL: http://localhost/otrs/RPC.pl

<?xml version=""1.0"" encoding=""utf-8""?>
  <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
soap:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
    <soap:Body>
      <Dispatch xmlns=""/Core"">
        <c-gensym4 xsi:type=""xsd:string"">soapUserName</c-gensym4>
        <c-gensym6 xsi:type=""xsd:string"">soapUserPassword</c-gensym6>
        <c-gensym8 xsi:type=""xsd:string"">TicketObject</c-gensym8>
        <c-gensym10 xsi:type=""xsd:string"">TicketSearch</c-gensym10>
        <c-gensym57 xsi:type=""xsd:string"">Limit</c-gensym57>
        <c-gensym59 xsi:type=""xsd:int"">10000</c-gensym59>
        <c-gensym8 xsi:type=""xsd:string"">Result</c-gensym8>
        <c-gensym10 xsi:type=""xsd:string"">ARRAY</c-gensym10>
        <c-gensym57 xsi:type=""xsd:string"">UserID</c-gensym57>
        <c-gensym59 xsi:type=""xsd:int"">1</c-gensym59>
      </Dispatch>
    </soap:Body>
  </soap:Envelope>
3. The result is in the XML format
If you meet problem, please give me an email, may I help a little bit. wangchiwei@gmail.com

How I went from $100-an-hour programming to $X0,000-a-week consulting.

https://training.kalzumeus.com/newsletters/archive/consulting_1

- Clients Pay For Value, Not For Time
- Charging Weekly: It Makes Everything Automatically Better
- Getting Clients: The Importance Of Social Proof
- Scaling A Consulting Business
- Hybridizing Consultancies With Product Businesses

Monday, November 19, 2012

Asynchronous partial views

http://blog.michaelckennedy.net/2012/11/13/improve-perceived-performance-of-asp-net-mvc-websites-with-async-partialviews/




Friday, November 16, 2012

The Eight Levels of Programmers

twisted-sister-i-wanna-rock-video-still-frame.jpg
http://www.codinghorror.com/blog/2009/04/the-eight-levels-of-programmers.html

Thursday, November 15, 2012

How to get current assembly version and build time?


        private static string GetAssemblyVersionBuildDate()

        {
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);

            return "v"+ System.Reflection.Assembly.GetCallingAssembly().GetName().Version.ToString() + " "+ dt.ToString();
        }

How to access session variables from anywhere in ASP.NET?


By full path like this:
System.Web.HttpContext.Current.Session["sessionVarName"];

How to remove local mapping in TFS?

How to remove local mapping in TFS?
1. In team exploerer, Open that folder
2. Go File -> Source Control -> Remove mapping (It is dynamic menu item)

Coexistence of projects between Visual Studio 2010 and 2012

http://weblogs.asp.net/sreejukg/archive/2012/10/17/coexistence-of-projects-between-visual-studio-2010-and-2012.aspx

clip_image001

Wednesday, November 14, 2012

How to parse html tag by HTML Agility pack?

 http://www.codeplex.com/htmlagilitypack
 
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(@"<html><body><p><table id=""foo""><tr><th>hello</th></tr><tr><td>world</td></tr></table></body></html>");
 
foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table")) {
    Console.WriteLine("Found: " + table.Id);
    foreach (HtmlNode row in table.SelectNodes("tr")) {
        Console.WriteLine("row");
        foreach (HtmlNode cell in row.SelectNodes("th|td")) {
            Console.WriteLine("cell: " + cell.InnerText);
        }
    }

CDN for jquery UI themes

http://stackoverflow.com/questions/1348559/are-there-hosted-jquery-ui-themes-anywhere



  • base: Google CDNMicrosoft CDN
  • black-tie: Google CDNMicrosoft CDN
  • blitzer: Google CDNMicrosoft CDN
  • cupertino: Google CDNMicrosoft CDN
  • dark-hive: Google CDNMicrosoft CDN
  • dot-luv: Google CDNMicrosoft CDN
  • eggplant: Google CDNMicrosoft CDN
  • excite-bike: Google CDNMicrosoft CDN
  • flick: Google CDNMicrosoft CDN
  • hot-sneaks: Google CDNMicrosoft CDN
  • humanity: Google CDNMicrosoft CDN
  • le-frog: Google CDNMicrosoft CDN
  • mint-choc: Google CDNMicrosoft CDN
  • overcast: Google CDNMicrosoft CDN
  • pepper-grinder: Google CDNMicrosoft CDN
  • redmond: Google CDNMicrosoft CDN
  • smoothness: Google CDNMicrosoft CDN
  • south-street: Google CDNMicrosoft CDN
  • start: Google CDNMicrosoft CDN
  • sunny: Google CDNMicrosoft CDN
  • swanky-purse: Google CDNMicrosoft CDN
  • trontastic: Google CDNMicrosoft CDN
  • ui-darkness: Google CDNMicrosoft CDN
  • ui-lightness: Google CDNMicrosoft CDN
  • vader: Google CDNMicrosoft CDN


  • How to solve problem, jQuery UI datepicker not working in IE9?

    http://rayaspnet.blogspot.ca/2011/12/how-to-avoid-quirks-mode-in-ie.html

    Put this line into the first place
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
    </head>


    or set this meta tag in IIS server into HTTP response headers.

    Reference:
    How to avoid compatibility view and quirk mode in IE?


    Synchronizing webpages across devices with SignalR

    http://lostechies.com/erichexter/2012/10/30/synchronizing-webpages-across-devices-home-automation/


    Tuesday, November 13, 2012

    ASP.NET SignalR

    http://weblogs.asp.net/davidfowler/archive/2012/11/11/microsoft-asp-net-signalr.aspx
    VsIntegration

    Monday, November 12, 2012

    How to set field value by reflection in C#?

                Class1 result1 = new Class1();
                FieldInfo[] fields = result1.GetType().GetFields(BindingFlags.Public| BindingFlags.Instance);
                foreach (var f in fields)
                {
                    f.SetValue(result1, Convert.ChangeType("1", f.FieldType));
                }

    How to Configure log4net with asp.net step by step

    http://ruchirac.blogspot.ca/2012/10/configure-log4net-with-aspnet-logging.html

    Wednesday, November 7, 2012

    How to solve error "The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF"?

    There are two ways to sovle the problem:
    1: Add this setting into config file?
    <configuration>
     <system.net>
      <settings>
       <httpWebRequest useUnsafeHeaderParsing="true" />
      </settings>
     </system.net>
    </configuration>

    2. Call following function first
            public static bool setAllowUnsafeHeaderParsing()
            {
                //Get the assembly that contains the internal class
                Assembly aNetAssembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
                if (aNetAssembly != null)
                {
                    //Use the assembly in order to get the internal type for the internal class
                    Type aSettingsType = aNetAssembly.GetType("System.Net.Configuration.SettingsSectionInternal");
                    if (aSettingsType != null)
                    {
                        //Use the internal static property to get an instance of the internal settings class.
                        //If the static instance isn't created allready the property will create it for us.
                        object anInstance = aSettingsType.InvokeMember("Section",
                          BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });
                        if (anInstance != null)
                        {
                            //Locate the private bool field that tells the framework is unsafe header parsing should be allowed or not
                            FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);
                            if (aUseUnsafeHeaderParsing != null)
                            {
                                aUseUnsafeHeaderParsing.SetValue(anInstance, true);
                                return true;
                            }
                        }
                    }
                }
                return false;
            }

    How to install SOAP::Lite module into OTRS on Windows IIS server?


    Run Perl\bin\ppm.bat as administrator
    Search SOAP and install it

    How to set up SOAP / Web service user for OTRS?

    - Login into your existing OTRS Installation as Admin
    - in the Menu under “Admin”->”Sysconfig” set Group to “Framework” and click “show”
    - In the list of subgroups click “Core::SOAP”
    - Check the boxes for SOAP::User: and SOAP::Password: and enter the values you like
    - click update

    http://www.iniy.org/?p=20

    Where is database connection setting in OTRS?

    Under folder:
    \OTRS\Kernel

    File name is config.pm

    Reference:
    http://doc.otrs.org/2.1/en/html/c1154.html

    How to get download file length by WebClient?

                byte[] buffer;
                var client = new WebClient();
                buffer = client.DownloadData("http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js");
                Stream strm = new MemoryStream(buffer);
                var fileLength = strm.Length;