You must Sign In to post a response.
  • Category: .NET

    Create Folder on server

    Hello All

    I am creating folder on server. I have used impersonation .

    Directory.Create(path) executed successfully but Directory is not created??

    Can any body help me

    Thanks in advance
  • #751565
    Hi Umesh
    Have you put TRY...CATCH to your code ? which user you are using for 'impersonation' ? Does that user has administrative rights ? Have you use Windows Authentication in your application ?
    Please use TRY...CATCH in your application and try to track error.
    Post error, so that we can help you to resolve your issue

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #751568
    Hello Umesh,

    If your code works in local but didn't work on server than they may be issue with permission.
    You should set all read write rights to a main ans sub directory where you have puted your application in server.
    You can also find error syntex as prasad said using try {} catch{} block in your code.
    Either you can alert your exception message ot you can append exception message in log.txt file which should be already in your application
    You can get exception message like this

    //your stuff regarding creation of a directory
    catch (Exception ex) {

    string error = ex.Message.ToString();
    //do stuff as your requirement

    I hope you got my point,if still you have an issue than i'll get back to you.

    Nirav Prabtani (Senior Web Developer)
    Email :
    blog :

  • #751587
    Hello Umesh,

    Use try...catch block in your code to find out the exact error if it breaks the execution in between the code. try to create the folder in your local PC first and if code works fine on your local machine then provide the "write" permission for the user who are going to create folder on server by using that code.

    try to use below code :


    Hope this will help you.

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo

  • #751598
    Hello Prasad sir
    Thanks for response. i have resolve this issue..

  • #751608

    If you want to create folder in your path then use below sample.

    protected void btnCreate_Click(object sender, EventArgs e)
    string Path = txtDir.Text;

    if (!System.IO.Directory.Exists(Path))
    lblStatus.Text = " Directory is created for the specified path.. " + Path;
    lblStatus.Text = "Directory is already created at specified path.." + Path;
    catch (Exception ex)
    lblStatus.Text = "Please check the Path of the Directory you entered.." + ex.Message;

    Try something like above to achieve your goal.

    Hope this will help you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments