Create ZipFile Insert Into Database During File Uploading
We Want To Create Zip File Whenever Uploading A New File Create ,Insert Zip File in Server Folder & Insert into Database Using in Asp.Net C#.
Multiple Zip Download
File Upload,Download
Download Single Zip File
Create Zip file
Download Coding
Download
ZIP.Dll
DEMO
HTML CODING
We Want To Create Zip File Whenever Uploading A New File Create ,Insert Zip File in Server Folder & Insert into Database Using in Asp.Net C#.
Multiple Zip Download
File Upload,Download
Download Single Zip File
Create Zip file
Download Coding
Download
ZIP.Dll
DEMO
HTML CODING
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Create ZipFile Insert Into Database During File Uploading Using in Asp.Net C#</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr><td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td></tr>
<tr><td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" />
</td></tr>
</table>
<br />
<br />
</div>
</form>
</body>
</html>
C# CODING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Ionic.Zip;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
con.Open();
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string filelocate=(Server.MapPath("UploadFiles/" + filename)); // Upload Temporary
FileUpload1.SaveAs(filelocate);
ZipFile zip = new ZipFile();
zip.AddFile(filelocate); // Create Zip Temporay File
string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));//Get Current Date
zip.Save(Server.MapPath("ZipFiles/"+zipName));//Save Zip Folder Current Date & Time
File.Delete(filelocate); // After Delete Temporary File
SqlCommand cmd = new SqlCommand
("insert into reg(filename,filepath)values('" + filename + "','" + "ZipFiles/" + zipName + "')", con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Zip File Create & Uploaded')</script>");
}
}
0 comments:
Post a Comment