SharePointID

I want to create an ASPX page that will be hosted in SharePoint. When I say hosted in SharePoint, I mean to say that the SharePoint top-level and the left-hand menu's will surround my page (as if my page has been hosted in SharePoint).

Is there a way to do that

Thanks,

SP



Re: SharePoint - Development and Programming SharePoint Look & Feel for custom pages

AC [MVP MOSS]

If your ASPX page is running within the SharePoint context (within a site) you can definately do this... just utilize the OOTB master pages. What you want to do us use the SPWeb.MasterUrl property in your ASPX page so it uses whatever master is set on the site level. This is done using a token (read more here: http://msdn2.microsoft.com/en-us/library/ms467402.aspx).

Then you want to add the bulk of your page to the PlaceholderMain content placeholder.

Look at the figure 2 in my article here (http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx) on using this token. That article goes one step further in packaging the file up into a Feature for easy deployment.






Re: SharePoint - Development and Programming SharePoint Look & Feel for custom pages

SharePointID

Andrew,

You are my man! Great piece of work.

I have some comments/questions after reading your article and the above reply:

(1) You asked me to use the SPWeb.MasterUrl property in the ASPX page. But correct me if I am wrong but I have to use either the property in the C# code or use the MasterPageFile=~masterurl/default.master in the Page directive, not both. right

(2) The following is the list of steps that I have come up with for creating an ASPX page that runs in SharePoint. Note that I have removed the deployment related steps; I will copy files myself for now. Do you see any issues with these

(2.1) Create a project in VS 2005 and add the ASPX page and the Code behind file.

(2.2) Make sure that the Page directive's MasterPageFile attribute is set to ~masterurl/default.master.

(2.3) Compile the project.

(2.4) Copy the newly created DLL to the bin folder of the web site under which the page needs to run

(2.4) Copy the ASPX page under the web application

(2.5) Hopefully, i will be celebrating here ....

The only thing which will be remaining @ that point would be adding a new tab across the top of the default page and have it call the newly created ASPX page. Any insights on that as well

Thanks,

SP





Re: SharePoint - Development and Programming SharePoint Look & Feel for custom pages

AC [MVP MOSS]

Wish there was an easy way to do comments inline in MSDN forums! Smile OK, here it goes...

#1 - Close... the ~masterurl/default.master tells SharePoint, at runtime, to swap this value out with the value of the SPWeb.MasterUrl property. Conversely, ~masterurl/custom.master is swapped with SPWeb.CustomMasterUrl. My first answer wasn't explicit here... what I should have said was "use [this] token to get SharePoint to use the value of [this] property." My bad Smile

#2 - You can definately do exactly what you explain here (including the celebration)... however, I'd argue to deploy it with a Feature. When I say do it, I mean provision the file using the Feature site element in the element manifest file. That article (http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx) explains the process.

Why do I argue against copying the ASPX -> web application Because now every site collection (and thus site) in that Web application can use the ASPX. Not desireable most of the times. Plus, there's no way to deploy it with a WSP. Hence, I like Features that provide all this control.

One thing you forgot was the add a entry for your page's class (defined in the code behind). That's a must.

How to add an item to the navigation, like the top nav Via code... hence another reason why I like Features here because it can be done when the page is provisioned via a Feature receiver:

Code Block

public override void FeatureActivated (SPFeatureReceiverProperties properties) {
// get a reference to the current site's top navigation
SPWeb site = properties.Feature.Parent as SPWeb;
if (site == null)
throw new SPException("Error obtaining reference to the parent SPWeb within FeatureActivated event handler.");
SPNavigationNodeCollection topNavigation = site.Navigation.TopNavigationBar;

// create new drop down menu for our new pages
SPNavigationNode newMenu = new SPNavigationNode("My Custom Page", "MyCustomPage.aspx", false);
// add the new menu to the end of the top nav bar
topNavigation[0].Children.AddAsLast(newMenu);

site.Update();
}

HTH! OH... BTW... Can't be "your" man... my wife would kill me Stick out tongue




Re: SharePoint - Development and Programming SharePoint Look & Feel for custom pages

SharePointID

Thanks buddy! that helps. I will try these over the weekend and will post the updates.

On a side note, I hate clients who just want to use Share Point for the sake of using Share Point. Yes, I am dealing with such client these days Sad

and for sure I would not want you to get killed, so I would say "You are the man"





Re: SharePoint - Development and Programming SharePoint Look & Feel for custom pages

AC [MVP MOSS]

Glad I could help... if you would just mark the post as an answer or helpful to help others, that would be great. Thanks and good luck!