background preloader

C-sharp

Facebook Twitter

Empty Template Text Box. Download control - 37.3 KB Introduction This guide will show you how to create a custom TextBox control that will display a value when empty, used for a label of the field. For instance, in an address form, this would show "Customer Name" in an empty text box. Once the user enters the control it reverts to standard operation. Background Sometime you need to make a form as compact as possible, and that requires you to have no additional label controls to describe your text boxes.

Using the code So the code provided is pretty much ready to use, but the methods involved will give you an idea of how this is done. Here is the code for the class. Note that since we start with a UserControl, we need to change the following line: public partial class EmptyTemplateTextBox : UserControl to read: public partial class EmptyTemplateTextBox : TextBox Since we started with a UserControl, we need to tweak the EmptyTemplateTextBox.Designer.cs file a bit. The three properties we need to add for this control are: Time Period Library for .NET. New in v2: performance improvement and support for accounting (4-4-5) calendar. Introduction When implementing some software for another project, I came across several requirements involving calculations with time periods.

These calculations were an important part of the solution and had high demands in respect to the correctness and accuracy of the results. The required functionality covered the following areas: Support for individual time periodsWorking with calendar periods within calendar yearsWorking with calendar periods deviating from the calendar year (fiscal or school periods)Working with the accounting and broadcast calendar The time calculations should be made available to both server components (Web Services and tasks) as well as for a rich client (WPF and Silverlight) and mobile devices. Analyzing the situation brought me to the conclusion that neither the components of the .NET Framework (which I didn't expect) nor any other available tools would cover all the requirements.

A Performance Counters Helper Class. Download sample - 14.92 KB Introduction In the last project I was working on, we needed to add some performance counters to measure the duration of various parts of the system. There is information on performance counters in MSDN and also in CodeProject, but we just could not find the exact information we were looking for. We started by creating a performance counters manager for one part of our system that specifically handled counting duration of operations. But then, we realized that we required similar functionality in other parts of the system.

So we created a base class PerformanceCountersManagerBase as a helper class for writing performance counters. Using the Code The attached code shows a simplified usage of the PerformanceCountersManagerBase. The sample is divided into 3 parts: Core. After you install the performance counters as explained below, you can run the sample, open the performance monitor and observe the performance counters as they change over time. installutil Impl.dll. Send ASP.NET formatted exception details via email. XML serialization using Generics. Download demo - 25.1 KB Serialize/deserialize your objects using generics.

Customize settings like indentation, encoding, namespaces and others. Table of contents XML Serialization Overview XML serialization is the process of converting an object into a XML string in order to persist it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. Some good uses for XML serialization/deserialization are [1]: Storing user preferences in an object Maintaining security information across pages and applications Modification of XML documents without using the DOM Passing an object from one application to another Passing an object from one domain to another Passing an object through a firewall as an XML string A generic serializer class – XmlSerializer<T> I’ve created a generic class to serialize/deserialize XML: This class allows us to: The scenario – User Shopping Cart Model source code: Using the code Generated XML: References.

Claim based Authentication and WIF. Introduction There is a lot of buzz about Claim based Authentication. In this article, we'll understand what is Claim based Authentication, what are the benefits and a lot more. This is my first article in this series. In subsequent posts, we will see the implementation and more scenarios. Let's first understand what the need is for Claim based authentication? Problems with Current Authentication We make several user accounts at several portals/websites.

One more problem, most of the applications use some authentication mechanism, mainly Classic UserName and Password. Most of the developers have some or the other day worked on the SingleSignOn feature. As a user, we create new user credentials (username and password) to many applications on the internet like Facebook, Yahoo, Gmail, etc. and some in-house sites like some college portal, etc. or some enterprise application. Solution But how can this take place? The above picture is self-explanatory.

Claim Based Authentication What is an Identity.

MVC

Loading Excel data into a GridView. Send ASP.NET formatted exception details via email. Managing Exception/Error is a common task in any application. In ASP.NET, there are many ways to handle those errors or exceptions, for example, when an error or exception occurrs in an ASP.NET application, the system is going to send a formatted error message to specified developers or teams mentioned in the email list.

The difference will be the body of the email will contain exactly the same formatted error as the ASP.NET generated one to display the error or exception details when occurred. For example, But when an ASP.NET application goes into life, the user should not have to see the above error page where they should see a custom error page which is easy to understand. So in here, the test application will display the default error page when an error occurs in the system as well as send an email with the formatted exception details like in the above image.

So the GetHtmlErrorMessage() method of the HttpUnhandledException class will do all the formatting stuff. Default error page: Google Charts in ASP.NET. Introduction Through this article, I'll try to explain how we can use Google charts for reporting purposes in ASP.NET web applications. Report generation is something quite common and we need to generate self explanatory and good looking reports to the users almost every time. “Images always speak more than words”. So instead of just showing the figures in our reports, we can let the users see diagrammatic charts which can help the users to analyze the whole data more quickly and easily. Though Microsoft itself has its charting controls for .NET, but we integrate it with other great technology by Google. Google has its own, very awesome and simple application for charting purposes which we will be using here. I will request you to get a brief idea of what Google charts are, by visiting the following link: So to brief stuff down, let’s look at one example.

Visit the below link: Reference. How to Configure ASP.NET Unit Tests in Visual Studio 2010. Write your own GetXml function. The DataSet object in .NET has a GetXml function. The method takes data from all the tables and from all rows and creates XML. The problem is that you cannot change this XML. So I created a method that does something similar: You can read about in my blog: Gregory Nozik Software Developer (Senior)SuperderivativesIsrael I’m a .net architect, focusing mainly on writing a scalable components, My expertise is designing for optimal performance and scalability.

Using Ajax AutoCompleteExtender for autosuggest. Download source - 2.64 KB Introduction In the present scenario, we need our text boxes to act more user friendly, so auto suggest is a feature that makes it more user friendly. Moreover the chance of making typo mistakes also reduces. This article will help you in adding a simple auto suggest feature using AJAX AutoCompleteExtender. Background A service is used to call the data from database. Using the Code Code is populating auto suggest for a company.

The name of the service is “CompanyServiceForAutoSuggest” in which exists method GetCompanyList which includes two parameters: “prefixText” the text to be searched to populate the autosuggest“count” the maximum number of records in the auto suggest The method returns an array string, which includes company name and its ID. I have created a control, as it needs to be placed at many locations. On the ucCompany.ascx page, write the following lines: ServicePath is the actual path where my service is saved. Points of Interest. Web.Config Transformations when Debugging.

I am a big fan of the Web.Config Transformations that got introduced with a while back. Prior to them being inherently supported one could accomplish the same thing with part of the Enterprise Library, and prior to that one could leverage a custom MSBuild Task or the XMLPoke Task to get your web.config updated based on the environment it was targeting. Having your configuration elements managed with a transform file makes it a bit easier to manage and keep track of your settings that could change based on environment or settings.

Without this each developer on your team might need to create host entries and keep their folder structure the same to ensure the settings work for each of their machines. Another option is each team member just has their own configuration files with their specific settings that they need but when source control is introduced this can get tricky because one developer might be overwriting another's settings. 7 Page Jump Methods in ASP.NET. Incrementing AssemblyVersion revision number on each build. On each release (or build operation), we are incrementing our build number to flag that we've done something different. Although Visual Studio has an auto-build/revision feature (use the "*" in the AssemblyVersion attribute), like the following code shows: [assembly: AssemblyVersion("1.0.0.

*")] However, that number begins from a very large value. Some of us would love to start from 1 and increment the revision number one by one. The above code simply reads a C# file, searches the "[assembly: AssemblyVersion" part of it and uses a regular expression to replace the revision number. Having the above code, we can save it as a JavaScript file (I save the file into the solution directory and name it as "AutoIncrementBuildNumber.js") and add the following line onto the post-build procedure of the project. CScript.exe "$(SolutionDir)AutoIncrementBuildNumber.js" "$(SolutionDir)Properties\AssemblyInfo.cs" "$(ConfigurationName)" The build number will be incremented after each release. Calling a C# method using jQuery on the client side. This code will help you when you need to define a method code-behind and want to call that method from the client side. jQuery has made life simple.

There is a very easy way to do this. Earlier, we knew one way that we needed to add our method as a WebMethod if we wanted to call a method from the code-behind at the client side. Using this method, we can do it without calling our method in a WebMethod. In this example, I am writing a method to delete a particular user when the Delete key is hit. I don't want a postback so I want the event to execute on the client side. I write a Delete method on the server side in the CS file and call it from the client side using jQuery. This is my method in the CS file with the name DeleteRec(). private void DeleteRec() { int ID= Request.Form["ID"].ToString().ToInteger(); int UserID = Request.Form["UserID "].ToString().ToInteger(); UserBO lObjUserBO = new UserBO (); lObjUserBO .DeleteUser(ID, UserID ); } Here is how we call the method on page load:

Automatic Zip Extractor. Introduction Do you get annoyed when you have to do so many things just to open up a compressed file you just downloaded? You have to (Vista+): Right-click Click Properties Click Unblock Click OK Right-click Extract all Extract Delete the .zip file It's like so many other things in Windows, too much clicking and too many steps! Then, on XP machines, there's the problem that if the the Zip file has a ton of files inside which aren't inside of a sub-folder, you get a hundred files extracted to the same directory as the Zip file!

AutoExtractor unobtrusively sits in your system tray and monitors a directory you choose. If you don't want it popping in your face every time a Zip file is added to the folder, you can turn that option off in the settings and use a keystroke command Ctrl+K (or whatever key you choose) to pop up the window instead. Note: You must have the Microsoft .NET 4.0 framework installed to allow for keyboard shortcuts to work correctly.

The Code Points of Interest History. Fast Colored TextBox for syntax highlighting. Introduction For one of my projects, I have felt the need of a text editor with syntax highlighting. At first, I used a component inherited from RichTextBox, but while using it for a large amount of text I found out that RichTextBox highlights very slowly a large number of colored fragments (from 200 and more). When such highlighting has to be made in a dynamic way, it causes a serious problem. Therefore I created my own text component which uses neither Windows TextBox nor RichTextBox. The rendering of a text was made completely only by the means of GDI+. The component works fast enough with a large amount of text and also possesses tools to make comfortably dynamic syntax highlighting.

It has such settings as foreground color, font style, background color which can be adjusted for arbitrarily selected text symbols. Implementation For storage of characters of text, structure Char is used: public struct Char { public char c; public StyleIndex style; } Styles are stored in a separate list: Note: LINQ to Entities: Basic Concepts and Features. Download source code - 45.3 KB Introduction In my first three articles on CodeProject.com, I have explained the fundamentals of Windows Communication Foundation (WCF), including: From early this year, I have started to write a series of articles to explain LINQ, LINQ to SQL, Entity Framework, and LINQ to Entities.

Followings are the articles I wrote or plan to write for LINQ, LINQ to SQL, and LINQ to Entities: And as I said, after finishing these five articles, I will come back to write some more articles on WCF from my real work experience, which will be definitely helpful to your real world work, if you are using WCF right now. Overview In the previous article (Introducing LINQ—Language Integrated Query), we learned the new features of C# 3.0 including LINQ. In this article, we will cover the basic concepts and features of LINQ to Entities, which include: ORM—Object-Relational Mapping LINQ to Entities is considered to be one of Microsoft's new ORM products.

Entity Framework LINQ to Entities. Twitter OAuth authentication using .NET. Check Website’s Shared Count on Facebook and Twitter. How to use the event log. Build truly RESTful API and website using same ASP.NET MVC code. Getting the default record type of a user for Event Creation in Salesforce. DateTime extension method to give Week number. Resizing images while uploading in ASP.NET.

Excel

RSA private key import from PEM format in C# SIP SMS Example. C# Date Time Parser. XML Serialization of Generic Dictionary, Multidimensional Array, and Inherited Type, with sharpSerializer .NET. Calling a code-behind function from JavaScript. Windows Charting Application. Facebook Webpart for SharePoint. Cross Site Scripting... Load all the Country Names of the World in DropDown.