Address: | 620001 |
Website: | demo |
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;
public partial class author_add_books : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["authid"].ToString();
Label2.Text = Session["authname"].ToString();
Label4.Text = DateTime.Now.ToString("dd:MM:yyyy");
}
protected void Button1_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Label3.Text = rnd.Next(0, 8989898).ToString();
FileUpload1.FileName.ToString();
String f1;
String bookname="";
String regno = Label3.Text;
if (FileUpload1.HasFile)
{
f1 = FileUpload1.FileName.Replace(FileUpload1.FileName, regno);
FileUpload1.SaveAs(Request.PhysicalApplicationPath + @"\books\" + f1 + ".pdf");
String fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
bookname = @"~\books\" + f1 + ".pdf";
}
if (FileUpload2.HasFile)
{
FileUpload2.SaveAs(Request.PhysicalApplicationPath + @"\multimedia\"+FileUpload2.FileName);
}
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|datadirectory|\book_publish.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand cmd = new SqlCommand("insert into new_books values('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + Label1.Text + "', '" + Label2.Text + "', '" + Label3.Text + "', '" + Label4.Text + "', '" + bookname + "', '" + ListBox1.SelectedItem.ToString() + "', '"+ FileUpload2.FileName +"')", con);
cmd.ExecuteNonQuery();
Label5.Text = "Book details uploaded.."+bookname;
}
}
Was this information helpful?
Post your Comment