Monday, April 30, 2007

SharePoint Designer Article 1 - how to edit a page?


In SharePoint 2003 (WSSv2) with FrontPage, it was so easy to edit a page. Just open the page you want to edit in Internet Explorer and hit the "Edit in FrontPage" icon at the toolbar.

Well, the good news are that in SharePoint 2007 (WSSv3) the same applies, but only for some of the pages, while other pages will tell you "This page cannot be edited in SharePoint Designer".

This article will explain what is going on, and how to get each type of page to be editable in SharePoint Designer.





Lets start easy- when you create a WSSv3 web site from one of the default template such as team site, blank site etc...you will have no problems using the easy button - edit in SharePoint Designer:



You can also open the SharePoint site or page for editing from within SharePoint Designer using the "Open Site" or "Open.." dialogs within the application:







When you open such a page from such a site directly from Internet Explorer, or from SharePoint Designer, you will see the page in SharePoint Designer, and be able to modify it using the designer mode or the code mode:




So far so good right?

So lets figure out why some of the pages give us the following message when we try to edit them in SharePoint Designer:

"This page cannot be edited in SharePoint Designer. You can edit the content in the browser, or edit the corresponding page layout in SharePoint Designer"

This page cannot be edited in SharePoint Designer. You can edit the content in the browser, or edit the corresponding page layout in SharePoint Designer



Why is that? well, simply because the page you are trying to edit is under the publishing feature. It is a publishing page, and as such, by default, gets it's layout from the layout page and the master page.

The only change you should be doing on such a page is edit it in the browser and add\remove\change web parts in it.


However, there is a way to work around this - detach it from it's layout page. This is similar to the ghosting\unghosting process that we had back in SharePoint 2003 (WSSv2), but with the added benefit that we can allways roll back the change.
It also means that in the first time you will edit that page, you will have to start from SharePoint Designer to do it:


Open the site that contains the page in SharePoint Designer (use "File>Open Site") and browse to the page you want to edit in the folder list.

Right click the file, and choose "Detach from page layout". This will unghost the file - copying it's layout from the layout page into the database, and so allowing you to edit it, just like you used to do in SharePoint 2003:




Unlike sharepoint 2003, you can take it back, and reattach the file:






Best practice:

Although unghosting is no longer a big bad wolf since it can be undone, you still shouldn't be doing it. It means that the page is disconnected from the layout page that defines the layout for all of the pages in the site. If you will want to make a change to the layout template in the future, this page will not change, unless you reattach the file, but in that case your changes to the file's layout will be lost.


So the best practice from SharePoint 2003 remains - only change a file using SPD if you must. There are ways to avoid editing a file in SPD and still making the changes you thought you had to do using SPD. For example - create a new layout page template, and change the page to use that layout.

Now, I hear you asking - "what about dataviews? we can only add them using SPD!". And I will cover that in my next article on the best practice of how to add a dataview using SPD to a page, without detaching it from its layout page.

If you cannot wait until I find the time for this article, just click on the "frontpage" tag in my blog - and see how I did it with sharepoint 2003 and frontpage. The method is the same.






1 comment:

david said...

How do you manage deployment scenarios for Data View Form Web Parts and Data View Web Parts. Is there an easy way to package these web parts in Features or Solutions? Can the Data View Web Part use custom objects as a Data Source? I can see SPDataSource, XML and Web Services but not custom objects like you get in Visual Studio grid views. Thanks.