Skip to main content

Posts

Showing posts from April, 2008

What's New in ASP.NET and Web Development

The .NET Framework version 3.5 includes enhancements for ASP.NET in targeted areas. Visual Studio 2008 and Microsoft Visual Web Developer Express Edition also include enhancements and new features for improved Web development. The most significant advances are improved support for developing AJAX-enabled Web sites and support for Language-Integrated Query (LINQ). The advances include new server controls and types, a new object-oriented client type library, and full IntelliSense support in Visual Studio 2008 and Microsoft Visual Web Developer Express Edition for working with ECMAScript (JavaScript or JScript). The following sections of this topic describe the changes in ASP.NET and Visual Web Developer. ASP.NET Enhancements Visual Web Developer Enhancements ASP.NET Enhancements The .NET Framework version 3.5 includes enhancements for ASP.NET in the following areas: New server controls, types, and a client-script library that work together to enable you to

Preprocess Win32 Messages through Windows Forms

In the unmanaged world, it was quite common to intercept Win32 messages as they were plucked off the message queue. In that rare case in which you wish to do so from a managed Windows Forms application, your first step is to build a helper class which implements the IMessageFilter interface. The sole method, PreFilterMessage(), allows you to get at the underlying message ID, as well as the raw WPARAM and LPARAM data. By way of a simple example: public class MyMessageFilter : IMessageFilter { public bool PreFilterMessage(ref Message m) { // Intercept the left mouse button down message. if (m.Msg == 513) { MessageBox.Show("WM_LBUTTONDOWN is: " + m.Msg); return true; } return false; } } At this point you must register your helper class with the Application type: public class mainForm : System.Windows.Forms.Form { private MyMessageFilter msgFliter = new MyMessageFilter(); public mainForm() { // Register message filter. Applicati

Is it possible to output the command-line used to build a project in Visual Studio?

Now that Whidbey has been out in Beta for more than a few months, it seems worth revisiting some frequently asked questions which have different (better?) answers now. In Everett (v7.1) the answer used to be No. However, in Whidbey (v8.0), the answer is Yes (and No). For the yes part of the answer, after building, go to the Output Window, select "Show Output from: Build", and about half way down you will see a section like this: Target "Compile" in project "ConsoleApplication1.csproj" Task "Csc" Csc.exe /noconfig /warn:4 /define:DEBUG;TRACE /debug+ /optimize- /out:obj\Debug\ConsoleApplication1.exe /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.31125\System.Data.dll, C:\WINDOWS.0\Microsoft.NET\Framework\v2.0.31125\System.XML.dll, C:\WINDOWS\Microsoft.NET\Framework\v2.0.31125\System.dll /target:exe /win32icon:App.ico AssemblyInfo.cs Class1.cs The task is invoking the IDE's in-process compiler to perform the equivalent of the above command-l

How do I get and set Environment variables?

Use the System.Environment class.Specifically the GetEnvironmentVariable and SetEnvironmentVariable methods. Admitedly, this is not a question specific to C#, but it is one I have seen enough C# programmers ask, and the ability to set environment variables is new to the Whidbey release, as is the EnvironmentVariableTarget enumeration which lets you separately specify process, machine, and user.

How do I create a constant that is an array?

Strictly speaking you can't, since const can only be applied to a field or local whose value is known at compile time. In both the lines below, the right-hand is not a constant expression (not in C#). const int [] constIntArray = newint [] {2, 3, 4}; // error CS0133: The expression being assigned to 'constIntArray' must be constant const int [] constIntArrayAnother = {2, 3, 4}; // error CS0623: Array initializers can only be used in a variable or field // initializer. Try using a new expression instead. However, there are some workarounds, depending on what it is you want to achieve. If want a proper .NET array (System.Array) that cannot be reassigned, then static readonly will do for you. static readonly int [] constIntArray = new int[] {1, 2, 3}; The constIntArray field will be initialized before it its first use. If, on the other hand, you really need a const set of values (say as an argument to an attribute constructor), then - if you can limit yourself

What is the difference between const and static readonly?

The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, w hereas the value of a const field is set to a compile time constant. In the static readonly case, the containing class is allowed to modify it only in the variable declaration (through a variable initializer) in the static constructor (instance constructors, if it's not static) static readonly is typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time. Instance readonly fields are also allowed. Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference. class Program { public static readonly Test test = new Test (); static void Main ( string [] args) { test.Name = "Program"; test = new T

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 th

How do I play default Windows sounds?

Sometimes, you might want to make your application a bit more audible. If you are using .NET 2.0, you can utilize the new System.Media namespace and its SystemSound and SystemSounds classes. The SystemSounds class contains five static properties that you can use to retrieve instances of the SystemSound class. This class in turn contains the Play() method, which you can use to play the wave file associated with the sound in Windows Control Panel. Note that the user can also disable all sounds altogether, which would mean that no sound can be heard through the computer speakers. To play for example the classical beep sound, you could use the following code:System.Media.SystemSounds.Beep.Play(); Similarly, you could play the “Question” sound with this code:System.Media.SystemSounds.Question.Play(); The System.Media namespace is defined in System.dll, so there are no new DLLs you would need to add to your project’s references to use the above code.

How do I calculate a MD5 hash from a string?

It is a common practice to store passwords in databases using a hash. MD5 (defined in RFC 1321) is a common hash algorithm, and using it from C# is easy. Here’s an implementation of a method that converts a string to an MD5 hash, which is a 32-character string of hexadecimal numbers. public string CalculateMD5Hash(string input){ // step 1, calculate MD5 hash from input MD5 md5 = System.Security.Cryptography.MD5.Create(); byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input); byte[] hash = md5.ComputeHash(inputBytes); // step 2, convert byte array to hex string StringBuilder sb = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("X2")); } return sb.ToString(); } An example call: string hash = CalculateMD5Hash("abcdefghijklmnopqrstuvwxyz"); …returns a string like this: C3FCD3D76192E4007DFB496CCA67E13BTo make the hex string use lower-case letters instead of upper-case, replace the single lin

How do I send out simple debug messages to help with my debugging?

Visual Studio offers tons of useful debugging features and allows you to step through your code line-by-line. However, there are times when you don’t want to step through your application, but want to make it output simple text strings with variable values, etc. Enter the System.Diagnostics.Debug class and its Write* methods. By using the Debug class, you can output messages similarly to the way the Win32 API function OutputDebugString. However, the beauty of the Debug class is that when you build your application using the default Release configuration in Visual Studio, no code lines are generated for your Debug.Write* class. This means there’s no performance penalty for using the Debug class in release code. To use the Debug class, simply add the “using System.Diagnostics;” statement to your C# code file, and call Debug.Write: Debug.Write("Hello, Debugger!"); In addition to Write, you have the possibility to call WriteIf, WriteLine and WriteLineIf. For example: bool @this =

What's the difference between SharePoint Portal Server and Windows SharePoint Services?

1) What's the difference between SharePoint Portal Server and Windows SharePoint Services? This is by far the biggest point of confusion for most people. Windows SharePoint Services (WSS) is a technology built into Microsoft's Windows Server 2003. It's a service that allows you to create team sites to assist with smaller group collaboration with features such as document and form libraries (somewhat akin to a shared file system folder, but with check in/out, version control, integration with office, etc.), custom lists such as issue, task, contact and any other types of list you can think up (think of a list as a set of columns and rows), simple search-ability, discussion boards, image libraries (for storing photos and other images) and surveys. That all said, there are valid reasons to create team sites that the whole company might visit. It takes a good process to determine when to put something in a team site and when to put it in the portal. That's where we usually

What is a SharePoint Web Site?

SharePoint Web Sites are pre-designed web sites that contain a wide range available services. When you subscribe to a SharePoint Web Site everything you need to get started using SharePoint is all ready and waiting for you. You can customize your web site in a variety of ways using tools included with SharePoint, or you can download and install one or more web site templates that include a variety of predetermined customizations. For a list of predefined customizations, click here .

How do I get Windows SharePoint Services?

Windows SharePoint Services is a component of Windows Server 2003 and conforms to the Windows Server 2003 licensing model. Organizations simply need to own Windows Server 2003 licenses to have the rights to also use Windows SharePoint Services. Learn more about licensing Windows Server 2003 and Windows SharePoint Services on the SharePoint licensing page.

What is the relationship between Windows SharePoint Services, Microsoft Office SharePoint Server 2007, and Microsoft Office SharePoint Designer 2007?

Windows SharePoint Services is a key component of Microsoft SharePoint Products and Technologies, which include: Windows SharePoint Services , formerly named SharePoint Team Services, a versatile technology in Windows Server 2003. In addition to its collaborative features, Windows SharePoint Services also exposes platform services and a common framework for document storage and management, as well as search, workflow, rights management, administration, and deployment features. These services provide the foundation for building scalable business applications. Office SharePoint Server 2007 , an integrated suite of easy-to-use server applications that help people and teams improve their efficiency and effectiveness. Office SharePoint Server 2007 connects sites, people, and business processes—facilitating knowledge sharing by offering ready-to-go, enterprise-wide functionality for records management, search, workflows, portals, personalized sites, and more. Office SharePoint Server 2007 ex

How does Windows SharePoint Services integrate with the Microsoft Office system?

Through a set of Web services and documented application interfaces, Windows SharePoint Services can be easily integrated with smart client tools. Users easily adopt these new tools because of their similarity to other familiar environments, such as the Microsoft Office system. For example, Microsoft Office Word, Microsoft Office Excel, Microsoft Office PowerPoint, Microsoft Office InfoPath, Microsoft Office Project, and Microsoft Office OneNote can use information in SharePoint sites natively. Users can create workspaces, post and edit documents, and assign tasks, all while working on documents stored in SharePoint sites. With Microsoft Office Outlook 2007, users can view calendars and contact lists stored on SharePoint sites and can create and manage sites for editing documents and organizing meetings.

My company currently uses Windows SharePoint Services 2.0. Why should we upgrade to Windows SharePoint Services 3.0?

Windows SharePoint Services 3.0 offers many new and enhanced features that help business organizations of all sizes further improve individual and team productivity, and the efficiency of their business processes. These new and improved features help employees to implement and manage workspaces and team sites more easily without help from IT, simplify and improve the management and maintenance of documents stored on SharePoint sites, and provide more robust and easy-to-use collaboration tools that encourage information sharing within the organization. Windows SharePoint Services 3.0 also provides IT departments with enhanced control of company resources and a more flexible and robust foundation for building new, Web-based applications and services that can connect to and capitalize on existing line-of-business applications.

What’s new in Windows SharePoint Services 3.0?

Key improvements to Windows SharePoint Services in Version 3.0 include: Improvements to collaboration workspaces: SharePoint sites now offer e-mail and directory integration, alerts, RSS publishing, templates for building blogs (also known as weblogs) and wikis (Web sites that can be quickly edited by team members—no special technical knowledge required), event and task tracking, improved usability, enhanced site navigation, and more. Enhancements to content storage: SharePoint lists and libraries now provide per-item security for better data control and integrity, a recycle bin, and enhanced flexibility for storing more types of content. Row and column capacity has also been increased, as has retrieval speed. Windows SharePoint Services 3.0 can be easily integrated with smart client tools. In particular, close integration with Microsoft Office Outlook 2007 provides offline access to events, contacts, discussions, tasks, and documents. Easier provisioning of workspaces: Windows Share

Why should I consider using Windows SharePoint Services for my organization?

Windows SharePoint Services offers you benefits in four primary areas: Efficient collaboration: Help your employees and teams to stay connected and productive by providing access to the people, documents, and information they need. Rapid deployment, ease of use: Deploy collaboration applications quickly that are easy to use through integration with familiar productivity tools such as the Microsoft Office system. Manageable infrastructure: Manage the security of your organization’s information resources by deploying a scalable storage infrastructure with powerful administration services and controls. Robust foundation platform for Web-based applications: Increase business process efficiency by creating Web applications and workflow scenarios on a cost-effective, extensible platform.

Who should consider using Windows SharePoint Services?

Windows SharePoint Services is a technology that enables people to collaborate in browser-based workspaces while providing a manageable infrastructure and extensible application platform for improving the efficiency of business processes. A variety of audiences benefit from the enhanced collaboration and productivity provided by Windows SharePoint Services: Organizations, business units, and teams seeking increased productivity and access to the people, documents, and information they need. Organizations of any size that want to start tactical implementation of collaboration tools, standardize existing infrastructure, or invest in strategic use of collaboration systems that integrate well with existing line-of-business applications. IT departments seeking better control over and security of company data, while adding value and efficiency to lines of business. Developers creating rich and scalable Web-based applications.

What is Windows SharePoint Services?

Windows SharePoint Services is a versatile technology included in Microsoft Windows Server 2003 that enables organizations and business units of all sizes to increase the efficiency of business processes and improve team productivity. With tools for collaboration that help people stay connected across organizational and geographic boundaries, Windows SharePoint Services gives people access to documents and information they need. With a familiar, Web-based interface and close integration with everyday tools including the Microsoft Office system of productivity programs, Windows SharePoint Services is easy to use and can be deployed rapidly. Users can create workspaces and then publish, store, share, and keep track of information, workflow, and documents. Built on Microsoft Windows Server 2003, Windows SharePoint Services also gives organizations a cost-effective foundation platform for building Web-based business applications that can scale easily to meet the changing and growing needs