ASP.NET MVC, MVC, C#, PYTHON, JQUERY

Showing posts with label ASP.NET MVC. Show all posts
Showing posts with label ASP.NET MVC. Show all posts

Monday, June 29, 2020

Download All Files In ZIP Format In Asp.Net MVC.NET



Hello Friends In this article, we will create a application for download all media file’s in zip format. We have to follow some simple steps to create a project and export some files in zip format in ASP.NET MVC
Step 1 – Create a Project
Opening Visual Studio, next, we need to create an ASP.NET MVC project. For doing that, just click File – New – Project.
After choosing a project, a new dialog will pop up. In that, select ASP.NET Web Application in the Web tab and give your project the location and a name. Then, click the “Ok” button. Choose the MVC Template.
Step 2: Install the SharpZipLib from Nuget package console
Install-Package SharpZipLib
Install-Package SharpZipLib


Step 3 – Create a Action Method in Controller for Download zip file
Write code into Our DownloadZipController and give Media file path into List for Media file that you want to download in the zip file and create a folder named DownloadedMedia in root directory. Right now, I gave the static image path but you can set dynamic image path according to your requirements.
using System;
using System.Drawing;
using System.Web;
using System.Web.Mvc;
using System.Xml.Linq;
using ICSharpCode.SharpZipLib.Zip;
namespace DownloadZipProject.Controllers
{
  public class DownloadZipController:Controller
  {
    private DataAccessLayer _db = new DataAccessLayer ();
    public FileResult DownloadMediaFilesInZip ()
    {
      var FileName = string.Format ("{1}_AllDocumentsFiles_{0}.zip",
    DateTime.Today.
    Date.ToString ("dd-MM-yyyy") + "_1",
    SessionManager.ApplicantUserName);
      var OutPutTempPath =
Server.MapPath (Url.Content ("/DownloadedMedia/") + FileName;
using (ZipOutputStream s =
       new ZipOutputStream (System.IO.File.Create
    (OutPutTempPath)))
{
s.SetLevel (9);
/byte[]buffer = new byte[4096];
var AllMediaList = new List < string > ();
DataSet ds = _db.RecruitmentApplicationPrint ();
var MediaFilesList = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
MediaFilesList.Add (Server.MapPath
    (ds.Tables[1].Rows[i]["DocPath"].
     ToString ()));}
for (int i = 0; i < MediaFilesList.Count; i++)
{
ZipEntry entry =
new ZipEntry (Path.GetFileName (MediaFilesList[i]));
entry.DateTime = DateTime.Now;
entry.IsUnicodeText = true; s.PutNextEntry (entry);
using (FileStream fs =
       System.IO.File.OpenRead (MediaFilesList[i]))
{
int sourceBytes;
do
{
sourceBytes = fs.Read (buffer, 0, buffer.Length);
s.Write (buffer, 0, sourceBytes);}
while (sourceBytes > 0);}
}
s.Finish (); s.Flush (); s.Close ();}
byte[]finalResult =
System.IO.File.ReadAllBytes (OutPutTempPath);
if (System.IO.File.Exists (OutPutTempPath)) System.IO.
File.Delete (OutPutTempPath);
if (finalResult == null
    || !finalResult.
    Any ())throw new Exception (String.
Format
("No Media File found"));
return File (finalResult, "application/zip",
     fileName);}
}
Step 4 – Implement button on view page for download Media files from the view side
Share:

Friday, September 7, 2018

Exploring ASP.NET MVC

   Exploring ASP.NET MVC

MVC

The MVC Model is an alternate to the ASP.NET web forms Model For developing web application .It is a light weight model and Support Exiting ASP.NET Feature.It Separates the Following three main Components From application 

 Model - 

Refers to a set of classes that describe the data that the application work with .In addition these classes define the business  Logic that governs how to data can be manipulated.

View -

Refer to the components that defines an application user Interface.For Example ,Login that contains text boxes and buttons.
Share:

Introduction To Web Application Development in ASP.NET MVC

 Introduction To Web Application Development

            Web Application is programs that are executed on the Web server from a web browser. 
These applications enable organizations to share information on the Internet and Corporate Intranets.
This information can be access from anywhere any time. The web application also supports commercial transactions. 

        The Three Layers of a Web Application   

Web application generally application broken into Three Layers. Each Layers has own Functionality. In Bellow Image, You Can see how three layers Contribute in Web Application






 Introduction to Web Pages

A Web application consists of many Web Pages. A Web page is Web document that Can be accessed through a Web Browser. Web pages are two Types:-

1:-Static Web Pages


  A Web page that contains only Static Contains and is delivered to the user as it is Stored is Called Static Web pages.

2:-Dynamic Web Pages

Web pages whose content  is generated dynamically by a Web Application or that response to user input and provides interactivity  is Call Dynamic Web Pages
Share:

Tuesday, September 4, 2018

What is Action Method in ASP. NET MVC

Hello friends in this article we will learn about Action Methods in ASP.NET MVC. 

In a controller  class all public  methods are called Action Method.
Action Methods mainly have a one to one mapping with user interactions.

Share:

Friday, August 31, 2018

What is Controller in ASP.NET MVC





As you know an MVC application consists of three parts: model, view, and controller. The development of a web application usually required the knowledge of all the three parts.
In ASP.NET MVC Controllers are responsible for processing an incoming user request, executing the appropriate application code and communicating with the model, and rendering the required view.

                            How to Create Controller.

In ASP.NET MVC, controllers handle all incoming request. For creating a controller you need to create a .cs containing the controller class in the controller folder.

public class HomeController :Controller {  //Write Some Code}
Share:

Tuesday, August 28, 2018

Working With HTML and URL Helpers In ASP.NET MVC


ASP.NET MVC  HTML and URL Helpers.

Hello, friends in this article we will learn about HTML and URL Helpers. Consider a situation where the development team working on the e-commerce shopping website application needs to give an option to a user should be able to navigate the different web pages. ASP.NET MVC offers a standard set of helper method. These helpers help you work with HTML and URLs.
The benefits of using these helpers are that they help you generate links and URLs form the routing configuration.

Some HTML Helpers Methods are :

  • Html.ActionLink()
  • Html.BeginForm() and Html.EndForm()
  • Html.Label() and Html.LabelFor()
  • Html.DisplayName() and Html.DisplayNameFor()
  • Html.TextBox() and Html.TextBoxFor()
  • Html.TextArea() and Html.TextAreaFor()
  • Html.EditorFor()
  • Html.Ediotr()
  • Html.Password() and Html.PasswordFor()
  • Html.HiddenFor()
  • Html.CheckBox() and  Html.CheckBoxFor()
  • Html.DropDownList() and Html.DropDownList()
  • Html.RedioButton() and Html.RedioButtonFor()
  • Url.Action()


1. Html.ActionLink()

The Html.ActionLink() Method generates a hyperlink (ancor tag) that points to a controller's action metho.The Html.ActionLink() helper uses the internal rougting process to generate the target URL for the hyperlink.

             The syntax of    Html.ActionLink() 

@Html.ActionLink("Link Text", "ActionName","Controller Name",HtmlAttributes )


This  Html.ActionLink() generate following HTML  markup:

<a href="Controller/ActionName">Link Text</a>
   

2.Html.BeginForm() and Html.EndForm()

The  Html.BeginForm() Method indicate the start of a form. This helper method coordinates with the routing engine to generate a proper URL.

The syntax of  Html.BeginForm() 
    

@{Html.BeginForm("ActionName","Controller Name");}

The preceding syntax will generate the following  markup:

<form action="ControllerName/ActionName" method="post">

Once you created successfully form you need to close the <form> tag by rendering a closing </form> tag. Html.EndForm() Helper method render the form end tag  </form>

In order to avoid to use Html.EndForm()  you can use the following syntax:


@using(Html.BeginForm("ActionName","ControllerName"){

//Write your code here
}

The preceding syntax will generate the following  markup:

<form action="ControllerName/ActionName" >
<!--Write your code here-->
</form>





Share:

Saturday, August 25, 2018

How to send SMTP Email ?

                How to Send Email Using SMTP mail





                        MailMessage mail = new MailMessage();
                        mail.To.Add(item);
                        mail.Subject = subject;
                        mail.Body = message;
                        mail.IsBodyHtml = true;
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host = "smtp.gmail.com";
                        smtp.Port = 587;
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials = new System.Net.NetworkCredential(email, pass);                                                    smtp.EnableSsl = true;
                        smtp.Send(mail);
Share:

SOCIAL PROFILES

Search This Blog

Powered by Blogger.

Fixed Menu (yes/no)

yes

Contact Form

Name

Email *

Message *

Tags

Ads Section

Tags

ASP.NET MVC (7) C# (11) jQuery (1)