Tag Archives: ASP .Net

Create Excel Report Programmatically Without Installing MS Excel. Asp.Net & Win Form C# Using WebService Example

Assuming you only have open source spreadsheet software i.e OpenOffice.org Calc and you want to make Excel report file programmtically.
You dont have MS Office installed in your computer or server. Sure you can do it using ExcelLibrary library from Google Apps.

In order to try examples in this blog post, please download ExcelLibrary library from this url https://code.google.com/p/excellibrary/downloads/list

Here, I give examples implementing it by creating a WebService so that Asp.Net Website or Win From C# can use this WebService.
This makes ExcelLibrary file only have to copy in WebService’s server without distribute it to local / client box.

First of all we need to know about basic of ExcelLibrary usage. Taken from https://code.google.com/p/excellibrary

//create new xls file
string file = "C:\\newdoc.xls";
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet("First Sheet");
worksheet.Cells[0, 1] = new Cell((short)1);
worksheet.Cells[2, 0] = new Cell(9999999);
worksheet.Cells[3, 3] = new Cell((decimal)3.45);
worksheet.Cells[2, 2] = new Cell("Text string");
worksheet.Cells[2, 4] = new Cell("Second string");
worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");
worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY\-MM\-DD");
worksheet.Cells.ColumnWidth[0, 1] = 3000;
workbook.Worksheets.Add(worksheet);
workbook.Save(file);

// open xls file
Workbook book = Workbook.Load(file);
Worksheet sheet = book.Worksheets[0];

 // traverse cells
 foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
 {
     dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
 }

 // traverse rows by Index
 for (int rowIndex = sheet.Cells.FirstRowIndex; 
        rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
 {
     Row row = sheet.Cells.GetRow(rowIndex);
     for (int colIndex = row.FirstColIndex; 
        colIndex <= row.LastColIndex; colIndex++)
     {
         Cell cell = row.GetCell(colIndex);
     }
 }

Continue reading

Asp.Net & ORM Tool NHibernate For Dummy Tutorial – Update & Delete Operation

NHibernate is a open source Object-Relational Mapping (ORM) tool. This ORM tool hides sql query complexities by replacing query with mapping and class object.

I already have article about basic NHibernate in previous post. If you are new to Nhibernate then I recommend to Click here Asp.Net & ORM Tool NHibernate For Dummy Tutorial – Select & Insert Operation first.

Lets recap what we have to do to work with NHibernate.

  1. Download necessary NHibernate file including NHibernate.dll & configuration template/example at http://sourceforge.net/projects/nhibernate
  2. Create xml mapping file and a class which representates DB table
  3. Include Nhibernate dll file, NHibernate xml configuration file, class library (if you have separate class project), and Asp.Net file it self
  4. Write codes inside the Asp.Net file that contains NHibernate configuration class object initialization, AddAssembly to Class Library, BuildSessionFactory, OpenSession, BeginTransaction, SaveOrUpdate, Commit to save data to DB.
  5. Write SQL Query replacement with QueryOver<T>() method and Where filter (if necessary) that has LinQ like syntax to retrieve record(s) and automatically convert to a class

Continue reading

Asp.Net & ORM Tool NHibernate For Dummy Tutorial – Select & Insert Operation

NHibernate is a open source Object-Relational Mapping (ORM) tool. This ORM tool hides sql query complexities by replacing query with mapping and class object.
Every .Net Project can use Nhibernate to work with database.

The purpose of NHibernate is to save developers work time thus increasing productivity. Large application may get more benefit from NHibernate than small app.

This blog post gives Asp.Net & NHibernate dummy examples. These examples cover select / retrieve records and insert a new record.

First thing first, we need to download Nhibernate files. Please download the zip file from http://sourceforge.net/projects/nhibernate/

As a brief, we need xml mapping file, a class which representates DB table, Nhibernate dll file, NHibernate xml configuration file, and Asp.Net file it self that contains NHibernate configuration object, NHibernate session etc to provide data to UI.

I use VS 2010 Express & SQL Server 2008 R2 to build this example.
Continue reading

Asp.Net Nested Grid View Example And Ajax PopUp & Calendar Extender


Nested Grid View is useful to show parent child relationship table. This blog post contains example to build Nested Grid View with Asp.Net.
The Parent Grid View content can be Edited and its Child Grid View loads on the fly if user clicks on parent grid view row.

I use Northwind Sample Database to produce nested Grid View. Also I use DropDownList, TextBox with Ajax PopUp and TextBox with Ajax Calendar to filter database query.
I already have example about Ajax Popup & Calendar in this Url Making Flexible User Input With Asp.Net Ajax PopUp & Calendar Extender Toolkit Controls .

So this blog contains miscelanous example. This might be useful for web internal application that contains complex user input & data layout.
Continue reading

Making Flexible User Input With Asp.Net Ajax PopUp & Calendar Extender Toolkit Controls


Complex user input design occurs oftenly in web app. Some of requirements need multiple inputs.
Using standard textbox, radio button, check box, combo box will resulting long and a lot of form elements with so many page refresh thus this is not good enough.
Application User Easiness of use requires simple process so we need to shorten & tidy up the look & feel of UI interface.

We need more sophisticated controls to accomplish that requirement. Fortunately, Asp.Net have Ajax PopUp Extender Control.
We can create several/combined inputs inside PopUp Extender and user see it as one control. Since this control is ajax enabled then when PopUp process is happening, page will only reload partially.

Other example I want to share in this blog post is Calendar Extender Toolkit. This is basically Ajax DatePicker.

Generally, we need a textbox, PopUp panel and PopupControlExtender to form a PopUp. This textbox act as trigger also target control, PopUp panel as the popup it self and PopupControlExtender is a controller that connect popup panel with target textbox.
Continue reading

Asp.Net Ajax Client Network Calls Techniques With WebRequest & WebRequestManager

Ajax Network Calls is almost being most extensively used on web application. Client calls a page on Url via javascript and the Url’s content is being stored in a variable as a string.
This variable can be written on html element like div element. Traditional ajax is basically a network call.

We can use ajax network call technique to populate combo box or select element from database, Auto complete function, search records, update, insert record etc.

I’ll give examples of ajax network calls techniques using client script Sys.Net.WebRequest class. We will use this client side class in javascript.
Remember that we have to put ScriptManager control in aspx page to enable Asp.Net ajax extension.

Web Request Example

I have two textboxes which their ids are txname and txage. After user enters his/her name, age and clicks “Go” button, current date and time will be displayed in div element along with entered values in each textboxes.

Continue reading

SSRS 2008 R2 Programmatically List Running Reports/Jobs & Cancel Examples

SSRS 2008 R2 does not have pre built List Running Reports in Web format that comes from installation. Unlike the older version: SSRS 2005, we have to use SQL Server Management Studio (SSMS) to see SSRS 2008 R2 running reports / jobs .

The lack of this pre built web format is kind of missing in my day to day monitoring because of SSRS 2008 R2 List running jobs view in SSMS shows only the report name in the first look.
I have to look at each jobs properties to see more details which means more clicks are required.

The below screen shot shows the older version: SSRS 2005 list running Reports:

Steps to show SSRS 2008 R2 list running Reports with help of SSMS are:

  1. Open SSMS 2008 and connect to Reporting Service server.
    Set Server Type field to Reporting Service. Server Name set to Url http://<myserveripaddress>/reportserver. Replace the <myserveripaddress> to your report server ip address.
    Authentication, UserName and Passwd depend to your environment. If your localhost is Reporting Service server then you can use Window Auth.
    Otherwise if the server is a remote server then use basic/form auth. Anyway just try it.
  2. Open Jobs folder to see running Reports. Refresh it to see current jobs.
  3. Double click to see more details at each job
  4. Cancel Job(s) by right click job and click ‘Cancel Job(s)’

Alternatively, we can build our own list running reports/jobs tool. SSRS has a built in class to show running Reports programmatically. The class is ReportingService2010 for SSRS 2008 R2. This class is accessed via web service. The Url path of this webservice is http://<myserveripaddress>/ReportServer/ReportService2010.asmx.
In this blog post, I give you examples of programmatic SSRS 2008 R2 List running jobs.
Continue reading