SharePoint Development Bookmark and Share   
 index > SharePoint - Development and Programming > How to change default.master by my custom installer?
 

How to change default.master by my custom installer?

Hello, all.

I created my custom .exe installer by Windows Application. and I could succeed
to create my site and changed master file by next code.

SPWeb ChildWeb = ParentWeb.Webs.Add(strChildName, strChildName, strChildName, (uint)1033, "STS#1", false, false);
ChildWeb.MasterUrl = "/_catalogs/masterpage/mypage.master";
ChildWeb.Update();

But this code requires to add 'mypage.master' to galleries in advance. I did it by
not programming but Web UI like [Site Actions]->[Site Settings]->[Galleries]->[Master pages].
I want to complete to create sites by only install program.

Q1. How to add 'mypage.master' file to galleries by API or command line tool?

Q2. Is is possible to put 'mypage.master' file on file system not database? which folder should I put file in?


Thank you for kindness in advance.

ishiro  Monday, July 21, 2008 5:03 AM

1) Here firstyou will have to install your MasterPage as a feature on the server.

Links below would help on feature stapling and installing master page as feature :

http://www.heathersolomon.com/blog/articles/servermstpageforsitecollect_feature.aspx

[Set Type="GhostableInLibrary" in ProvisionedFiles.xml ]

2) Nowbefore the lines to create a site in your code, add lines to programmatically activate your master page feature on the parent site.

(Help link : http://dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/02/22/how-to-programmatically-activate-a-feature.aspx)

Now when you activate the feature the master page should get added to the master page gallery and available for the entire site collection.

Check if this helps..

Laxmikant Rathi  Monday, July 21, 2008 5:54 AM

It doesn't look like your feature actually deploys the masterpage file. You need to have two files the Feature.xml and the ElementsFile.xml (name it whatever you want). The ElementsFile.xml contains the files you need to provision.

http://msdn.microsoft.com/en-us/library/ms441170.aspx

What you should do is use the VSEWSS extensions. Create an empty SharePoint project. Then add a SharePoint module (your masterpage) to the project.

Michael Washam - MSFT  Monday, July 21, 2008 12:41 PM

1) Here firstyou will have to install your MasterPage as a feature on the server.

Links below would help on feature stapling and installing master page as feature :

http://www.heathersolomon.com/blog/articles/servermstpageforsitecollect_feature.aspx

[Set Type="GhostableInLibrary" in ProvisionedFiles.xml ]

2) Nowbefore the lines to create a site in your code, add lines to programmatically activate your master page feature on the parent site.

(Help link : http://dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/02/22/how-to-programmatically-activate-a-feature.aspx)

Now when you activate the feature the master page should get added to the master page gallery and available for the entire site collection.

Check if this helps..

Laxmikant Rathi  Monday, July 21, 2008 5:54 AM
Hello, Rathi. Thank you for your quick reply. I really appreciate it !

I made a feature like below.

<?xml version="1.0" encoding="utf-8"?>
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657"
Title="Custom Master Pages"
Description="Custom master pages for use across multiple site collections."
Hidden="False"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>

and install it.

> stsadm -o installfeature -name CustomMasterPage
Operation completed successfully.

It seems to be success and I could also activate this feature by [Site Actions]->[Site Settings]->[SIte collection features].

But
I could not see my custom master file in my galleries of Master pages, and I could not find the link 'Master page' which means that I could not check if master file was registered or not.

The article you introduced me says that:

> The master pages are now ready to use on the site. Navigate to the Master Page settings by selecting Site Settings in
> the breadcrumbs and choosing Master Page. (Or Site Actions - Site Settings - Modify All Site Settings - Master
> page (under the Look and Feel submenu).

my 'Look and Feel' menu in [Site Actions]->[Site Settings] is like below. No 'Master Page' menu !!

- Title, description, and icon
- Tree view
- Site theme
- Top link bar
- Quick Launch
- Save site as template
- Reset to site definition

I don't know reason why... please give me some advice though this may be another different issue.

My environment is:
Windows Server 2003
SharePoint Services 3.0


best regards.
ishiro  Monday, July 21, 2008 8:35 AM

Hi,

Now as per ur steps you have installed the feature, now you need to activate it on your site.

As per my previous reply once you are done with install feature, activate the feature from your code.

(You can activate this from command line as well but as per your requirement you wanted to do it from code.)

Once you activate this feature, the Master page will get uploaded to the Master Page gallery. Master Page Gallery is only oneper site collection. So this would get added to the master page gallery of the top level site.

Master Page Menu :You would see this link only when you havepublishing featureactivated for your site.

Laxmikant Rathi  Monday, July 21, 2008 9:17 AM
Hello, Rathi. Thank you for your reply!

> Now as per ur steps you have installed the feature, now you need to activate it on your site.

> As per my previous reply once you are done with install feature, activate the feature from your code.


I did activate this feature from code but only to fail... the result was same as my post of previous....
I tried next two type.


Try 1 -> for Site Collection.

Feature.xml
------------------------------------------------------------------------------------------------------
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657"
Title="Custom Master Pages"
Description="Custom master pages for use across multiple site collections."
Hidden="False"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>
------------------------------------------------------------------------------------------------------

ProvisionedFile.xml
------------------------------------------------------------------------------------------------------
<!-- _lcid="1033" _version="12.0.4407" _dal="1" -->
<!-- _LocalBinding -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="OSGMasterPages" Url="_catalogs/masterpage" Path="MasterPages" RootWebOnly="TRUE">
<File Url="Sample.master" Type="GhostableInLibrary">
<Property Name="ContentType" Value="My Sample Master Page" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/sample.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/sample.png" />
<Property Name="MasterPageDescription" Value="This is my sample master page for use with collaboration or publishing sites." />
</File>
</Module>
<Module Name="PublishingLayoutsPreviewImages" Url="_catalogs/masterpage" IncludeFolders="??-??" Path="" RootWebOnly="TRUE">
<File Url="Sample.png" Name="Preview Images/Sample.png" Type="GhostableInLibrary">
</File>
</Module>
</Elements>
------------------------------------------------------------------------------------------------------

program.cs
------------------------------------------------------------------------------------------------------
string strUrl = "http://sampledomain:999";
string strChildName = "Mysite";

SPSite ParentSite = new SPSite(strUrl);
ParentSite.Features.Add(new Guid("{FDFCD4C4-F0D9-43b5-8739-A33681049657}"));
SPWeb ParentWeb = ParentSite.OpenWeb();
SPWeb ChildWeb = ParentWeb.Webs.Add(strChildName, strChildName, strChildName, (uint)1033, "STS#1", false, false);
ChildWeb.MasterUrl = "/_catalogs/masterpage/Sample.master";
ChildWeb.Update();
------------------------------------------------------------------------------------------------------

Install is finished successfully, but when I accessed to http://sampledomain:999/Mysite,
an error occured 'Go back to site. Error. File Not Found.'

I checked http://hddms:999/_layouts/ManageFeatures.aspx?Scope=Site, the feature was
activated correctly.


Try 2 -> for Site.

Feature.xml
------------------------------------------------------------------------------------------------------
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657"
Title="Custom Master Pages"
Description="Custom master pages for use across multiple site collections."
Hidden="False"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>
------------------------------------------------------------------------------------------------------

ProvisionedFile.xml
------------------------------------------------------------------------------------------------------
(same as up)
------------------------------------------------------------------------------------------------------

program.cs
------------------------------------------------------------------------------------------------------
string strUrl = "http://sampledomain:999";
string strChildName = "Mysite";

SPSite ParentSite = new SPSite(strUrl);
SPWeb ParentWeb = ParentSite.OpenWeb();
SPWeb ChildWeb = ParentWeb.Webs.Add(strChildName, strChildName, strChildName, (uint)1033, "STS#1", false, false);
ChildWeb.Features.Add(new Guid("{FDFCD4C4-F0D9-43b5-8739-A33681049657}"));
ChildWeb.MasterUrl = "/_catalogs/masterpage/Sample.master";
ChildWeb.Update();
------------------------------------------------------------------------------------------------------

Install is finished successfully, but when I accessed to http://sampledomain:999/Mysite,
an error occured 'Go back to site. Error. File Not Found.'

I checked http://hddms:999/License/_layouts/ManageFeatures.aspx, the feature was
activated correctly.


Umm... I read the article you told me again and again. but I don't know what happend...
something wrong with me???

> Master Page Menu :You would see this link only when you havepublishing featureactivated for your site.

Ok. thank you for telling me that. All I have to do is letting the feature work correctly.

best regards.

ishiro  Monday, July 21, 2008 10:53 AM

I'm sorry, I mistook url... I correct below. Smile

> I checked http://hddms:999/_layouts/ManageFeatures.aspx?Scope=Site, the feature was
> activated correctly.

http://sampledomain:999/_layouts/ManageFeatures.aspx

> I checked http://hddms:999/License/_layouts/ManageFeatures.aspx, the feature was
> activated correctly.

http://sampledomain:999/Mysite/_layouts/ManageFeatures.aspx
ishiro  Monday, July 21, 2008 11:05 AM

It doesn't look like your feature actually deploys the masterpage file. You need to have two files the Feature.xml and the ElementsFile.xml (name it whatever you want). The ElementsFile.xml contains the files you need to provision.

http://msdn.microsoft.com/en-us/library/ms441170.aspx

What you should do is use the VSEWSS extensions. Create an empty SharePoint project. Then add a SharePoint module (your masterpage) to the project.

Michael Washam - MSFT  Monday, July 21, 2008 12:41 PM
Hello, Washam. Thank you for your reply.

I could
accomplish my purpose!! My Feature.xml has not enough node. I managed to understand
the mechanism of feature now!!

Feature.xml [before]
--------------------------------------------------------------------------------------------------------------
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657"
Title="Custom Master Pages"
Description="Custom master pages for use across multiple site collections."
Hidden="False"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>
--------------------------------------------------------------------------------------------------------------


Feature.xml [after]
--------------------------------------------------------------------------------------------------------------
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657"
Title="Custom Master Pages"
Description="Custom master pages for use across multiple site collections."
Hidden="False"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ProvisionedFiles.xml" />
</ElementManifests>
</Feature>
--------------------------------------------------------------------------------------------------------------

I really appreciate some help of Rathi and Washam. I'm happy to get you Smile

best regards.
ishiro  Monday, July 21, 2008 4:36 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom Audit Log for the Logged in user details along with the time stamp
• How to find out the name of web part showing its web part error after a migration?
• Programatically save and stop editing
• Db authentication in sharepoint
• Find URL using web part
• SPSite Exception - Unable to reference Web Application unless on Sharepoint Server itself
• Consuming WCF web service from sharepoint
• Does a lot of http handler affect the performance?
• Users, groups and webservices
• is it possible to add analyze the item with msword in the actions button of discussionboard?