Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:32:41+00:00 2026-06-15T08:32:41+00:00

Hi I am trying to create a new directory usingC#/asp.net webforms but I do

  • 0

Hi I am trying to create a new directory usingC#/asp.net webforms but I do not seem to have any luck.Here is my code:

    string path = "~/Images/avatar/" + User.Identity.Name + "/userAvatars/";
     private void createPath(string path)
     {
           string activeDir = @"~/Images/avatar/userAvatars";
           if( !Directory.Exists(Server.MapPath(path)) )
           {
               string newPath = Path.Combine(activeDir, User.Identity.Name);
               Directory.CreateDirectory(newPath);
            }
      }
     createPath(path)

Now this code does not throw any errors but it does not create the folder either unless I provide a physical directory starting from the letter of the drive.Example:

D:\Projects IDE\Visual Studio\MyWork\Websites\Forum

This won’t work because at some point I will want to upload the application to the server.

So how can I set the filepath to get the root if the project and make this code work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:32:43+00:00Added an answer on June 15, 2026 at 8:32 am

    Try this

    string newPath = HostingEnvironment.MapPath(Path.Combine(activeDir, User.Identity.Name)
    Directory.CreateDirectory(newPath);
    

    You are forgetting to map the newPath after you use Path.Combine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am now trying to create new database manager under Fragment class. But unfortunately,
Trying to create a new Dedicated Cache Role in Windows Azure but get the
When trying to create a new team project with any of the default project
I'm trying to create a job in an ASP.NET (C#) form using Quartz.NET, and
I'm trying to post to an asp.net webpage and receive the resulting xml. Here's
I'm trying to create a new user on my development active directory server using
I'm trying to programatically create a new Active Directory user setting the sAMAccountName attribute
I am trying to create a Local IIS Website using ASP.NET . When I
I'm new to postgreSQL and I have a simple question: I'm trying to create
I'm trying to create a new directory in the branch of my SVN repository

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.