Wednesday, 22 February 2012

storing text documents in the folder and the file path in the database

1 .first create the folder to store the documents 
    here i created folder with name "documents"


2 after that create table in database like this


and in code behind

   string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
        //Save images into Images folder
        FileUpload1.SaveAs(Server.MapPath("documents/" + FileName));
        //Getting dbconnection from web.config connectionstring
     
        //Open the database connection
        con.Open();
        //Query to insert images path and name into database
        SqlCommand cmd = new SqlCommand("Insert into testing(ImageName,ImagePath) values(@ImageName,@ImagePath)", con);
        //Passing parameters to query
        cmd.Parameters.AddWithValue("@ImageName", FileName);
        cmd.Parameters.AddWithValue("@ImagePath", "documents/" + FileName);
        cmd.ExecuteNonQuery();
        //Close dbconnection
        con.Close();

Monday, 20 February 2012

Procedure to bind checkboxlist control


  public void chkboxlist()
    {
        SqlDataAdapter da = new SqlDataAdapter("select SE_Category from category", con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        CheckBoxList1.DataSource = dt;
        CheckBoxList1.DataTextField = "SE_Category";
        CheckBoxList1.DataValueField = "SE_Category";
        CheckBoxList1.DataBind();
        CheckBoxList1.Items.Insert(0, "Others");
    }


Thursday, 9 February 2012

Importing data from text fles/notepad into database



BULK
INSERT table_name
FROM 'C:\Documents and Settings\manju\Desktop\test.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO

Monday, 6 February 2012

Most hardest thing is to change the default view of the DropDown LIst. here is the simple CSS for that


<style type="text/css"> 
.select {
  -webkit-appearance: button;
  -webkit-border-radius: 2px;
  -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1);
  -webkit-padding-end: 20px;
  -webkit-padding-start: 2px;
  -webkit-user-select: none;
  background-image: url(images/arrow.png),
    -webkit-linear-gradient(#FAFAFA, #F4F4F4 40%, #E5E5E5);
  background-position: center right;
  background-repeat: no-repeat;
  border: 1px solid #AAA;
  color: #555;
  font-size: inherit;
  margin: 0;
  overflow: hidden;
  padding-top: 2px;
  padding-bottom: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;}
</style>
.----------------------------




  <asp:DropDownList ID="DropDownList1" runat="server"  CssClass="select"    Width="150px">
        <asp:ListItem>manja</asp:ListItem>
         <asp:ListItem>manja1</asp:ListItem>
          <asp:ListItem>manja2</asp:ListItem>
           <asp:ListItem>manja3</asp:ListItem>
        </asp:DropDownList>



    thats it .............. joy......

Sunday, 22 January 2012

Simple method to send mails form your asp.net


first include

Using System.Net.Mail;

-------------------------------------------


protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add("manjunath4ualways@gmail.com");
        mail.To.Add("manjunath4ualways@gmail.com");
        mail.From = new MailAddress("manjunath.le@smartdrivelabs.com");
        mail.Subject = "Mail from manju";

        string Body = "Hi, this mail is manju ";
        mail.Body = Body;

        mail.IsBodyHtml = true;
     
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential
             ("your mail id", "password");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = false;
        smtp.Send(mail);
    }

thats it........




Simple method to send mails form your asp.net with attachment


first include

Using System.Net.Mail;

-------------------------------------------


protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add("manjunath4ualways@gmail.com");
        mail.To.Add("manjunath4ualways@gmail.com");
        mail.From = new MailAddress("manjunath.le@smartdrivelabs.com");
        mail.Subject = "Mail from manju";

        string Body = "Hi, this mail is From Manju ";
        mail.Body = Body;

        mail.IsBodyHtml = true;
        if (FileUpload1.HasFile)
        {
            string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
            mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileName));
        }


        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gamil.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential
             ("your mailid", "password");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = false;
        smtp.Send(mail);
    }
thats it...............

your SMTP server name means......... the outgoing mail server for your mail id which ll be used in outlook for mail configuration


Wednesday, 18 January 2012

stored procedure for inserting records

first create the procedure in the sql server like this

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[comment]
(
@name varchar(50),
@email varchar(50),
@comment varchar(max)
)
as
insert into Commentbox (SE_name,SE_Email,SE_comment) values (@name,@email,@comment)

and then in code behind

 string connstr = ConfigurationManager.ConnectionStrings["smartedu"].ConnectionString;
        SqlConnection conn = new SqlConnection(connstr);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "dbo.comment";
 
        cmd.Parameters.AddWithValue("@name",TextBox1.Text);
        cmd.Parameters.AddWithValue("@email", TextBox2.Text);
        cmd.Parameters.AddWithValue("@comment", TextBox3.Text);
        cmd.Connection = conn;

        try
        {
            conn.Open();
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }

        TextBox3.Text = "";
        TextBox2.Text = "";
        TextBox1.Text = "";