How to create a directory inside another subdirectory.

Posted by Bhanubysani under ASP.NET on 8/29/2011 | Points: 10 | Views : 1088 | Status : [Member] | Replies : 1
i have a code like this...

UPOBJ.U_TaskName = ddlTask.SelectedItem.Text.ToString();
UPOBJ.U_FileUploadPath = Server.MapPath("~/DaywiseReports");
string path = UPOBJ.U_FileUploadPath;
UPOBJ.U_Date=MetaData.StripTagsRegex(System.DateTime.Now.ToString("MMMM dd, yyyy"));
DirectoryInfo dirInfo = new DirectoryInfo(UPOBJ.U_FileUploadPath);
string reportFile = UploadReport.FileName;
string FileExtension = Path.GetExtension(reportFile);
UPOBJ.U_DayWiseReport = UPOBJ.U_Date + FileExtension;
if (UPOBJ.U_DayWiseReport != "" || UPOBJ.U_DayWiseReport != string.Empty)
{
dirInfo.CreateSubdirectory(UPOBJ.U_UserID.ToString());

UploadReport.SaveAs(path + "/" + UPOBJ.U_UserID.ToString() + "/" + UPOBJ.U_DayWiseReport.ToString() );
}
result = UBLOBJ.SubmitDaywiseReport(UPOBJ);
if (result > 0)
{
AlertMessage("Report Sent Succeesfully");
ddlTask.ClearSelection();
}
else
AlertMessage("Some Problem Occured While Sending the Report");

this code is successfully creating a directory daywisereports/username/reprtname with date..

but my problem is the file will be saved like this

daywisereports/username/taskname/reports..

for every task a subdirectory will be created like this..and if the daywise reports directory not presented automatically the directory will be cretaed..plz help me in witing this code

Regards,
Bhanu Prakash Bysani



Responses

Posted by: Ndebata on: 8/31/2011 [Member] Starter | Points: 25

Up
0
Down
//Assuming you have a directory having path as DirPath

if (!System.IO.Directory.Exists(System.IO.Path.Combine("DirPath", "NewDirectoryName")))
System.IO.Directory.CreateDirectory(System.IO.Path.Combine("Path", "NewDirectoryName"));


Bhanubysani, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response