Thursday, 1 May 2014

Adding new folder on buttonclick and adding images to that folder

No comments
for creating folder

.cs


 protected void Button1_Click(object sender, EventArgs e)
    {
        System.IO.Directory.CreateDirectory(MapPath("~/" + TextBox1.Text));
    }



Showing all folders in radiobuttonlist and saving image to that perticular folder


if (!IsPostBack)
        {
            DirectoryInfo info = new DirectoryInfo(MapPath("~/"));
            string[] ex = { "App_Code", "Bin" };
            RadioButtonList1.DataSource =from p in info.GetDirectories("*", SearchOption.TopDirectoryOnly)
                                             where !ex.Contains(p.Name)
                                             select p;
            RadioButtonList1.DataBind();
        }


Inserting image in that folder


 protected void Button2_Click(object sender, EventArgs e)
    {
        string path = Server.MapPath(RadioButtonList1.SelectedItem.Text+"\\");
        string name = FileUpload1.FileName;
        string ext = Path.GetExtension(name);

        if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".doc")
        {
            string concate = path + name;
            FileUpload1.SaveAs(concate);
        }


    }