3
  1. I use powershell to copy a site collection from production to dev. I never had issues before.

When I go to http://portal.company.net/sales I get following error

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /sales/default.aspx

Version Information: Microsoft .NET Framework Version:2.0.50727.5448; ASP.NET Version:2.0.50727.5456

Right click > View Source > gives me following message

The file /sales/_catalogs/masterpage/v4.master does not exist

I am able to navigate to _layouts/settings.aspx page but format is all messed up and it's plain text view with links.

I clicked on Master pages and page layouts and get the same 404 error. (_Layouts/RedirectPage.aspx?Target={SiteCollectionUrl}_catalogs/masterpage)

However, I can nagivate to "Site Content and Structure" Page and verified that v4.master does exists.

http://portal.company.com/sales/_Layouts/sitemanager.aspx?Source={WebUrl}_layouts/settings.aspx&Filter=1&FilterOnly=1

1 Answer 1

1

The master page has been messed up. You can use the following PowerShell to upload the master page to the Master Pages gallery again.

Run the below script by saving it as UploadMasterPages.ps1

Usage

powershell.exe -noexit .\UploadMasterPages.ps1 "http://sitecollection"

param($webAppUrl)

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Administration")

$checkInComment="Check In"
$publishComment="published"
$approveComment="Approved"
$logfile = "UploadMasterPage_$(get-date -f yyyyMMdd_hhmmss).log"
$spsite = new-object Microsoft.Sharepoint.SPSite($webAppUrl);
$web = $spsite.RootWeb;

    $masterPageList = ($web).GetFolder("Master Page Gallery")
    # Get file system path
$filesfolde = Split-Path $script:MyInvocation.MyCommand.Path

$masterPageLocalDir = $filesfolde + "\Docs"
    #For upload all files in document library from file system
foreach ($file in Get-ChildItem $masterPageLocalDir)
    {
    $web.AllowUnsafeUpdates=$true;
try
{
    if ([Microsoft.SharePoint.Publishing.PublishingSite]::IsPublishingSite($spsite)) 
    {

    $stream = [IO.File]::OpenRead($file.fullname)
          $destUrl = $web.Url + "/_catalogs/masterpage/" + $file.Name;
        $masterPageFile=$web.GetFile($destUrl)
    #write-host($masterPageFile)
           if($masterPageFile.CheckOutStatus -ne "None")
        {

                #$web.AllowUnsafeUpdates  = $true;
                $masterPageList.files.Add($destUrl,$stream,$true)


                $stream.close()                     
                $masterPageFile.CheckIn($checkInComment);                       
                 $masterPageFile.Publish($publishComment);              
                 $masterPageFile.Approve($approveComment);
                 $masterPageFile.Update();         
                     $web.Update();
                      $web.AllowUnsafeUpdates  = $false;
                      $outputText = $file.Name+ " Master Page uploaded on $web site"
                      write-output $outputText
                      write-output $outputText |  out-File $logfile -Append
        }
        else
        {
                 $masterPageFile.CheckOut();
                 try{
                 $masterPageList.Files.Add($destUrl,$stream,$true)
                 }
                 catch
                 {
                 write-Output $_
                 }
                 $stream.close()                              
                 $masterPageFile.CheckIn($checkInComment);                        
                 $masterPageFile.Publish($publishComment);                        
                 $masterPageFile.Approve($approveComment);
                 $masterPageFile.Update();         
                     $web.Update();
                      $web.AllowUnsafeUpdates  = $false;
                      $outputText = $file.Name +  " Master Page uploaded on $web site"
                      write-output $outputText
                      write-output $outputText |  out-File $logfile -Append
        }
    }

    else
    {

        $stream = [IO.File]::OpenRead($file.fullname)
            $destUrl = $web.Url + "/_catalogs/masterpage/" +$file.Name
        $masterPageFile=$web.GetFile($destUrl)
             if($masterPageFile.CheckOutStatus -ne "None")
          {
                $masterPageList.Files.Add($destUrl,$stream,$true)
                $stream.close()                     
                $masterPageFile.CheckIn($checkInComment);                       
                 $masterPageFile.Publish($publishComment);              
                 $masterPageFile.Approve($approveComment);
                 $masterPageFile.Update();         
                     $web.Update();
                      $web.AllowUnsafeUpdates  = $false;
                      $outputText = $file.Name +  "Master Page uploaded on $web site"
                      write-output $outputText
                      write-output $outputText |  out-File $logfile -Append
           }
           else
           {
                 $masterPageFile.CheckOut();
                 $masterPageList.Files.Add($destUrl,$stream,$true)
                 $stream.close()                              
                 $masterPageFile.CheckIn($checkInComment);                        
                 $masterPageFile.Publish($publishComment);                        
                 $masterPageFile.Approve($approveComment);
                 $masterPageFile.Update();         
                     $web.Update();
                      $web.AllowUnsafeUpdates  = $false;
                      $outputText = $file.Name+ "Master Page uploaded on $web site"
                      write-output $outputText
                      write-output $outputText |  out-File $logfile -Append
          }
    }


}
catch
{
try
       {


        $stream = [IO.File]::OpenRead($file.fullname)
            $destUrl = $web.Url + "/_catalogs/masterpage/" + $file.Name;
        $masterPageFile=$web.GetFile($destUrl)
             if($masterPageFile.CheckOutStatus -ne "None")
           {
                $masterPageList.Files.Add($destUrl,$stream,$true)
                $stream.close()                     
                $masterPageFile.CheckIn($checkInComment);
                $masterPageFile.Update();         
                     $web.Update();
                      $web.AllowUnsafeUpdates  = $false;
                      $outputText = $file.Name+ " Master Page uploaded on $web site"
                      write-output $outputText
                      write-output $outputText |  out-File $logfile -Append
           }
          else
            {

                 $masterPageFile.CheckOut();
                $masterPageList.Files.Add($destUrl,$stream,$true)
                $stream.close()                     
                $masterPageFile.CheckIn($checkInComment);
                $masterPageFile.Update();         
                     $web.Update();
                      $web.AllowUnsafeUpdates  = $false;
                      $outputText = $file.Name +" Master Page uploaded on $web site"
                      write-output $outputText
                      write-output $outputText |  out-File $logfile -Append
           }
       }
    catch
       {
        write-Output $_ | out-File $logfile -Append
       }     
}
}
$web.dispose();
$spsite.dispose();

Source: https://uploadmasterpages.codeplex.com/SourceControl/list/changesets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.