UK Hosting Directory

Just another WordPress weblog

Information Filled Under ‘C#’

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

Do You Trust It?: Discover Techniques for Safely Hosting Untrusted Add-Ins with the .NET Framework 2.0

When you allow your application to run arbitrary code through an add-in, you may expose users to unknown code, running the risk that malicious code will use your application as an entry point into the user’s data. There are several techniques you can use to reduce the attack surface of your application, which Shawn Farkas discusses here. Shawn Farkas MSDN Magazine November 2005

Go here to see the original:
Do You Trust It?: Discover Techniques for Safely Hosting Untrusted Add-Ins with the .NET Framework 2.0

Are You Protected?: Design and Deploy Secure Web Apps with ASP.NET 2.0 and IIS 6.0

Ensuring the security of a Web application is critical and requires careful planning throughout the design, development, deployment, and operation phases. It is not something that can be slapped onto an existing application. In this article, Mike Volodarsky outlines best practices that allow you to take advantage of the security features of ASP.NET 2.0 and IIS 6.0 to build and deploy more secure Web applications

View post:
Are You Protected?: Design and Deploy Secure Web Apps with ASP.NET 2.0 and IIS 6.0

Who Goes There?: Upgrade Your Site’s Authentication with the New ASP.NET 2.0 Membership API

Here Dino Esposito and Andrea Saltarello cover the plumbing of the Membership API and its inherently extensible nature, based on pluggable providers. To demonstrate the features, they take an existing ASP.NET 1.x authentication mechanism and port it to ASP.NET 2.0, exposing the legacy authentication mechanism through the new Membership API. Dino Esposito and Andrea Saltarello MSDN Magazine November 2005

More:
Who Goes There?: Upgrade Your Site’s Authentication with the New ASP.NET 2.0 Membership API

Memory Models: Understand the Impact of Low-Lock Techniques in Multithreaded Apps

Because the use of low-lock techniques in your application significantly increases the likelihood of introducing hard-to-find bugs, it is best to use them only when absolutely necessary. Here Vance Morrison demonstrates the limitations and subtleties low-lock techniques so that if you are forced to use them you have a better chance of using them correctly. Vance Morrison MSDN Magazine October 2005

View original post here:
Memory Models: Understand the Impact of Low-Lock Techniques in Multithreaded Apps

High Availability: Keep Your Code Running with the Reliability Features of the .NET Framework

Reliability requires the capacity to execute a sequence of operations in a deterministic way, even under exceptional conditions. This allows you to ensure that resources are not leaked and that you can maintain state consistency without relying on application domain unloading (or worse, process restarts) to fix any corrupted state. Unfortunately, in the.NET Framework, not all exceptions are deterministic and synchronous, which makes it difficult to write code that is always deterministic in its ability to execute a predetermined sequence of operations.

Excerpt from:
High Availability: Keep Your Code Running with the Reliability Features of the .NET Framework

Stay Alert: Use Managed Code To Generate A Secure Audit Trail

In today’s security-conscious environments, a reliable audit trail is a valuable forensic tool The Windows Server 2003 operating system provides features that let you enable a wide range of applications to make use of auditing functionality. This article looks at auditing from the operating system perspective and describes a sample managed code implementation that will allow you to add auditing to your own server applications. Mark Novak MSDN Magazine October 2005

More:
Stay Alert: Use Managed Code To Generate A Secure Audit Trail

Best Practices: Fast, Scalable, and Secure Session State Management for Your Web Applications

ASP.NET provides a number of ways to maintain user state, the most powerful of which is session state. This article takes an in-depth look at designing and deploying high-performance, scalable, secure session solutions, and presents best practices for both existing and new ASP.NET session state features straight from the ASP.NET feature team. Mike Volodarsky MSDN Magazine September 2005

Read more here:
Best Practices: Fast, Scalable, and Secure Session State Management for Your Web Applications

Winsock: Get Closer to the Wire with High-Performance Sockets in .NET

The Win32 Windows Sockets library (Winsock) provides mechanisms to improve the performance of programs that use sockets, and the Microsoft .NET Framework provides a layer over Winsock so that managed applications can communicate over sockets. To use all these layers to write a truly high-performance socket-based application requires a little background information, as Daryn Kiely explains here. Daryn Kiely MSDN Magazine August 2005

Read more here:
Winsock: Get Closer to the Wire with High-Performance Sockets in .NET