<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="fileupload.aspx.cs" Inherits="LuqmanSolutions.fileupload" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Green">asp.net FileUpload example: File Rename</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="OrangeRed"
>
</asp:Label>
<br /><br />
<asp:TextBox ID="txttitleone" runat="server"></asp:TextBox> <br /><br />
<asp:TextBox ID="txttitletwo" runat="server"
></asp:TextBox>
<asp:FileUpload
ID="FileUpload1"
runat="server"
Font-Size="Large"
ForeColor="OrangeRed"
/>
<br /><br />
<asp:Button ID="btnSave" runat="server" Text=" Save "
onclick="btnSave_Click" style="height: 26px" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BE_Luqman;
using BL_Luqman;
namespace LuqmanSolutions
{
public partial class fileupload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
BESlider be = new BESlider();
be.Pictitleone = txttitleone.Text;
be.Pictitletwo = txttitletwo.Text;
if (FileUpload1.HasFile)
{
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string fileExtension = GetExtension(filename);
string guid = Guid.NewGuid().ToString();
filename = guid + "." + fileExtension;
FileUpload1.SaveAs(MapPath("~/images/F/" + filename));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/images/F/") + filename);
//System.Drawing.Image bmp1 = img1.GetThumbnailImage(1400, 500, null, IntPtr.Zero);
//bmp1.Save(MapPath("~/images/S/") + filename);
be.Picname=filename.ToString();
System.Drawing.Image bmp2 = img1.GetThumbnailImage(150, 59, null, IntPtr.Zero);
bmp2.Save(MapPath("~/images/L/") + filename);
be.Picthumb = filename.ToString();
}
else
{
Label1.Text = "First select a file.";
}
new BLSlider().Get_Data_SliderInsert(be);
txttitleone.Text="";
txttitletwo.Text="";
}
private string GetExtension(string FileName)
{
string[] split = FileName.Split('.');
string Extension = split[split.Length - 1];
return Extension;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BE_Luqman;
namespace DAL_Luqman
{
public class DALSlider
{
private string connect = MyConnectionString.path;
public List<BESlider> show()
{
List<BESlider> list = new List<BESlider>();
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spshow.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
BESlider BESlider = new BESlider();
BESlider.Picid = Convert.ToInt32(sdr["Picid"]);
BESlider.Picname = Convert.ToString(sdr["Picname"]);
BESlider.Picthumb = Convert.ToString(sdr["Picthumb"]);
BESlider.Pictitleone = Convert.ToString(sdr["Pictitleone"]);
BESlider.Pictitletwo = Convert.ToString(sdr["Pictitletwo"]);
list.Add(BESlider);
}
}
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
return list;
}
public void Get_Data_SliderInsert(BESlider be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spsliderinsert.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Picname", be.Picname);
cmd.Parameters.AddWithValue("@Picthumb", be.Picthumb);
cmd.Parameters.AddWithValue("@Pictitleone", be.Pictitleone);
cmd.Parameters.AddWithValue("@Pictitletwo", be.Pictitletwo);
con.Open();
cmd.ExecuteNonQuery();
}
public void Get_Data_SliderUpdate(BESlider be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spsliderupdate.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Picid", be.Picid);
cmd.Parameters.AddWithValue("@Picname", be.Picname);
cmd.Parameters.AddWithValue("@Picthumb", be.Picthumb);
cmd.Parameters.AddWithValue("@Pictitleone", be.Pictitleone);
cmd.Parameters.AddWithValue("@Pictitletwo", be.Pictitletwo);
con.Open();
cmd.ExecuteNonQuery();
}
}
}
No comments :
Post a Comment