views:

5287

answers:

6

I have created a custom list in a SharePoint site and generated a Visual Studio 2008 project using SharePoint Solution Generator. I can package this as a feature and install it. It runs fine on my server.

After testing this out, I've been able to add a custom masterpage to the feature which is deployed to the _catalogs/masterpage folder. Here it is:

<Elements Id="2196306F-3F37-40b5-99CF-42E89B93888A" xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
    <Module Name="DefaultMasterPage" Url="_catalogs/masterpage" RootWebOnly="FALSE">
      <File Url="gcbranding.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
    </Module>
</Elements>

Now that I have a custom masterpage in my site, I would like to have this used for the creation of new items. But I don't want to have to set the master from SharePoint Designer.

Going back to the generated solution, it has NewForm.aspx etc. with the list schema. How do I...

  1. Customize the form that is displayed for new items, and have it redirect to a thankyou.aspx page rather than showing all the list items?
  2. Set the url to the master page correctly?

I'm lost on point number 1. Do I need to create a custom webpart and embed that in NewForm.aspx?

On point 2 I have made some headway but have run into an issue. If I set the master like this in my NewForm.aspx...

 MasterPageFile="~/masterurl/gcmaster.master"

It will install OK, but when I hit the site I get an error because ~ is not allowed in the URL. If I use _catalogs/masterpage in the directive, it will not find the master because the URL is relative. Only this code seems to work:

MasterPageFile="../../_catalogs/masterpage/gcmaster.master"

What's the best practice way of setting the master page file in SharePoint, when deploying a custom feature/solution?

+2  A: 

Re Masterpage: I think you want '~masterurl/gcmaster.master'. no "/" between the "~" and "master".

Re NewForm: You can create your own code-behind page for NewForm.aspx, change the Inherits attribute to your own class. I think I would start by having my custom code behind inherit from SharePoint.SharePoint.WebPartPages.WebPartPage, and go from there.

Jason
A: 

Best way to do it is open up NewForm.aspx in SharePoint Designer, change:

MasterPageFile="~masterurl/default.master"

to

MasterPageFile="~masterurl/custom.master"

This will obviously edit the current instance but if you want to deploy this with a site def or feature then you need to create and NewForm.aspx page within the same folder as schema.xml in your list instance folder.

Hope that helps.

Lee Dale
A: 

BrianLy,

To answer this question:

1.Customize the form that is displayed for new items, and have it redirect to a thankyou.aspx page rather than showing all the list items?

The SIMPLEST answer, is, change the "Add New Item" link to add a source URL for your thank you page. For example, instead of (I had to leave out the http):

www.yoursite.com/Lists/Links/NewForm.aspx

you change it to:

www.yoursite.com/Lists/Links/NewForm.aspx?Source=www.yoursite.com/ThankYou.aspx

When the user click Submit from the NewForm page, they will be redirected to ThankYou.aspx.

You will probably have to use SharePoint Designer to change the link, however.

Chris
A: 

For redirect check this out: http://www.sharepointdrive.com/blog/Lists/Posts/Post.aspx?ID=9

Mindaugas Bliudzius
A: 

Hi,

Override the OnPreInit event on the webpage, and in there put this line in:

this.MasterPageFile = SPContext.Current.Web.CustomMasterUrl; (if you're using the custom master page)

If you're using the default master page, use the following line:

this.MasterPageFile = SPContext.Current.Web.MasterUrl;

HTH,

James

code4life
I forgot to mention: the deployed master page has to be set as the custom or default masterpage. This occurs during the features activation phase, and you must implement an inherited SPFeatureReceiver class to do this. The SPFeatureReceiver sub class must be set up in the feature.xml file, of course.
code4life
A: 

Hi guys.

If you want to reuse a master page across a variety of .aspx pages, then you're better off setting it as the Custom Master Page. There's no page in WSS that lets you do this easily, so you're better off either Right-Clicking your _catalogs/masterpage/gcmaster.master file in SharePoint Designer and choosing Set as Custom Master Page, or setting it on the server through PowerShell (SharePoint script header available here: http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=7)

$web = Get-SPWeb("http://mysiteurl")

$web.CustomMasterUrl = "_catalogs/masterpage/gcmaster.master"

$web.Update()

Then in the @Page directive of your .aspx page, you can set:

MasterPageFile="~/masterurl/custom.master"

Bear in mind that this makes all .aspx pages in your site that reference "~/masterurl/custom.master" use your gcmaster.master page.

Alternatively, you could skip all that and for your .aspx page simply include a @Page directive that looks like this:

MastPageFile="~/site/_catalogs/masterpage/gcmaster.master"

Enjoy!

joel

joelblogs.co.uk - Joel's SharePoint Tricks and Tips

Joel Jeffery