Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MasterPage, application.master, several sites collections

Posted on 2007-02-16
5
Medium Priority
?
641 Views
Last Modified: 2008-06-21
Hy,

I have 2 sites collection on my WSS2007 server. I have 2 customize master page for earch site collection. Now I want to apply the master page to the in the _layout folder. I found in this site how to link the page from the application.master to a custom masterpage. http://www.sharepointblogs.com/dwise/archive/2007/01/08/SingleMasterPage.aspx 
But the problem is that I have 2 master pages for each site collection.

Is there a way to select a custom master page for page in the _layout folder for each of my master page?
0
Comment
Question by:MerlinMM3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 11

Expert Comment

by:G0ggy
ID: 18561614
Have a read of this article, dynamically changing the master page is about 3/4 of the way down, maybe it will help:

http://msdn2.microsoft.com/en-us/library/ehszf8ax(vs.80).aspx
0
 

Author Comment

by:MerlinMM3
ID: 18573134
Hy,

The link helps me a bit but I mostly use another source to help me.

I successfully made some modification to the code on site to make it work. I integrated some code from this site: http://weblogs.asp.net/soever/archive/2006/11/14/SharePoint-2007_3A00_-using-the-masterpage-from-your-site-in-custom-_5F00_layouts-pages.aspx 

Now my code work for several sites collection. It assumes that I have the new application.master in the _catalog/masterpage/ folder for each site collection. It also assume that all site collection are under the url /sites/…

I have some difficulties to implement a test to be sure the file exit in the folder _catalog. If the new application.master doesn’t exist the code should do nothing (use the default one).

Some can help with that part.

Here my code

using System;
using System.Web;
using System.Web.UI;
using System.IO;
using Microsoft.SharePoint;


namespace MasterPage
{
    public class MasterPageModule : IHttpModule
    {
        //HttpContext _Context = null;
        public void Init(HttpApplication context)
        {
            //_Context = context.Context;
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
        }
        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            Page page = HttpContext.Current.CurrentHandler as Page;
            if (page != null)
            {
                page.PreInit += new EventHandler(page_PreInit);
            }
        }          
        void page_PreInit(object sender, EventArgs e)
        {
            Page page = sender as Page;
            try
            {
                if (page != null)
                {
                    // Is there a master page defined?
                    if (page.MasterPageFile != null)
                    {

                        // only change the application.master files as those are the offenders
                        if (page.MasterPageFile.Contains("application.master"))
                        {
                           
                            SPWeb myWeb = Microsoft.SharePoint.WebControls.SPControl.GetContextSite(System.Web.HttpContext.Current).OpenWeb();
                            string strUrl = myWeb.Site + "/_catalogs/masterpage/application.master";
                            strUrl = strUrl.Substring(strUrl.IndexOf("/site"));
                            page.MasterPageFile = strUrl;

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                page.Response.Write(ex.Message);
                page.Response.End();
            }
        }

        public void Dispose()
        {
        }
    }
}
0
 

Author Comment

by:MerlinMM3
ID: 18592978
With little searching I found :

    public static bool RemoteFileExists(string FilePath)
    {
        try
        {
            HttpWebRequest webRequ = WebRequest.Create(FilePath) as HttpWebRequest;
            HttpWebResponse webResp = (HttpWebResponse) webRequ.GetResponse();
            return true; //because url is found
        }
        catch
        {
            return false; //because url not found
        }
    }
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 19251944
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question