Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using a DLL - basic question

Using a DLL - basic question

Using a DLL - basic question

Hi there,

I have a website written in ASP classic that presents data from a SQL database.  I would now like to export the data as Excel and after some research have found that using EP Plus and .NET is one of the better ways of doing this.  

I am totally new to this and so far I have:

1.  Downloaded and installed Visual Web Developer 2010 Express on my PC
2.  Created a folder on the IIS server and converted it to an application
3.  Installed .NET framework 4 on server and configured application to use this.
4.  Added a line to my web.config file  <customErrors mode="Off"/>
5.  Copied EPPLUS.DLL to the folder on the IIS server where my project is.

Some sample code has been supplied on the EP Plus website:


private void DumpExcel(DataTable tbl)
            using (ExcelPackage pck = new ExcelPackage())
                //Create the worksheet
                ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");

                //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                ws.Cells["A1"].LoadFromDataTable(tbl, true);

                //Format the header for column 1-3
                using (ExcelRange rng = ws.Cells["A1:C1"])
                    rng.Style.Font.Bold = true;
                    rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));  //Set color to dark blue

                //Example how to Format Column 1 as numeric
                using (ExcelRange col = ws.Cells[2, 1, 2 + tbl.Rows.Count, 1])
                    col.Style.Numberformat.Format = "#,##0.00";
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;

                //Write it back to the client
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=ExcelDemo.xlsx");

So my questions for now are...

1.  I want to add a button to my default.aspx folder that runs the above code.  How do I 'tell' default.aspx about the epplus.dll file?

2.  Do I need to make a default.aspx.cs file and stick the code in there?  I can see there is a default.aspx.vb file so I think somehow I have selected the wrong language for the website?

Thanks very much

Ed Mozley

RE: Using a DLL - basic question

Yes, you picked the wrong language. You can't simply create a .cs file and make it work.

To bring in the DLL: In Visual Web Developer, open the project. Right-click on it, then Add References. Select the DLL. You will also need a using statement in the .cs file to bring the name space in.  

Craig Berntson
MCSD, Visual C# MVP, www.craigberntson.com/blog

RE: Using a DLL - basic question

Hi Craig,

Thanks for this - I have started again and made sure that I selected c# as the language for the website.

I have also added the reference to the DLL - it has now appeared under the bin folder in the solution explorer.

I've had a look at the default.aspx.cs file and at the start I can see some code which I think are the using statements you mention:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

On their FAQ (http://epplus.codeplex.com/wikipage?title=FAQ&amp;referringTitle=Documentation) it says the following under requirements:

"This library utilize the System.IO.Packaging namespace"

Does this mean I should add...


using System.IO.Packaging namespace

...to the code above?

Thanks a lot


RE: Using a DLL - basic question


After a bit more digging around I found I had to add a WindowsBase assembly reference.  This meant that when I typed the line:


using System.IO.Packaging;

I no longer get an error.  I  must admit at this stage I don't know what a namespace or an assembly reference is but nevertheless shall keep going...!

Now that I've done those two things what's next please?

Thanks again


RE: Using a DLL - basic question

Update - the website stopped working and after much digging around I found this article:


It told me that an application cannot be in the same application pool as another application that is using a different version of .NET.

I don't know what an application pool is but I made one called DOTNET4 and set my application to use that.

That got the page loading again but I still had lots of errors and after much googling and fiddling around found I had to change my code to include the following:


using System.IO.Packaging;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System.Data;
using System.Drawing;

This EP Plus seems very popular but it is REALLY badly documented and I don't understand why there is no working example out there!

The page now runs without any errors but nothing actually happens - what am I doing wrong?

My main chunk of code which is at the top is inside the public partial class - not quite sure how to call it though!



RE: Using a DLL - basic question

An assembly is simply a DLL or an EXE. A namespace is a logical organiztion of classes.  

Craig Berntson
MCSD, Visual C# MVP, www.craigberntson.com/blog

RE: Using a DLL - basic question

Hi; Don't panic. Spend some time for  videos on youtube for beginners. This will save a lot of time and arrange recent stuff you learned. How to add reference, button event, etc.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close