Question

Here is my code to create Directory. It Works on local-end but if I host this web app then will get the ERROR MESSAGE : PATH NOT FOUND

 try
 {
     if (tvFolders.SelectedNode != null)
     {
         TreeNode fileNode = new TreeNode();

         fileNode.Text =Server.MapPath("~//"+ tvFolders.SelectedValue.ToString());

         string rootPath = fileNode.Text;
         Directory.CreateDirectory(rootPath + "/" + txtDirName.Text);
         lblMessage.Text = "Directory created";

      }
      else
         lblMessage.Text = "Directory already exists";
}
catch (Exception)
{
}
Was it helpful?

Solution

Try using Server.MapPath as follow

string rootPath = Server.MapPath(fileNode.Text);
Directory.CreateDirectory(rootPath + "/" + txtDirName.Text);

More detail about server.mappath

Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top