Design Patterns - The Best Practices
Few years back, design patterns for .net developers were less known though it is widely being used by java developers.
So as .net languages and developers got more matured over the time, people started looking for .net code optimization, performance, best practices, extensibility and maintainability of the code side.
First obvious question about making use of design patters is why? Why we should implement design patterns in our solutions/applications.
Well I will try to read and make notes of why and how of design patterns and share in this series. So let begin.
1. Why design patterns? What benefit I will get?
Productivity: Design pattern helps to build an architecture which can enhance the productivity.
Extensibility: When a software is released and becomes successful and widely accepted it is obvious that it will receive lots of request change and updates. So if while building the application proper design patterns is implented it will be easy to supply those updates and request. Most design patterns promote the idea of coding against interfaces and base classes, which makes it easier to change and enhance your application at a later stage.
Simplicity: Our solution architecture should be simple, well thought out, clean, crisp and easy to understand. This can be acheived by knowing the design pattern in advance.More...
Import/Export E worksheet using ADO.Net
Excel is very known format for storing small amount of data. So you may want your data residing in ms sql or oracle or any other data source do be exported because of any of the following reason:
- Running calculation to derive the wanted information
- Doing some statistical computation like MEAN, MEDIAN, MODE
- Generating Graphical report
- Making use of PivotTable and PivotChart
Apart from above listed one there exists also lots of other reasons to export data in excel format. Similarily we can use excel to do bulk import of data and put it into sql server database. It is very easy and faster to do data entry in excel sheet and then import those data to rdbms system.
Export to Excel from SQL Server:
There are may ways we can read data from sql server and export to excel sheet like using third party controls, binding data to some data controls and then exporting using "GridView.RenderControl()" method.
But here I am going to show how to export from sql server to ms excel using ado.net.
1. Create an asp.net website project named "ExcelExportImport" and 2 folders to it "DownloadFiles" and "UploadFiles".
2. Download AdventureWorksLT2008 database and attach ot your sql server database. More...
Developing Image upload web user control with image preview in asp.net:
As a developer working for content management system/ecommerce/blogging/social sites development, one most frequent task is image upload.
We spend lots of time dragging/dropping file control, upload button and writing code to check for file extension and then uploading the image on the site in specified directory location.
And if one wants to show the preview this task gets even much lengthier.
Keeping this in mind I wrote a web user control which is generic in nature and can be just used on any page with little configuration and offcourse no code rewriting.
Also this user control is bindable and has image preview if choosen. So this can be used inside data grid view/form view/list view/repeater/details view/data list control by just dragigng and dropping.
So lets start building image upload web user control with preview (optional):
1. Add a web user control to your website project.More...
C#/Asp.Net - Uploading multiple files like Gmail/Orkut
There are several ways of supporting multiple file upload in asp.net based on the requirements. Below are few ways that we can do coding to support multiple file uploads in asp.net:
1. If we fix number of files to be uploaded, we can place that many FileUpload control while designing the page.
So lets see the complete code. Screenshots of the code: