2

I want to programmatically create a directory on the server using ASP.NET.

I have done this using System.IO's Directory.CreateDirctory. however, the newly created folder is not accessible in the code.

after searching a bit, I came to know that the newly create folder is not included the project and hence not accessible.

6
  • What do you mean by "not accessible" and "not included in the project"? Do you expect that it is added to the solution of your app? Commented Mar 8, 2010 at 9:02
  • Has the folder actually been created? As that would mean that your user context had the ability to create the folder, but not access it, which is a bit odd. Commented Mar 8, 2010 at 9:03
  • @Slavo, I mean that the files in the directory cannot be accessed from the code behind.Throws an exception for file not found. @Paddy the folder has been created. Commented Mar 8, 2010 at 9:11
  • Try to post your code Jayesh....do show how you are accessing the file...I guess the problem is in that place of your code... Commented Mar 8, 2010 at 9:28
  • Well I am using this code to create directory: Directory.CreateDirectory(Server.MapPath("/") + @"\Images-" + ObjectName); The directory is created. Next, I am adding images to it, programatically [Slide1.png, Slide2.png ...] The images are also added at the required destination [I check it manually browsing the directory] Next I am accessing the images and setting it to the ImageURL attribute of <asp:Image> with id=images... images.ImageUrl = Server.MapPath("/") + @"\Images-" + ObjectName + "Slide1.png"; With this, the Image object is not displaying anything! Commented Mar 8, 2010 at 9:37

3 Answers 3

2

OK...From your answer to my comment I think you can try this thing out:

 images.ImageUrl = "~/Images-" + ObjectName + "/Slide1.png";

Hope this helps...!!

Sign up to request clarification or add additional context in comments.

4 Comments

Yep, it looks like the OP is attempting to set the ImageUrl to the mapped path to the image, without a slash between the folder and the image - I guess the output source would look something like: src="c:\path-to-site\Images-ObjectNameSlide1.png"
@Zhaph - Ben Duguid : Yes, that was a mistake. But still if you put that missing slash, you won't get the required image as the property itself says what it needs ImageUrl..!! It needed a URL while Jayesh was providing it an absolute path..!!
Yes, I saw that ;) hence the +1 ;)
Yeah it was my mistake, giving absolute path Thanks Manish.
0

You mention that it is not included in the project. Are you referring to the project in Visual Studio? If so, it will not show up there as it is not a listing of file system directories. It is a listing of project files as build in the proj file. You will need to add it there.

If you are referring to the application then it should be available as soon as it is successfully created.

Please let us know where your issue is happening.

1 Comment

hi, By referring to project, I actually meant VisualStudio project. Well, the directory is created, I checked that, however, when I try to access a file in that directory it is throwing an error for file not found. However when I manually try to access the file from the same location, i can access it. So I was wondering if there would be any security restrictions while accessing from the code behind. Have no clue whatsoever.
0

Be careful when modifying the content of the web site in IIS : it detects such modifications and restarts the application immediately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.