using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.IO; public partial class ImageUpLoader : System.Web.UI.Page { string sqlstr; static string path; string strFileName1; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } public void uploadDocument() { if ((FileUpload1.PostedFile != null)) { HttpPostedFile file1 = FileUpload1.PostedFile; path = /* "Documents/" + */ file1.FileName; strFileName1 = Server.MapPath("~/Documents/") + file1.FileName; file1.SaveAs(strFileName1); string ext = Path.GetExtension(path); string contenttype = String.Empty; switch (ext) { case ".jpg": contenttype = "image/jpg"; break; case ".png": contenttype = "image/png"; break; case ".gif": contenttype = "image/gif"; break; case ".pdf": contenttype = "image/pdf"; break; //case ".doc": // contenttype = "Documents/vnd.ms-word"; // break; //case ".docx": // contenttype = "Documents/vnd.ms-word"; // break; //case ".xls": // contenttype = "Documents/vnd.ms-excel"; // break; //case ".xlsx": // contenttype = "Documents/vnd.ms-excel"; // break; } } } protected void btnUpload_Click(object sender, EventArgs e) { uploadDocument(); string date = DateTime.Now.ToString("dd-MM-yyyy"); string imageid = DAL.getRunningID("4"); sqlstr = "insert into Images(ImageID,URL,DateTime)values(" + imageid + ",'" + path + "','" + date + "')"; string sqlUpdate = "update Fms_Autonumber set RNo='" + imageid + "' where RCode='4'"; List<string> ids = new List<string>(); ids.Add(sqlstr); ids.Add(sqlUpdate); int j = DAL.sqlTransaction(ids); if (j > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Successfully Inserted", "alert('Image Uploaded Successfully..!')", true); } mltImageurl.Text = strFileName1; } }
Quote:After data inserted, if i refresh the page without pressing upload button then also data is inserting..
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)