Click here to Skip to main content
12,823,976 members (44,175 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 21 Jul 2008

Creating a Sub directory Breaks SharePoint Virtual Site Makeup

, 21 Jul 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Creating a sub directory using MapPath("testdir") breaks SharePoint virtual site makeup


This small article is about a SharePoint caveat that I encountered while developing a WebPart. The cause of the problem was the command:


This indirectly breaks SharePoint and results in an HTTP 404 error.

The Steps to Reproduce

Step 1: Using VS 2007, create a WebPart with the following code:

protected override void CreateChildControls()


    Label label = new Label();
    label.Text = "Dropzone created";

Also add the code...

[assembly: System.Security.AllowPartiallyTrustedCallers()]

... to the AssemblyInfo.cs file.

Step 2: Deploy the WebPart to your SharePoint server. I won't attempt to document the deployment steps because it will take the focus away from the specific topic of this article.

Step 3: Change the trust level of SharePoint from minimal to full. This is not recommended in general, but I only want to show a quick way to allow the WebPart to create a folder.


<trust level="WSS_Minimal" originUrl="" />


<trust level="Full" originUrl="" />

Step 4: Go to YourSite > Web Part Gallery and add the new WebPart. This step may not be necessary for some deployment methods.


Step 5: Go to YourSite > Site Settings > Sites and Workspaces and create a new site for this test.


Step 6: Edit the default page, http://yourserver:###/TestMapPath/Pages/default.aspx, of the new site and add your WebPart to this page. Exit edit mode.


Now whenever you view this page and WebPart, the following folder will be created:


Great, you think. The WebPart worked as expected. It did work as expected, so far. But wait, there is more.

Step 7: Now restart the site. You can easily do this by modifying and saving the \\yourserver\c$\Inetpub\wwwroot\wss\VirtualDirectories\###\web.config file.

Step 8: Now try to visit the page http://yourserver:###/TestMapPath/Pages/default.aspx again.


The site is broken!

What happened?

When the WebPart created the directory, it created a physical folder that conflicts with the virtual content of the TestMapPath site. When we accessed the page (after the restart), IIS was looking for the page in the physical folder, and could not find it there. IIS was not able to pass the request down the chain to the SharePoint service and retrieve the virtual content of the page.


  • Version 1 dated 22 July 2008


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Johan Fourie
Australia Australia
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 21 Jul 2008
Article Copyright 2008 by Johan Fourie
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid