Skip to main content

Selecting directory using DropDownList

ASSIGNMENT-

The objective is to write the name of directory in the first textbox and click on Create dir then all directories have to added in the below DropDownList.

By Selecting the image from FileUpload control and the directory from dropdownlist we can put the image in the specific selected directory



How to add the directories using code-

    protected void CheckDir_Click(object sender, EventArgs e)
    {
        Directory.CreateDirectory(Server.MapPath(TextBox1.Text) + "/"); 
        DropDownList1.Items.Add(TextBox1.Text);
    }  

UploadButton Code- 

   protected void Upload_Click(object sender, EventArgs e)
    {
        FileUpload1.SaveAs(Server.MapPath("~") + "//"+DropDownList1.Text+"//" + FileUpload1.FileName);


    }


Insert 4 directories-
1. pic1
2. pic
3. pic3 
4. pic4 

Selecting pic2 from the Drop Down List and select the image from file Upload control and click on Upload button 


Checking the pic2 directory-



There you go-


CODE-








Comments

Popular posts from this blog

FileUpload And QueryString

1. Took File Upload control, Button, Image button control,  Label (First Page) [Browse your desired file > Click on Upload Button > Image will be shown in Image Button Control  ]  Inside the event of ImageButton QueryString is defined.  CODING- 2. When we click on it then the next page will be shown Image ,Using QueryString-  (Next Page) Image control will be used-  Inside page_load event we will call QueryString.

DataBase Assignment

  1. Registration page(Design)  Note:- We used Range validator in Age 's textbox.  Coding- 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 Registration : System.Web.UI.Page {     SqlConnection cn;     SqlCommand cm;     SqlDataReader dr;     protected void Page_Load(object sender, EventArgs e)     {     }      //Coding of submit button     protected void Button1_Click(object sender, EventArgs e)     {         string p=@"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356";         cn = new SqlConnection(p);         cn.Open();         string q = "insert into Chitransh_reg values ( '"+TextBox1.Te...

Quiz[Session]

  3.USING SESSION-   Code- using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Assign2 : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {     }     protected void Button11_Click(object sender,EventArgs e)     {         if (RadioButtonList1.SelectedIndex == 0)              TextBox1.Text = "1";         else              TextBox1.Text = "0";                               if (RadioButtonList2.SelectedIndex == 2)             TextBox2.Text = "1";         else             TextBox2.Text = "0";           ...