Archive for the ‘.net’ category

Using HTML5 Web Storage in ASP.NET

January 25th, 2012

This article does a great job at showing you a simple example of how to use local browser web storage in conjunction with ASP.NET web methods to save and retrieve the data from a server side database.  Even if you aren’t interested in using this functionality in an application you have now, it’s worth reading to know what HTML5 brings to the table as far as storing your data down at the client.

Get the root part of a domain in .NET

September 16th, 2011

Need to get the .com, .us, .biz, etc. part of the domain name in .NET?

Here’s how:

Dim root As String
root = Right(Request.Url.Host, (Request.Url.Host.Length) - InStrRev(Request.Url.Host, "."))

Visual Studio 2010 Code Metrics Viewer

June 29th, 2011

What is Code Metrics Viewer? – Matthias Friedrich highlights his Visual Studio 2010 Code Metrics Viewer extension which plugs into VS 2010 Professional and uses the Code Metrics Power Tool to provide code metrics information to the IDE. Matthias is blogging a number of posts on this project blog which look at the various features of the viewer and I encourage you to check those other posts out too.

Ajax-based data loading using jQuery in ASP.NET

June 28th, 2011

Great article to check out!

Ajax-based data loading using jQuery.load() function in ASP.NET – Hajan Selmani takes a back to basics look at using jQuery to load partial chunks of HTML from a page using Ajax and insert them into the current page, providing a nice way of lighting up a web application with an ‘Ajax’ feel whilst easily maintaining non-ajax support.

The Microsoft Kinect SDK has arrived!

June 17th, 2011

The official Microsoft Kinect SDK beta is now out and available for download! Covered by Channel Nine Live Media, Microsoft Scientist Anoop Gupta made the announcement himself that after the long wait, users may now go to the official SDK website to download the latest software development kit for the Kinect camera.

Here are the features that will come with the Kinect SDK (taken from Microsoft SDK website):

“The Kinect for Windows SDK beta is a programming toolkit for application developers. It enables the academic and enthusiast communities easy access to the capabilities offered by the Microsoft Kinect device connected to computers running the Windows 7 operating system.

The Kinect for Windows SDK beta includes drivers, rich APIs for raw sensor streams and human motion tracking, installation documents, and resource materials. It provides Kinect capabilities to developers who build applications with C++, C#, or Visual Basic by using Microsoft Visual Studio 2010.

Raw sensor streams

Access to raw data streams from the depth sensor, color camera sensor, and four-element microphone array enables developers to build upon the low-level streams that are generated by the Kinect sensor.

Skeletal tracking

The capability to track the skeleton image of one or two people moving within the Kinect field of view make it easy to create gesture-driven applications.

Advanced audio capabilities

Audio processing capabilities include sophisticated acoustic noise suppression and echo cancellation, beam formation to identify the current sound source, and integration with the Windows speech recognition API.

Sample code and documentation

The SDK includes more than 100 pages of technical documentation. In addition to built-in help files, the documentation includes detailed walkthroughs for most samples provided with the SDK.

Easy installation

The SDK installs quickly, requires no complex configuration, and the complete installer size is less than 100 MB. Developers can get up and running in just a few minutes with a standard standalone Kinect sensor unit (widely available at retail outlets).

This SDK is designed for non-commercial purposes only; a commercial version is expected to be available at a later date.”

Additional details about the SDK is that it is currently in beta, meaning it is not yet the actual finished product. Rather, Microsoft wants the opinion of the Kinect hackers/developers in finalizing the product. By keeping it in beta, Microsoft will then ask users to give their feedback concerning the SDK with the eventual hope of releaseing a Kinect SDK built for and with Kinect hackers.

There is also a commercial version coming out. Details are not yet final as to what the difference would be between the two versions of the Kinect.

Source: kinecthacks.com

Tutorial for getting started with ASP.NET, WCF and jQuery

June 15th, 2011

I have been doing some work lately with jQuery, WCF, HTML5 and ASP.NET and it’s been actually pretty fun challenging and fun. I’ve gotten to tinker with quite a few new technologies that I hadn’t used before and really got to sink my teeth into jQuery and some of the cool new features that HTML5 has to offer (like local storage and offline capabilities).

When starting out with my recent project I had to pull from various resources to learn what these tools were capable of and how I could fit them all together. And while it doesn’t get into the HTML5 aspects of my project this article on creating a simple task list with ASP.NET, WCF and jQuery would have been very helpful to me in the beginning.

While the article is only Part 1 in a series, I think it will get you going in the right direction and will show you some of the power that you have on the client with the new jQuery data templates.  I must say that with the introduction of these templates you can truly offload a large amount of your logic down to the client which will provide for a much better (and faster) user experience.

Anyway, check out the article.  It’s short, to the point and offers the source code as a download too!

Rename an email attachment before sending in .NET

April 21st, 2011

I recently had the need to send an email with a file attachment from disk. The problem I faced was that the filename was not very user friendly at all. What I didn’t want to do however was rename the file on disk, or create another copy of the file with a more generic name, that could create conflicts with other users in the system.

I was happy to find that you can simply change the attachment’s file name after you create it based on the file on disk. So my original file, 2073B129-6DFF-4088-A785-C9CD8B1AADBF.pdf, could appear as Agreement.pdf to the recipient of the email. Much better, don’t you think?

And here’s how I did it:

Attachment attachment;
attachment = new Attachment("2073B129-6DFF-4088-A785-C9CD8B1AADBF.pdf");
attachment.ContentDisposition.FileName = "Agreement.pdf";
MailMessage.Attachments.Add(attachment);

There’s obviously more to the code related to creating the message, etc. But this is what you need if you want to give the attachment a different file name.

Enjoy!

How to use the My Namespace in C#

February 22nd, 2011

When I was first trying to transition from VB.NET to C# I found it pretty odd that the “My” Namespace wasn’t available in C#.  If you aren’t aware of what I’m talking about, the Microsoft.VisualBasic.MyServices namespace (My in Visual Basic) provides easy and intuitive access to a number of .NET Framework classes, enabling you to write code that interacts with the computer, application, settings, resources, and so on.

After a little hunting I discovered that by simply adding a reference and a using statement that I could be up and running with my beloved My classes that I had come to know and love.  Here’s how you do it…

Add a Reference

  1. In Solution Explorer, right-click the References node, and select Add Reference.
  2. When the References dialog box appears, scroll down the list, and select Microsoft.VisualBasic.dll.You might also want to include the following line in the using section at the start of your program.
    using Microsoft.VisualBasic.Devices;

Example

This example calls various static methods contained in the MyServices namespace. For this code to compile remember that we added a reference to Microsoft.VisualBasic.DLL in the step above.

using System;
using Microsoft.VisualBasic.Devices;
 
class TestMyServices
{
    static void Main()
    {
        // Play a sound with the Audio class:
        Audio myAudio = new Audio();
        Console.WriteLine("Playing sound...");
        myAudio.Play(@"c:\WINDOWS\Media\chimes.wav");
 
        // Display time information with the Clock class:
        Clock myClock = new Clock();
        Console.Write("Current day of the week: ");
        Console.WriteLine(myClock.LocalTime.DayOfWeek);
        Console.Write("Current date and time: ");
        Console.WriteLine(myClock.LocalTime);
 
        // Display machine information with the Computer class:
        Computer myComputer = new Computer();
        Console.WriteLine("Computer name: " + myComputer.Name);
 
        if (myComputer.Network.IsAvailable)
        {
            Console.WriteLine("Computer is connected to network.");
        }
        else
        {
            Console.WriteLine("Computer is not connected to network.");
        }
    }
}

Not all the classes in the MyServices namespace can be called from a C# application. You can visit this MSDN article that details more on what’s not supported.

Use ASP.NET and DotNetZip to Create and Extract ZIP Files

February 16th, 2011

I recently came across this article from Scott Mitchell, that shows how to use DotNetZip to create and extract ZIP files in an ASP.NET application, and covers advanced features like password protection and encryption.

The article details all that you can do with the feature-rich, free, open source ZIP implementation for .NET - DotNetZip. Using DotNetZip and a dash of .NET code you can:

  • Create a new ZIP file and add one or more files or folders,
  • Read the contents of a ZIP file,
  • Extract all (or some) of the contents of a ZIP file to a specified folder,
  • Use advanced ZIP file format features, such as encrypting the contents of the ZIP and protecting them with a password.

This is definitely something that will come in handy.  I’ve tried working with zip files in the past and it has never been this easy.  Dealing with a ZIP file is definitely something that you will need to do at some point if you program long enough.  With this article, it will definitely be something that you won’t bang your head against the wall trying to accomplish!

CMAP Main Meeting – Tuesday, December 7th – IIS Express, Razor, and WebMatrix, OH my!

December 7th, 2010
CMAP Main Meeting – Tuesday, December 7th – IIS Express, Razor, and WebMatrix, OH my! – G. Andrew Duthie

When: Tuesday, November 7th, 6:30 PM – 9:00 PM

Where: HCC Business Training Center, 6751 Columbia Gateway Drive, MD, 21046

Topic: IIS Express, Razor, and WebMatrix, OH my!

Does the announcement of so many new technologies make you wonder where the yellow brick road is that will lead you to the Oz of understanding? Well, there’s no denying that there’s a lot to keep up with these days if you’re a web developer. So let Microsoft Developer Evangelist G. Andrew Duthie give you an overview of Microsoft WebMatrix, ASP.NET Web Pages, the new Razor syntax, and IIS Express, and how they fit in with the existing offerings in Microsoft’s web stack.

Learn how and when you’d want to leverage these new technologies, and when existing technologies may be a better choice. Expect discussion and demo, and bring your questions, so we can make this an interactive and dynamic session!

Presenter: G. Andrew Duthie

G. Andrew Duthie, aka .net DEvHammer, is the Developer Evangelist for Microsoft’s Mid-Atlantic States district, where he provides support and education for developers working with the .net development platform. In addition to his work with Microsoft, Andrew is the author of several books on ASP.NET and web development, and has spoken at numerous industry conferences from VSLive! and ASP.NET Connections, to Microsoft’s Professional Developer Conference (PDC) and Tech-Ed. Andrew is also the creator and developer of Community Megaphone, a site designed for promoting and finding developer community events. Andrew can be reached through his blog at http://blogs.msdn.com/gduthie or on Twitter at @devhammer.

For more information about the meeting, please visit the CMAP website.