European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

European ASP.NET 4.5 Hosting - UK :: Zip File Manipulation in ASP.NET 4.5

clock December 11, 2014 08:16 by author Scott

One of the missing feature of .NET framework was a support for Zip file manipulation such as reading the zip archive, adding files, extracting files, etc. and we were using some third party libraries such as excellent the DotNetZip. In .NET 4.5, we have an extensive support for manipulating .zip files.

First thing that you should do is to add System.IO.Compression assembly as reference to your project. You may also want to reference System.IO.Compression.FileSystem assembly to access three extension methods (from the ZipFileExtensions class) for the ZipArchive class: CreateEntryFromFile,CreateEntryFromFile, and ExtractToDirectory. These extension methods enable you to compress and decompress the contents of the entry to a file.

Let’s cover the bits and pieces that we get from System.IO.Compression assembly at first. The below sample shows how to read a zip archive easily with ZipArchive class:

static void Main(string[] args) {

    const string zipFilePath = @"C:\apps\Sample Pictures.zip";

    using (FileStream zipFileToOpen = new FileStream(zipFilePath, FileMode.Open))
    using (ZipArchive archive = new ZipArchive(zipFileToOpen, ZipArchiveMode.Read)) {

        foreach (var zipArchiveEntry in archive.Entries)
            Console.WriteLine(
                "FullName of the Zip Archive Entry: {0}", zipArchiveEntry.FullName
            );
    }
}

In this sample, we are opening the zip archive and iterate through the collection of entries. When we run the application, we should see the list of files inside the zip archive:

It’s also so easy to add a new file to the zip archive:

static void Main(string[] args) {

    const string zipFilePath = @"C:\apps\Sample Pictures.zip";

    using (FileStream zipFileToOpen = new FileStream(zipFilePath, FileMode.Open))
    using (ZipArchive archive = new ZipArchive(zipFileToOpen, ZipArchiveMode.Update)) {

        ZipArchiveEntry readMeEntry = archive.CreateEntry("ReadMe.txt");
        using (StreamWriter writer = new StreamWriter(readMeEntry.Open())) {
            writer.WriteLine("Lorem ipsum dolor sit amet...");
            writer.Write("Proin rutrum, massa sed molestie porta, urna...");
        }

        foreach (var zipArchiveEntry in archive.Entries)
            Console.WriteLine(
                "FullName of the Zip Archive Entry: {0}", zipArchiveEntry.FullName
            );
    }
}

In this sample, we are adding a file named ReadMe.txt at the root of archive and then we are writing some text into that file.

Extracting files is into a folder is so easy as well. You need reference the System.IO.Compression.FileSystem assembly along with System.IO.Compression assembly as mentioned before for this sample:

static void Main(string[] args) {

    const string zipFilePath = @"C:\apps\Sample Pictures.zip";
    const string dirToExtract = @"C:\apps\Sample Pictures\";

    using (FileStream zipFileToOpen = new FileStream(zipFilePath, FileMode.Open))
    using (ZipArchive archive = new ZipArchive(zipFileToOpen, ZipArchiveMode.Update))
        archive.ExtractToDirectory(dirToExtract);
}

There are some other handy APIs as well but it is so easy to discover them by yourself. 



European ASP.NET 4.5 Hosting - UK :: How to Use ListView Control in ASP.NET 4.5

clock July 24, 2014 08:49 by author Scott

ASP.NET 4.5 offer many great feature. Previously, we have discussed about one of new feature on ASP.NET 4.5, Key HTML Editor Features in ASP.NET 4.5. In today post, we will discuss about how to use ListView Control in ASP.NET 4.5

ASP.NET ListView Control has a great features that GridView and Repeater controls had control over the markup. The ListView Control allows you to display the data in various formats including grid format, bulleted list format and in flow format.

How to Insert and Delete Data with the ListView Control

OK, let’s get started

1. Drag the ListView control from data category of the toolbox to default.aspx page and choose the datasource for the control as shown below

2. Configure ListView option from ListViewControl smart tags as shown below

Provide the template information by selecting the desired template and also it allows you to select style for control. It also allows you to enable operations such as inserting and updating.

3. Add some custom styling to the control by adding a class as shown below

<LayoutTemplate>
            <ul id="itemPlaceholderContainer" runat="server" class="ItemStyle">
                <li runat="server" id="itemPlaceholder" />
            </ul>
</LayoutTemplate>

4. Remove the Id columns from ItemTemplate as these mark-ups generated automatically when you configure the control and columns. Repeat the same for InsertItemTemplate.

5. Add the custom styles to item containers as below

.ItemStyle
{
  width: 800px;
  list-style-type:none;
  clear:both;
}

.ItemStyle li
{
  height: 300px;
 width:250px;
 float:left;
}
.ItemStyle li img
{
 width:180px;
margin: 10px 20px 10px 0;
}

6. Run your application and you’ll see the result

Hosting Your ASP.NET 4.5 Site with HostForLIFE.eu

If you need/looking for cheap and reliable ASP.NET 4.5 hosting with European server, you can rely on us. We have support the latest ASP.NET 4.5 on our shared hosting environment. You can always start from only €1.29/month to test drive your new ASP.NET 4.5 application. Why wait longer??



FREE ASP.NET 4.5 Hosting UK - HostForLIFE.eu :: How can HostForLIFE.eu Guarantee Our Windows ASP.NET 4.5 Hosting Service?

clock March 24, 2014 07:05 by author Scott

Only focusing on ASP.NET hosting service, HostForLIFE prove ourselves to be one of the best ASP.NET hosting providers that offer the most highlights, although there are thousands of ASP.NET hosting companies on the market. In below, we have listed our main features that has integrated with our 4 ASP.NET hosting plans.

Offering Many Excellent Features

- 1-Click Application Installer

In the HostForLIFE control panel, there is a 1-click web application installer for convenient installation of many popular open source web applications, including PHP apps like WordPress, Joomla, Drupal and phpBB, and ASP.NET applications like DotNetNuke, nopCommerce, BlogEngine and Orchard.

- PHP & MySQL

In the past, PHP didn't run well on a Windows server, but over the last several years, Microsoft has improved IIS and now PHP runs vey well on Windows hosting platforms, which means famous open source apps like Joomla, WordPress and Drupal can run well on HostForLIFE Windows hosting plans.

In addition, by supporting MySQL as part of their Windows hosting platform, a popular open source relational database system, HostForLIFE enables customers to use a lot of popular open source apps.

- ASP.NET 4.5.1 Hosting

We support ASP.NET 4.5.1 hosting on our Windows 2012 platform, which is compatible with Visual Studio 2013/2012, and our Windows 2008 hosting platform also fully supports ASP.NET 4.0 and is compatible with Visual Studio 2010, which enables customers' applications to be written in any language that is compatible with the common language runtime, including Visual Basic and C#.

- SQL Server

HostForLIFE always improve our technology and we always up to date with the Micorosoft technology. We offer the latest SQL 2012 version. We also support integrated full text search, stored procedures and ASP.NET SQL Session, which makes their customers get DBO right and manage SQL database remotely using SQL Management Studio or SQL Management Studio Express.

- Windows 2012 Hosting

We use Windows server 2012 – the latest Windows operating system comes with IIS8 to deliver customers with more options for their web applications including support for .NET, ASP and PHP. What's more, they support Full Trust to make customers' sites isolated from one another for greater reliability and security.

Utilizing Cutting-Edge Facilities & Infrastructures

HostForLIFE uses a state-of-the-art data enter which is featured with UPS backup power, diesel generators, firewall protection and 24×7 security. Moreover, we houses dual quad Dell servers that are 100% factory built and tested, coming with the best specification of 64 bit software, 32 GB of RAM, and RAID 10 disk arrays. All of the first-class facilities and infrastructures enable HostForLIFE to provide satisfying uptime and fast hosting speed for our customers to run websites smoothly and stably.

Providing Quality Technical Support

As one of the most reliable hosting companies, HostForLIFE offers quality technical support powered by a group of support staffs through email, all of who are professional, knowledgeable, experienced and on-site 24×7, so that we are able to give quick response and effective assistance to troubled customers to resolve problems.

In addition, in our online knowledgebase and blog, HostForLIFE technicians and engineers have worked out a lot of in-depth articles to teach customers how to deal with common issues independently.



European ASP.NET 4.5 Hosting - HostForLIFE.eu :: Send Bulk Email Using ASP.NET 4.5

clock January 22, 2014 05:58 by author Scott

This article explains how to send bulk email using ASP.Net 4.5. You can use:

  • ASP .NET web page
  • Grid View
  • HTML Email Templates
  • Gmail SMTP Mail Server

Create a new project using "File" -> "New" -> "Project..." then select web "ASP .Net Web Forms Application". Name it " Bulk Email".

Now in the Design page “Default.aspx” design the web page as in the following screen:

In the Design Source (Default.aspx) write the code as: 

Default.aspx.cs

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
 Inherits="BulkEmail._Default" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
   
 <section class="featured">
       
 <div class="content-wrapper">
           
 <hgroup class="title">              
               
 <h2>Send Bulk email using asp.net</h2>
           
 </hgroup>
           
 <p>
                To learn more about ASP.NET
           
 </p>
       
 </div>
   
 </section>
</asp:Content>
<asp:Content
 runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
      
 <h3>We suggest the following:</h3>
   
 <asp:Panel ID="Panel1" runat="server" Width="100%" ScrollBars="Horizontal">
   
 <p>
      
 <asp:Button ID="btnBind" runat="server" Text="View" OnClick="btnBind_Click" /> <asp:Label
ID="Label1"
 runat="server" Font-Bold="true" ForeColor="Green" Text="Total Customers:">   
</asp:Label><asp:Label ID="lbltotalcount" runat="server" ForeColor="Red" Font
Size
="Larger"></asp:Label> </p>
   
 
       
 <asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" />
       
 <asp:GridView ID="grvCustomers" runat="server"></asp:GridView>

   
 </asp:Panel>
</asp:Content>

In the Web.config file create the connection string as:

Web.config

<connectionStrings>     
   
<add
 name="ConnectionString"connectionString="Server=localhost;userid=root;password=;Database=
orthwind"providerName="MySql.Data.MySqlClient"/>      

</connectionStrings>

In the code behind file (Default.aspx.cs) write the code as: 

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

//Using namespaces 
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Data;

namespace BulkEmail
{
   
 
public partial class _Default : Page
    {
        #region MySqlConnection Connection
       
 
MySqlConnection conn = new
MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

       
 protected void Page_Load(object sender, EventArgs e)
        {
           
 
Try
            {
               
 if (!Page.IsPostBack)
                {

                }
            }
           
 
catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }
        #endregion
        #region show message
       
 
/// <summary>
       
 /// This function is used for show message.
       
 /// </summary>
       
 /// <param name="msg"></param>
       
 void ShowMessage(string msg)
        {
           
 ClientScript.RegisterStartupScript(Page.GetType(), 
"validation", "<script
language='javascript'>alert('"
 + msg + "');</script>");
        }      
 
        #endregion
        #region Bind Data
       
 
/// <summary>
       
 /// This display the data fetched from the table using MySQLCommand,DataSet and
MySqlDataAdapter

       
 /// </summary>
       
 /// <param name="sender"></param>
       
 /// <param name="e"></param>
       
 protected void btnBind_Click(object sender, EventArgs e)
        {
           
 
Try
            {
                conn.Open();
               
 MySqlCommand cmd = new MySqlCommand("Select
CustomerID,ContactName,Address,Phone,Email from customers"
, conn);
               
 MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
               
 DataSet ds = new DataSet();
                adp.Fill(ds);
                grvCustomers.DataSource = ds;
                grvCustomers.DataBind();
                lbltotalcount.Text = grvCustomers.Rows.Count.ToString();
            }
           
 catch (MySqlException ex)
            {
                ShowMessage(ex.Message);
            }
           
 
Finally
            {
                conn.Close();

            }
            btnBind.Visible =
 false;
        }
        #endregion
        #region Bulk email,GridView,gmail
       
 
/// <summary>
       
 /// this code used to Send Bulk email 
       
 /// </summary>
       
 /// <param name="sender"></param>
        
/// <param name="e"></param>
       
 protected void btnSend_Click(object sender, EventArgs e)
        {
           
 
Try
            {
                lbltotalcount.Text =
 string.Empty;
               
 foreach (GridViewRow grow in grvCustomers.Rows)
               {
                   
 
string strCustomerID = grow.Cells[0].Text.Trim();
                   
 
string strContactName = grow.Cells[1].Text.Trim();
                   
 
string strAddress = grow.Cells[2].Text.Trim();
                   
 
string strPhone = grow.Cells[3].Text.Trim();
                   
 
string strEmail = grow.Cells[4].Text.Trim();                

                   
 
string filename = Server.MapPath("~/Event.html");
                   
 string mailbody = System.IO.File.ReadAllText(filename);
                    mailbody = mailbody.Replace(
"##NAME##", strContactName);
                   
 string to = strEmail;
                   
 
string from = "[email protected]";
                   
 MailMessage message = new MailMessage(from, to);
                    message.Subject =
 "Auto Response Email";
                    message.Body = mailbody;
                    message.BodyEncoding =
 Encoding.UTF8;
                    message.IsBodyHtml =
 true;
                   
 SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                    System.Net.
NetworkCredential basicCredential = new
System.Net.
NetworkCredential("[email protected]", "Password");
                    client.EnableSsl =
 true;
                   
 client.UseDefaultCredentials = true;
                    client.Credentials = basicCredential;
                   
 try
                    {
                        client.Send(message);
                        ShowMessage(
"Email Sending successfully...!" + strContactName + " &nbsp;");                                           
                    }
                   
 catch (Exception ex)
                    {
                        ShowMessage(ex.Message);
                    }
                } 
            }
           
 
catch (MySqlException ex)
            {
                ShowMessage(ex.Message);
            }
           
 
Finally
            {
                conn.Close();
            }
        }
        #endregion
    }
}

See the following screen for the Default.aspx: Total Customers data bind.

Now, see the following screen for the Default.aspx: send email waiting.

Now, show in the Message box “Email sending successfully”.

Now "Email Account Open" - > "View Email". You’ll see the messages on your inbox. Bulk Sending an E-Mail Using ASP.NET 4.5 with HTML Email Templates and Gmail SMTP Mail Server. I hope this article is useful. 



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in