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......