ASP.NET 4.6 Hosting Tutorial – How to Read & Show Excel Files in ASP.NET

Microsoft Office Excel is a spreadsheet-application which a good mean to store data in spreadsheet in a table (tabular) form. In this article, we will see how to display data (retrive data or read data) from an Excel spreadsheet using ASP.NET.

excel-round-function

We are going to read an Excel file in ASP.NET. Our ASP page will be on remote server and an Excel file in our desktop. First of all we need to upload it to a remote server and then retrive the data. So we are design a form to upload an excel. There will be possibility that we have to retrive data from a file again and again so we will rename Excel and then upload it.

<%@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”Default.aspx.vb” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Read and Display Data From an Excel File (.xsl or .xlsx) in ASP.NET</title>
<style type=”text/css”>
tr.sectiontableentry1 td,
tr.sectiontableentry2 td {
padding: 4px;
}
tr.sectiontableentry1 td {
padding: 8px 5px;
background: url(hline.gif) repeat-x bottom;
}
tr.sectiontableentry2 td {
padding: 8px 5px;
background: url(hline.gif) repeat-x bottom #F2F2F2;
}
</style>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table style=”padding: 5px; font-size: 11px;” align=”center” border=”0″>
<tbody>
<tr>
<td>
<strong>Please Select Excel file containing job details…</strong>
</td>
</tr>
<tr>
<td>
<div style=”background: url(hline.gif) repeat-x bottom #F2F2F2;padding: 8px 5px;border-bottom: 1px solid #ccc;”>
<asp:FileUpload ID=”txtFilePath” runat=”server”></asp:FileUpload>&nbsp;&nbsp;
<asp:Button ID=”btnUpload” runat=”server” Text=”Upload” /><br />
<asp:Label ID=”lblMessage” runat=”server” Visible=”False” Font-Bold=”True”
ForeColor=”#009933″></asp:Label>
</div>
</td>
</tr>
<tr>
<td>
<asp:GridView ID=”grvExcelData” runat=”server”>
<RowStyle CssClass=”sectiontableentry2″ />
<AlternatingRowStyle CssClass=”sectiontableentry1″ />
</asp:GridView>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</body>
</html>

Connection to Excel with Microsoft OLE DB Provider for Jet

The Microsoft OLE DB Provider for Jet(stands for Joint Engine Technology is a database engine) provides an OLE DB interface to Microsoft Access databases, and allows SQL Server 2005 and later distributed queries to query Access databases and Excel spreadsheets. We will connect to a Microsoft Excel workbook using the Microsoft OLE DB Provider for Jet 4.0, read data and then display the data in a GridView.

xlsx (Excel 2007) contains Microsoft.ACE.OLEDB.12.0 as the provider. This is the new Access database engine OLE DB driver and is also capable of reading Excel 2003. We are going to use it to read xlsx (Excel 2007) data.

We have a excel file whose content are as shown below. Note here sheet name must be same, means if want to read data from Sheet1. You must take care while writting SQL query because SELECT * FROM [Sheet1$] and SELECT * FROM [sheet1$] are two different queries.

Excelldata

VB.NET Code

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
If (txtFilePath.HasFile) Then
Dim conn As OleDbConnection
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim query As String
Dim connString As String = “”
Dim strFileName As String = DateTime.Now.ToString(“ddMMyyyy_HHmmss”)
Dim strFileType As String = System.IO.Path.GetExtension(txtFilePath.FileName).ToString().ToLower()

‘Check file type
If strFileType.Trim = “.xls” Or strFileType.Trim = “.xlsx” Then
txtFilePath.SaveAs(Server.MapPath(“~/UploadedExcel/” & strFileName & strFileType))
Else
lblMessage.Text = “Only excel files allowed”
lblMessage.ForeColor = Drawing.Color.Red
lblMessage.Visible = True
Exit Sub
End If

Dim strNewPath As String = Server.MapPath(“~/UploadedExcel/” & strFileName & strFileType)

‘Connection String to Excel Workbook
If strFileType.Trim = “.xls” Then
connString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & strNewPath & “;Extended Properties=””Excel 8.0;HDR=Yes;IMEX=2″””
ElseIf strFileType.Trim = “.xlsx” Then
connString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” & strNewPath & “;Extended Properties=””Excel 12.0;HDR=Yes;IMEX=2″””
End If

query = “SELECT * FROM [Sheet1$]”

‘Create the connection object
conn = New OleDbConnection(connString)
‘Open connection
If conn.State = ConnectionState.Closed Then conn.Open()
‘Create the command object
cmd = New OleDbCommand(query, conn)
da = New OleDbDataAdapter(cmd)
ds = New DataSet()
da.Fill(ds)

grvExcelData.DataSource = ds.Tables(0)
grvExcelData.DataBind()

da.Dispose()
conn.Close()
conn.Dispose()
Else
lblMessage.Text = “Please select an excel file first”
lblMessage.ForeColor = Drawing.Color.Red
lblMessage.Visible = True
End If
End Sub

C#.NET Code

protected void btnUpload_Click(object sender, EventArgs e)
{
if ((txtFilePath.HasFile))
{

OleDbConnection conn = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
string query = null;
string connString = “”;
string strFileName = DateTime.Now.ToString(“ddMMyyyy_HHmmss”);
string strFileType = System.IO.Path.GetExtension(txtFilePath.FileName).ToString().ToLower();

//Check file type
if (strFileType == “.xls” || strFileType == “.xlsx”)
{
txtFilePath.SaveAs(Server.MapPath(“~/UploadedExcel/” + strFileName + strFileType));
}
else
{
lblMessage.Text = “Only excel files allowed”;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Visible = true;
return;
}

string strNewPath = Server.MapPath(“~/UploadedExcel/” + strFileName + strFileType);

//Connection String to Excel Workbook
if (strFileType.Trim() == “.xls”)
{
connString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + strNewPath + “;Extended Properties=\”Excel 8.0;HDR=Yes;IMEX=2\””;
}
else if (strFileType.Trim() == “.xlsx”)
{
connString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” + strNewPath + “;Extended Properties=\”Excel 12.0;HDR=Yes;IMEX=2\””;
}

query = “SELECT * FROM [Sheet1$]”;
//query = “SELECT [Country],[Capital] FROM [Sheet1$] WHERE [Currency]=’Rupee’”
//query = “SELECT [Country],[Capital] FROM [Sheet1$]”

//Create the connection object
conn = new OleDbConnection(connString);
//Open connection
if (conn.State == ConnectionState.Closed) conn.Open();
//Create the command object
cmd = new OleDbCommand(query, conn);
da = new OleDbDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);

grvExcelData.DataSource = ds.Tables[0];
grvExcelData.DataBind();

lblMessage.Text = “Data retrieved successfully! Total Records:” + ds.Tables[0].Rows.Count;
lblMessage.ForeColor = System.Drawing.Color.Green;
lblMessage.Visible = true;

da.Dispose();
conn.Close();
conn.Dispose();
}
else
{
lblMessage.Text = “Please select an excel file first”;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Visible = true;
}
}

We have tested above code and got result as shown below:

Retrieved_Excel_data


ASP.NET 4.6 Hosting with HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. They deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. They have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.

awards-03.pngHostForLIFE.eu is Microsoft No #1 Recommended Windows and ASP.NET Hosting in European Continent. Our service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and many top European countries.

HostForLIFE.eu Hosting is the first host to offer its customer all the new features of the ASP.NET 4.6 Hosting. You can simply deploy your ASP.NET 4.6 website via our world-class Control Panel or conventional FTP tool. This ASP.NET 4.6 Hosting is part of HostForLIFE.eu service and it is provided free of charge.

Top Best & Cheap jCore Hosting 2016

To choose the jCore Hosting for your site, we recommend you going with the following Best & Cheap jCore Hosting company that are proved reliable and sure by our editors. Here is a summary of key improvements available in JCore  hosting:

Choosing the Best & Cheap jCore Hosting

jCore is a Multi Site web Content Management System build especially for webmasters (using the well known LAMP environment) who have to maintain multiple websites for their clients and they would like to keep the source codes up to date and easily fix bugs for all clients at once.

microsoft-660x300

jCore has two main systems, jCore Server – which holds all the libraries and modules you can build on, andjCore Client – which is the stripped version of the core system without any libraries as it uses the ones from the core.

Think of jCore server as the library for your site/program and jCore client as the website that you show to the public. In multi site setup you don’t even have to install jCore server, just copy the files in a public place where all your client sites can access it and that’s it, just like you would build a program by using a library. This way when you upgrade to a new version you just overwrite the old jCore server files with the new ones and all your client sites are already “upgraded”.

If you want to grow your business framework, surely you need to make a design with the best use of the technology platform to connect your business. The most important technology that is used to design the business is jCore Hosting development.jCore Hosting is used as a model of a proven technology platform to implement a model-view-controller that is able to give the developers a powerful method for building and designing dynamic websites.jCore Hosting has released with several attribute routing improvements, feature updates and bug fixes. Due to the improvements on jCore Hosting, many web hosting providers are interested to provide jCoreHosting. In order to help you choosing the best and recommended jCore Hosting provider, we have reviewed several web hosting providers and found this hosting provider below can provide you the best and recommended jCore Hosting.

jCore Hosting
Shared Hosting Features Fully Support jCore Hosting
Easy to Use Control Panel Support SQL 2016
 24/7 Tech Support Use Windows Server 2008 R2 and above
99.9% Uptime Guarantee Support ASP, ASP.NET, PHP or even CGI
 Wordclass Data Center Experts on ASP.NET Core 1.0
There’s a money back guarantee

Best & Cheap Recommendation jCore Hosting

HostForLIFE.eu, ASPHostPortal.com and UKWindowsASP.NET are quality hosting providers that offer the best and recommended jCore Hosting services. While it may be true that many web hosting providers will be capable in hosting the jCore Hosting platform, however, there is a definitive difference between a web hosting company that only support jCore Hosting and one that will provide a superior service with no surprise malfunctions. The smartest option is to choose a hosting provider that has experience of hosting jCore Server . Here is a brief overview of our 3 highly best and recommended jCore Hosting Hosting providers that are proving popular with jCore Hosting users :

logo_hflukwindowsasp.netlogo-asphostportal
Unlimited Domain5 DomainHost Unlimited Sites
Unlimited Bandwidth20 GBAnytime money back
Unlimited Disk Spaces1 GB99.9% hosting uptime
Full trust level 24×7 US support24×7 US support
Latest MSSQLLatest MSSQLLatest MSSQL
Latest MySQLLatest MySQLLatest MySQL
24×7 tech supportFree Cloud HostingASP.NET, MVC, Silverlight, URLRewrite2, WebMatrix
ASP.NET 1.1/2/3.5/4/5SP1/4.5, MVC 4/5, /5/6URLRewrite2ASP.NET 1.1/2/3.5/4/5SP1/4.5, MVC 4/5, /5/6URLRewrite2ASP.NET 1.1/2/3.5/4/5SP1/4.5, MVC 4/5, /5/6URLRewrite2
Support IIS 7/8/8.5ASP.NET, MVC, Silverlight, URLRewrite2, WebMatrixSupport IIS 7/8/8.5
More Details More Details More Details

ASPHostPortal.com offers the foremost effective jCore Hosting Hosting  plans ever. In reality, they feature the absolute most reasonable jCore Hosting arrange at $5 per month. Now, this is often fully a cost to beat. This budget vary is really cheap so it garnered ASPHostPortal.com the most effective Budget jCore Hosting Provider title.

For starters, you need to be able to reach whoever with your questions, comments, and concerns, any time of the day or night. With a great number hosting providers keeping the same hours that your employers do, it can be difficult to work on your website or internet business unless you are already doing it full-time. Unfortunately, this is not possible for a great number Internet entrepreneurs starting out. ASPHostPortal.com and some of the other veteran companies out there post user service expert at your beckon call any time of the day or night. If you have any technical issues or questions with regard to the service, billing-virtually anything-then you can catch way outs through a ticketing system or email service.

But basic questions of functionality can often be taken care of through the use of an intuitive control panel like Plesk. Plesk web hosting allows you to make most of the key decisions with regard to how your site looks and operates. Since it is so easy to work with, a great number site owners and internet business expert can forgo the hiring of a technical wizard to make updates and upgrades to the site. This places more control and a better sense of understanding in one’s own hands and enables the creation of a website one can truly be proud of.


UKWindowsHostASP.NET is a hosting service that offers full functionality for your business or individual needs at reasonable prices. The hosting services on the internet representation comes in region-specific versions indicating its good standing amongst internet hosting customers.

ukwindowsasp.netUKWindowsHostASP.NET gives jCore Hosting plans; Starter, Economy, Developer, and Enterprise. Their plan starts from £3.00/month – £17.00/month with complete ASP.NET Core 1.0 RC2 Hostingfeatures, Money back guarantee, 24/7 customer support, daily backup service, and powerful server technology.

ukwindowshostaspnet

UKWindowsHostASP.NET also claims to have 99.99% uptime. This is partly supported by the availability of UPS backup and partly through redundant servers. Extensive industry survey and analysis shows that the uptime is approximately 99%, which isnt poor for the cost. Just like all other hosting services, the firm has a reliable and efficient customer service, which is accessible via ticketing system and e-mail. The statistics corresponding to resolution of issues suggest that the customer service response time is comparatively high as compared to other competitors from the business.


With the amount of jCore Hosting firms around, choosing jCore Hosting services might be described as a little tough, most especially if you’re not a technical person and a beginner on the earth of online promoting. So as to settle on the best hosting company though, you would like to establish necessary factors to take under consideration in choosing an jCore Hosting.

Some of the basic needs of internet hosting include disk house, bandwidth, and domain name. However, different functions would possibly be required with respect to the wants of a specific web site. Generally, Most of all Companies need jCore Hosting in their hosting service, in a very method that jCore Hosting will be one of many vital requirements of Windows hosting.

hostforlifebanner

While a ton of the Windows hosting corporations nowadays offer the essential needs within their services, they vary in arrange rates, performance, and add-on options. Undoubtedly even the smallest differences within the hosting rates matter most particularly if you’re on a good budget. Thus, although hosting options are greatly thought-about in choosing a website host, the affordability is equally thought-about further.

Certainly one of the foremost in style ASP.NET hosting companies giving most of the features that can be necessary for private and business websites is HostForLIFE.eu. HostForLIFE.eu is one of many biggest jCore Hosting hosts with a platform that serves a lot of than 2000 websites everywhere the globe. This undoubtedly shows they’re among in all probability the foremost trusted and the most most popular jCore Hosting firms today.

ASP.NET Core 1.0 Hosting Tutorial – How To Find & Use Session in ASP.NET Core 1.0

If you’re just starting to develop in ASP.NET, you may not have encountered Session before. Session is a serialized collection of objects that are related to the current user’s session. The values are usually stored on the local server memory, but there are alternate architectures where the values can be stored in a SQL database or other distributed storage solutions, especially when your servers are part of a server farm. In this tutorial, we will show you how to find and use session in ASP.NET Core 1.0.flat-vector-design-illustration-of-modern-business-office-and-workspace-600x500

Finding Session in ASP.NET Core 1.0

ASP.NET Core 1.0 has been written from the ground up to be a modular, choose-what-you-need framework. What this means is that you must explicitly include any packages you want to use in your project. This allows developers to maintain tight control over what functionality our ASP.NET Core projects actually need, and exclude anything that is not necessary.

Step 1

Session is considered to be one of “additional” packages.  In order to include that package we need to add a reference to Microsoft.AspNet.Session in the project.json file. If we wanted to use memory as our caching backend, we would also include Microsoft.Extensions.Caching.Memory.

Finding Session in ASP.NET Core 1.0 (1)

Step 2

Once we’ve got the package included in our project, we need to make it available to the Services layer by modifying the ConfigureServices() method in the Startup file, like so:

Step 3

However, that isn’t quite enough to get Session fully integrated into our project. We also need to inject the Session service into our Dependency Injection container in the Startup file’s Configure() method, like so:

With all of these steps completed, you can now use Session in your projects just like in any other ASP.NET application. If you wanted to use a different cache backend (rather than memory) you could grab a different NuGet package like Redis or SqlServer. Don’t forget to check NuGet if you can’t find the functionality you need; it is probably there and you just need to download it.

Using Session in ASP.NET Core 1.0

ASP.NET Core 1.0 has introduced some new extension methods that we can use for accessing and storing Session values. The odd thing is that these extensions are not in Microsoft.AspNet.Session; rather, they are in Microsoft.AspNet.Http, and so we will need to add that package.

Using Session in ASP.NET Core 1.0 (1)

Once we’ve got that package included, we can start using the extension methods:

The new extension methods are:

  • Get: Returns a byte array for the specified Session object.
  • GetInt: Returns an integer value for the specified Session object.
  • GetString: Returns a string value for the specified Session object.
  • Set: Sets a byte array for the specified Session object.
  • SetInt: Sets an integer value for the specified Session object.
  • SetString: Sets a string value for the specified Session object.

Best and Recommended ASP.NET Core 1.0 Hosting

If you are looking at creating website of your own, hosting it with ASP.NET Core 1.0 can be a great choice. While there are various companies today who offer you ASP.NET Core 1.0 hosting services, it is extremely important for you to understand and compare the features that various companies offer. To make this search easier for you, we have listed down top 3 hosting providers which you need to compare for the best and recommended ASP.NET Core 1.0 hosting.