UK Hosting Directory

Just another WordPress weblog

Information Filled Under ‘C#’

How to Use Optional Parameters in C# 4.0

Optional parameters are default values used when a function or method is called without specific arguments. They can be used in PHP… // PHP optional parameters function DoSomething($num = 1, $str = “optional”) { // code } as well as VisualBasic.NET: ‘ VB.NET optional parameters Public Sub DoSomething( Optional ByVal num As Integer = 1, Optional ByVal str As String = “optional” ) ‘ code End Sub and similar functionality can be written in JavaScript: // JavaScript optional parameters function DoSomething(num, str) { num = (typeof(num) != “undefined”

Read the original post:
How to Use Optional Parameters in C# 4.0

jQuery and Windows Azure

The goal of this blog entry is to describe how you can host a simple Ajax application created with jQuery in the Windows Azure cloud. In this blog entry, I make no assumptions. I assume that you have never used Windows Azure and I am going to walk through the steps required to host the application in the cloud in agonizing detail.

Link:
jQuery and Windows Azure

AsyncEnumerator Survey for Microsoft

If you have never used my AsyncEnumerator class (which is part of my free Power Threading library) to simplify writing code that performs asynchronous operations, then you can ignore the rest of this blog posting. I have been working with Microsoft in an attempt to add my AsyncEnumerator (or something like it) into a future version of the .NET Framework.

More:
AsyncEnumerator Survey for Microsoft

Crystal Reports for Visual Studio 2010

Crystal Reports has been a part of Visual Basic since 1993, and a part of Visual Studio since its first release in 2002. Crystal Reports has been a very successful component of these products. With the release of Visual Studio 2010, SAP and Microsoft have mutually decided to change how we deliver this important component to the .NET developer community going forward

View original post here:
Crystal Reports for Visual Studio 2010

Named & optional parameters in Silverlight 4

Named & optional parameters are a new C# language feature coming up with .NET FX 4.0 and guess what… it’s in Silverlight 4 as well! Optional parameters will come very useful when defining complex APIs where you would usually have to provide several Read More……( read more )

See the rest here:
Named & optional parameters in Silverlight 4

I’m speaking at the DevWeek conference in London this week and did a short video interview

You can find Part 1 here: http://blogs.msdn.com/devpara/archive/2010/03/16/jeffrey-richter-at-devweek-2010-part-1.aspx and Part 2 here: http://blogs.msdn.com/devpara/archive/2010/03/16/jeffrey-richter-at-devweek-2010-part-2.aspx

More:
I’m speaking at the DevWeek conference in London this week and did a short video interview

How can I get objects and property values from expression trees?

This is a follow-up to the Getting Information About Objects, Types, and Members with Expression Trees post, so I would recommend that you read that one first. Among other code examples in that blog post, I demonstrated how you can get a property name as a string by using expression trees.

Continue reading here:
How can I get objects and property values from expression trees?

Covariance and Contravariance FAQ

In this post I’ll try to answer the most common questions I find on forums and in documentation feedback about C# covariance and contravariance. It’s a big topic for a single blog post, so expect to see a lot of “more information” links. Special thanks to Eric Lippert and Chris Burrows for reviewing and providing helpful comments

Read this article:
Covariance and Contravariance FAQ

My CLR via C# book is at the printer. The source code and Introduction are available now!

Hello all, I just wanted to tell everyone that my book, CLR via C# 3rd Edition, went to the printer this week and should be in stores in early February! The book has been updated for Visual Studio 2010, CLR 4.0 and C# 4.0. The source code for the book is available now and can be downloaded from here: http://wintellect.com/Books.aspx Also, an excerpt from the book’s Introduction can be found here: http://blogs.msdn.com/microsoft_press/archive/2010/01/21/rtm-d-today-clr-via-c-third-edition.aspx

Getting Information About Objects, Types, and Members with Expression Trees

Starting with C# 3.0 and Visual Studio 2008, you can use expression trees to get information about objects, types, and members. In this post I’m going to show some examples and explain what benefits you can get by using this technique. If you are not familiar with expression trees, I would recommend reading Charlie Calvert’s blog post Expression Tree Basics first

See original here:
Getting Information About Objects, Types, and Members with Expression Trees

3D Buzz XNA Xtreme 101 Volume 1,2,3 Complete | 3.5 GB

3D Buzz XNA Xtreme 101 Volume 1,2,3 Complete | 3.5 GB DVD I Have you ever been interested in creating your own games? Welcome to the XNA Xtreme 101 video training course! This first volume covers nearly 30 hours of lecture and is specially geared toward the first-time programmer interested in creating games for the PC and Xbox 360 platforms! Volume I will quickly get you up to speed in programming with a strong foundation in the C# programming language

Read more from the original source:
3D Buzz XNA Xtreme 101 Volume 1,2,3 Complete | 3.5 GB

Get value collection of a SharePoint Choice Field

 public static List GetChoiceFieldValues(string listName,string fieldName, string siteCollection, string webSite)         {             List fieldList;             SPSite spSite = null;             SPWeb spWeb = null;             try             {                 if (siteCollection != null)                     spSite = new SPSite(siteCollection);                 else                     spSite = SPContext.Current.Site;                 if (webSite != null)                     spWeb = spSite.OpenWeb(webSite);                 else                     spWeb = spSite.OpenWeb();                 SPList spList = spWeb.Lists[listName];                 SPFieldChoice field = (SPFieldChoice)spList.Fields[fieldName];                 fieldList = new List ();                 foreach (string str in field.Choices)                 {                     fieldList.Add(str);                 }             }             catch (Exception ex)             {                 LogException(ex);                 throw;             }             finally             {                 if(spWeb != null)                     spWeb.Close();                 if(spSite != null)                     spSite.Close();             }             return fieldList;         }  

Read the original post:
Get value collection of a SharePoint Choice Field

Improving the AJAX Control Toolkit with the Lightweight Test Automation Framework (LTAF)

The AJAX Control Toolkit is an incredibly popular set of controls that enable you to easily add JavaScript functionality to an ASP.NET application. The AJAX Control Toolkit has consistently been one of the top three most popular downloads from CodePlex since the birth of CodePlex (see http://www.CodePlex.com ).

Go here to read the rest:
Improving the AJAX Control Toolkit with the Lightweight Test Automation Framework (LTAF)

ASP.NET 4.0 AJAX – Preview 4 – Client Templates

A little over a month ago, Microsoft released the fourth preview of ASP.NET 4.0 AJAX.  This is the new release of the Microsoft AJAX Framework that will be released with ASP.NET 4.0.  We’re getting closer to the RTM release of .NET 4.0 (hopefully later this year), so I figured this would be a good time to start posting about ASP.NET 4.0 AJAX.  There are some very exciting things coming along with ASP.NET 4.0, and the ASP.NET AJAX component is no exception.  The best news about ASP.NET AJAX is that you can start using it today without having to wait for the full blown ASP.NET AJAX framework.  Keep in mind that these components are still in “preview” mode (meaning no Microsoft support), though they are usable at your own risk.  For more information, you can check out the license on CodePlex. In this post, I’ll be talking about the client templates that can be found in the latest release.  Client templates are very powerful.  They are a key component for rich client-side applications.  Up until now, I have been using jTemplates , a client template solution plugin for jQuery.  If you aren’t familiar with jTemplates, check out Dave Ward’s article “ Use jQuery and ASP.NET AJAX to build a client side Repeater .”  jTemplates is really a nice plugin, but it’s a bit disconnected from the flow of the page.  Enter ASP.NET 4.0 AJAX and the DataView control. Introducing the Sys.UI.DataView Control The ASP.NET AJAX DataView (not to be confused with the ADO.NET DataView), is a new control that functions similar to a server-side repeater as you will see.  The first thing to note with the DataView is that this control operates without ASP.NET, meaning you can use this in any framework or even a straight HTML page.  This shouldn’t be too much of a surprise, since you can download the ASP.NET AJAX Library 3.5 as standalone scripts today.  Having said that, let’s start with an simple example that will just run in a standard HTML page.  For this first example, I will walk through declaratively setting up template binding.  Let’s get started… Want to follow along with the examples?

Link:
ASP.NET 4.0 AJAX – Preview 4 – Client Templates

Errors "Microsoft .NET Framework 3.5 installation has failed. SQL 2008 Setup requires .NET 3.5 to be installed." and "This server…

Today I had to work on a project which uses VS2008 and SQL Server 2008. I haven’t used SQL2008 but had used VS2008 a little bit. When I tried to install SQL2008 (Developer edition) got this strange error which says “Microsoft .NET Framework 3.5 installation has failed.

Read the original post:
Errors "Microsoft .NET Framework 3.5 installation has failed. SQL 2008 Setup requires .NET 3.5 to be installed." and "This server…

Add a user programmatically to a User Group in SharePoint

        ///         /// Add a user to a Sharepoint group         ///         /// Login name of the user to add         /// Group name to add         private void AddUserToAGroup(string userLoginName, string userGroupName)         {             //Executes this method with Full Control rights even if the user does not otherwise have Full Control             SPSecurity.RunWithElevatedPrivileges(delegate             {                 //Don’t use context to create the spSite object since it won’t create the object with elevated privileges but with the privileges of the user who execute the this code, which may casues an exception                 using (SPSite spSite = new SPSite(Page.Request.Url.ToString()))                 {                     using (SPWeb spWeb = spSite.OpenWeb())                     {                         try                         {                              //Allow updating of some sharepoint lists, (here spUsers, spGroups etc…)                             spWeb.AllowUnsafeUpdates = true;                             SPUser spUser = spWeb.EnsureUser(userLoginName);                             if (spUser != null)                             {                                 SPGroup spGroup = spWeb.Groups[userGroupName];                                 if (spGroup != null)                                     spGroup.AddUser(spUser);                             }                         }                         catch (Exception ex)                         {                             //Error handling logic should go here                         }                         finally                         {                             spWeb.AllowUnsafeUpdates = false;                         }                     }                 }             });         }   Here in this method you have to set “spWeb.AllowUnsafeUpdates = true” to allow updating some sharepoint lists.

Continue reading here:
Add a user programmatically to a User Group in SharePoint

How can I easily log a message to a file for debugging purposes?

Often, you need a way to monitor your applications once they are running on the server or even at the customer site — away from your Visual Studio debugger. In those situations, it is often helpful to have a simple routine that you can use to log messages to a text file for later analysis. Here’s a simple routine that has helped me a lot for example when writing server applications without an user interface: using System.IO; public string GetTempPath() { string path = System.Environment.GetEnvironmentVariable(“TEMP”); if (!path.EndsWith(“\”)) path += “\”; return path; } public void LogMessageToFile(string msg) { System.IO.StreamWriter sw = System.IO.File.AppendText( GetTempPath() + “My Log File.txt”); try { string logLine = System.String.Format( “{0:G}: {1}.”, System.DateTime.Now, msg); sw.WriteLine(logLine); } finally { sw.Close(); } } With this simple method, all you need to do is to pass in a string like this: LogMessageToFile(“Hello, World”); The current date and time are automatically inserted to the log file along with your message.

See the article here:
How can I easily log a message to a file for debugging purposes?

How can I speed up hashtable lookups with struct object as keys?

When you have struct objects as the key in a hashtable, the lookup operation of the hashtable performs miserably. This can be attributes to the GetHashCode() function which is used internally to do the lookup. If a struct contains only simple value types (int, short, etc.), the algorithm which computes the GetHashCode creates hashes which fall into mostly the same bucket.

See the article here:
How can I speed up hashtable lookups with struct object as keys?

Toolbox: Analyze HTTP Traffic, Synchronize Databases, and More

Debugging Web applications can be a difficult process due to the logical, physical, and temporal differences between the mishmash of technologies that comprise such an application. For bugs that arise from the HTML and script received by the browser or in the transfer or request of a page’s markup, developers often adopt archaic debugging techniques, such as using View Source and Notepad to scrutinize the contents received by the browser

Excerpt from:
Toolbox: Analyze HTTP Traffic, Synchronize Databases, and More

Are You in the Know?: Find Out What’s New with Code Access Security in the .NET Framework 2.0

Unlike role-based security measures, code access security is not based on user identity. Instead, it is based on the identity of the code that is running, including information such as where the code came from. Here Mike Downen discusses the role of code access security (CAS) in .NET and outlines some key new features and changes in CAS for the .NET Framework 2.0.

Read more from the original source:
Are You in the Know?: Find Out What’s New with Code Access Security in the .NET Framework 2.0