Wednesday, April 29, 2015

C# Default Values of Types

This was not something I was aware of for many years, mostly because I would think it bad programming practice to not give instantiated objects a value.

But seems that is considered ok now, at least with C#.  Witness the extension methods in LINQ that specify "OrDefault".

Default Values Table (C# Reference)



The following table shows the default values of value types returned by the default constructors. Default constructors are invoked by using the new operator, as follows:
int myInt = new int();
The preceding statement has the same effect as the following statement:
int myInt = 0;
Remember that using uninitialized variables in C# is not allowed.
Value type
Default value
false
0
'\0'
0.0M
0.0D
The value produced by the expression (E)0, where E is the enum identifier.
0.0F
0
0L
0
0
The value produced by setting all value-type fields to their default values and all reference-type fields to null.
0
0
0

LINQ simple example, and diff between QUERY and METHOD syntax




           // 1. Pre-LINQ way of doing it:
            // *******************************************

            foreach (var c in customerList)
            {
                if (c.CustomerId == customerId)
                {
                    foundCustomer = c;
                    break;
                }
            }


            // 2. LINQ using Query Syntax:
            //*******************************************
         
         var query = from c in customerList
                        where c.CustomerId == customerId
                        select c;

            foundCustomer = query.First();




            // 3. LINQ using METHOD Syntax:
            //*******************************************

            foundCustomer = customerList.First(c =>
                c.CustomerId == customerId);

     



Thank you, Deborah Kurata!

Sunday, April 26, 2015

Using jQuery for Autocomplete Textboxes

$(function () {




};


var createAutoComplete = function(){
          var $input = $(this);
         
          var options = {
                    source: $input.attr("thingsToUseForAutocomplete")
          };
          $input.autocomplete(options);
};

//wireup elements of DOM

$("input[thingsToUseForAutocomplete].each(createAutoComplete);

Friday, April 24, 2015

How to move your Visual Studio .NET Web project ( Web Site™ ) to another computer

How To Determine If the Solution Was Created/Saved As an Application vs. Web Site™ :
- in sln file, look for:
look for this line in sln fileindicates

ProjectSection(SolutionItems)
Application

ProjectSection(WebsiteProperties)
Web Site™


How to move your Visual Studio .NET Web project ( Web Site™ )  to another computer

https://support.microsoft.com/en-us/kb/326495


This step-by-step article describes how to create a Visual Studio .NET Web Project on one computer, and then move the project to second computer and open the project on the second computer.


Requirements

  • Microsoft Windows 2000 or Windows XP Professional
  • Microsoft .NET Framework
  • Microsoft Internet Information Services (IIS)
  • Microsoft Visual Studio .NET
Note This environment is required on both the source computer and the target computer.


Create an ASP.NET Web application on the source computer by using Visual C# .NET

To create a new ASP.NET Web Application project named WebAplication1 by using Microsoft Visual C# .NET, follow these steps:
  1. Open Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, under Project Types, click Visual C# Projects. Under Templates, click ASP.NET Web Application.
  4. In the Location text box, type WebAplication1. If you are using the local server, you can leave the server name ashttp://localhost so that the Location text box is set to http://localhost/WebAplication1.
  5. From the ToolBox, drag a TextBox control to WebForm1.aspx.

Create project folders on the target computer

  1. Create the project folder.
    To do this, follow these steps:
    1. Create the WebApplication1 folder at C:\Inetpub\wwwroot\ of the target computer.
    2. Share the C:\Inetpub\wwwroot\ folder. Give Full Control permissions to the Authenticated users.

      For more information about how to share the files and folders, click the following article number to view the article in the Microsoft Knowledge Base:
      301281 How to share files and folders over a network for workgroups in Windows 2000
  2. Create the virtual directory.
    To do this, follow these steps:
    1. Click Start, point to Settings, and then click Control Panel.
    2. Double-click Administrative Tools, and then double-click Internet Services Manager. Or, if you run Microsoft Windows XP on your computer, open Internet Information Services.
    3. Expand the server name.
    4. In the left pane, right-click Default Web Site, point to New, and then click Virtual Directory.
    5. On the Virtual Directory Creation Wizard screen, click Next to continue.
    6. On the Virtual Directory Alias screen , type an alias or name for the virtual directory (such as WebSpplication1), and then click Next.
    7. On the Web Site Content Directory screen, click Browse. Locate the content folder that you created to hold the content (c:\Inetpub\wwwroot\WebApplication1).
    8. Click Next to continue.
    9. On the Access Permissions screen, click to select the check boxes for ReadRun scripts (such as ASP), andBrowse.
    10. Click Finish.
  3. Create the solution folder.
    To do this, create the solution folder WebApplication1 for .sln file in Visual Studio Projects. This is located atC:\Documents and Settings\UserName\My Documents\Visual Studio Projects\.

    Note UserName is the user name to log on to the computer.

Copy the project to the target computer

To copy the project to a remote computer, follow these steps on the source computer:
  1. Connect to a Shared Folder by Using a Mapped Drive.
    Connect the folder C:\Inetpub\wwwroot on the remote computer, with Map Network Drive as \\server\wwwroot$where server is the name of remote server computer.
  2. Copy the Project.
    To do this, follow these steps:
    1. On the Visual Studio .NET menu of WebApplication1, click Project, and then click Copy Project.
    2. In the Destination project folder text box, type http://servername/WebApplication1, where servername is the name of your server. WebApplication1 is the virtual directory and is also the name of the folder that you created in step 2 of the "Create Project Folders on the Target Computer" section of this article.
    3. In Web access method, click the File Share option. In the Path text box, type F:\WebApplication1.

      Note F represents the name of the mapped network drive.
    4. In Copy, click to select the All the files in source project folder option.
    5. Click OK to copy the project.
    Note While copying the project, you may receive the following error messages because of incompatibility between the versions of Internet Information Server (IIS) on the source and the target computers.
    Microsoft Development Environment
    The Web was created successfully, but an error occurred when trying to configure the application root for this Web. Web projects may not operate correctly without an application root. The returned error was: Active Directory Services cannot find the web server. A possible cause for this is an incompatibility between versions of Internet Information Server (IIS) on the client and the server. The usual cause for this error is creating Web projects on a Windows 2000 or newer server from a Windows NT 4.0 client. You can manually configure the application root using the Internet Services Manager.
    -or-
    Microsoft Development Environment
    Microsoft Development Environment Unable to set the permissions on the 'bin' folder to restrict browse access. Active Directory Services cannot find the web server. A possible cause for this is an incompatibility between versions of Internet Information Server (IIS) on the client and the server. The usual cause for this error is creating Web projects on a Windows 2000 or newer server from a Windows NT 4.0 client. You can manually restrict browse access to this folder using the Internet Services Manager.

Open the project on the target computer

To open the project on the target computer after you successfully copy the project from the source computer, follow these steps:
  1. In Visual Studio .NET, on the File menu, point to Open, and then click Project From Web.
  2. Type the address of your virtual server and the project file name (for example, type http://localhost/WebApplication1), and then click Open.
  3. Move to the C:\Inetpub\wwwroot\WebApplication1 folder, select the .csproj file, and then click Open.
  4. On the Build menu, click Build Solution.
  5. To save the solution (.sln) file, select the folder C:\Documents and Settings\UserName\My Documents\Visual Studio Projects\WebApplication1, and then click Save.

Collapse imageREFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:
308582 How to connect and disconnect a network drive in Windows XP
320451 Remote ASP.NET projects require IIS on the client computer or FrontPage Server Extensions on the server computer