Yet another way of writing code in SharePoint2007

Hi all;

Remember my post “Publish Your .ASPX Page With Code Behind To SharePoint 2007“, here is a simpler way of creating no code behind aspx page in SharePoint2007.

Here we will go through 3 steps:

  1. Build a simple aspx page in Visual Studio 2005 (with no separate code file).
  2. Tweak the SharePoint Web application Web.config file to accept running codes.
  3. Copy the aspx code to a new aspx page in SharePoint.

So lets start:

Building the aspx page

  1. open up Visual Studio 2005 or 2008, and make a new web site name it whatever.
  2. add another aspx page to the web site, but here uncheck the checkbox titled “Place code in separate file“.
  3. open this aspx page, and switch to design view.
  4. drop a TextBox, name it txtHello, and drop a Button name it btnHello.
  5. double click the btnHello command button.
  6. in the btnHello_Click protected sub, write this simple line code
  7. txtHello.text = “Hello World”. run your web site to test if every thing works fine.


Modify the web.config file of the SharePoint Web application:

  1. Open your Web application web.config file (which is found in this path –> C:\inetpub\wwwroot\wss\VirtualDirectories\xxxx   , the xxxx is the port number of your web application but in most cases for the default website its 80).
  2. add the following lines to the web.config file, directly inside the <configuration<SharePoint> directive and save.

<SafeMode MaxControls=500 CallStack=false DirectFileDependencies=10 TotalFileDependencies=50 AllowPageLevelTrace=false>


<PageParserPath VirtualPath=/* CompilationMode=Always AllowServerSideScript=true IncludeSubFolders=true ></PageParserPath>



here we are telling SharePoint to accept running codes from the root path including all sub folders by using “/*” , but i prefer that you create a folder in your site collection, naming it “Applications”, and put all aspx pages that contains code in it, then change the path in the VirtualPath=/*  to be VirtualPath=/Applications/* .


Finally, copy the code in this aspx page to a new aspx page in SharePoint using SharePoint Designer:

  1. Open SharePoint Designer 2007, create a new aspx page, back to your web site which you created in, open the aspx page that you’ve created and tested, switch to code view, select all (Ctrl+A) and Copy (ctrl+C) code, paste the code in the SharePoint aspx page.
  2. Save & Check-In the SharePoint aspx page, run and have fun.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: