below is my codes.
This code can create directory and sub-directory. It can also upload image..The problem is I want to upload the image into sub directory, It cannot save into sub-directory.It stores only on the main directory.The main directory is the Albums directory. The concept of this, is that everytime I create a directory (that is a sub-directory), I upload images/photo that would automatically save in the sub-directory i created..
Anyone can help me regarding this matter.
Anyone can help me regarding this matter.
onclick="Button1_Click" />
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.IO;
using System.Data.SqlClient;
using System.Data.SqlTypes;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblFolderName.Visible = false;
txtFolderName.Visible = false;
btnSave.Visible = false;
}
private void CreateDirectoryIfNotExists(string NewDirectory)
{
try
{
// Checking the existance of directory
if (!Directory.Exists(NewDirectory))
{
//If No any such directory then creates the new one
Directory.CreateDirectory(NewDirectory);
Label1.Text = "Directory Created";
}
else
{
Label1.Text = "Directory Exist";
}
}
catch (IOException _err)
{
Response.Write(_err.Message);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
lblFolderName.Visible = true;
txtFolderName.Visible = true;
btnSave.Visible=true;
Label1.Visible = false;
}
protected void btnSave_Click(object sender, EventArgs e)
{
string NewDirectory = Server.MapPath("~/Albums/" + txtFolderName.Text);
//New Directory Name in string variable
CreateDirectoryIfNotExists(NewDirectory);
//Calling the function to create new directory
Label1.Visible = true;
6 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
mikescrupzPosted Sep 25, 2013, 10:16 AM
Posted Sep 25, 2013, 9:56 AM
What's happening if you attach the debugger?
mikescrupzPosted Sep 25, 2013, 8:44 AM
mikescrupzPosted Sep 25, 2013, 8:17 AM
mikescrupzPosted Sep 25, 2013, 7:47 AM
Posted Sep 25, 2013, 1:29 AM
Can you please upload the complete code to check?