Tag Archives: WebService

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;

// 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

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

How to Show Data from Any Source such as Array, DataTable, WebService and Database Using Asp.Net ListView and ObjectDataSource

A web page is about to show a data. This data may generate from database or other object like an class instance.

Mostly, data is presented to a table and a lot of tutorial about making a table that I have is related to database. Developers have a listview / gridview / repeater etc for data view and sqldatasource control as a data source.

Although sqldatasource is good and may increase productivity. An organisation is not always use SQL Server and one of their web tables may not use database at all.

So I prefer to use ObjectDataSource control. This control is more generic data source because we use our own bare class to return a DataTable instance. Since we write our own class then inside it we can code an operation to any RDBMS or work with any objects.
ObjectDataSource control is also good option to retrieve data via Web Service from another Server and maybe that Server is located at different site. We cant see any code like database connection in Web Service but only class and namespace reference of it. Although maybe there is a database operation inside Web Service itself.

In this blog post, I generate the data manualy to DataTable in the first example and secondly, I generate it from webservice and database. Both of them show data via listview and use arbitrary class that I make. ObjectDatasource acts as bridge between this custom class instance and listview.

Adding Data Manualy to DataTable

Here’s the example:
I will show simple table that has persons info with their name, city and province.
.aspx file (piece of code):


Continue reading

Introduction To Asp .Net Ajax 3 (ScriptManagerProxy)

“ScriptManagerProxy Class enables nested components such as content pages and user controls to add script and service references to pages when a ScriptManager control is already defined in a parent element.”
Source: http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanagerproxy.aspx

As you may know by now the ScriptManager manages all resource of Asp .Net Ajax. ScriptManager is a must have control to enable Ajax functionality.
We can include service and Javascript reference inside ScriptManager.

However Asp .Net enables only one ScriptManager component at a page. If you need to add another reference then use ScriptManagerProxy instead.
This is useful when you put ScriptManager at MasterPage and then you can extend custom functionallity using ScriptManagerProxy i.e to add Ajax Client Js File in your content page.
You can have reference to common Ajax Js script or web service at MasterPage and then you add custom Js script inside your specific custom page.
Also this ScriptManagerProxy avoid wasteful resource by referencing only a web service or script that needed by a page. Not all reference is included in ScriptManagerProxy, we have only common reference in Parent ScriptManager.

I give you an example of making above scenario using ScriptManagerProxy in this post. I create a master page containing ScriptManager component that reference to a web service.
This web service will return a product stock qty balance. Also I have a content page that shows product stock using ScriptManagerProxy that reference to Js script to access the web service method.


Continue reading

[Resolved]Cannot Consume/Access/Use Asp .Net Classes in App_Code / Bin folder and WebService ‘Compilation Error’


We can create Asp .Net classes or bussiness objects inside App_Code or using compiled library .dll file in Bin folder.
Alternatively classes may be write inside WebService. If nothing is wrong then we can access our web app classes when it is launched via Visual Studio.
Unfortunately, after we deploy it to IIS and try to access deployed classes or WebService an error “Compilation error .. Type xxx is not defined ..” occurs.


Let’s make a New Website Asp .Net Empty Web Application to make problem and solution clear.
Continue reading