I would like to upload and associate customized version of Editform.aspx and displayform.aspx using SharePoint designer to one of my Custom List in production and make them default. I have tried using SPFiles.Add, filestream and [Microsoft.SharePoint.SPTemplateFileType]::FormPage but contents which I customized using SharePoint designer are wiped off and I see complete new version of http://ift.tt/1v9UFlD like I am missing something here? Please advise.
function UploadFileInLibrary
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string]$webUrl,
[Parameter(Mandatory=$true)]
[string]$DocLibName,
[Parameter(Mandatory=$true)]
[string]$FilePath
)
Start-SPAssignment -Global
$spWeb = Get-SPWeb -Identity $webUrl
$spWeb.AllowUnsafeUpdates = $true;
$List = $spWeb.Lists[$DocLibName]
$folder = $List.RootFolder
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1)
$File= Get-ChildItem $FilePath
#$spFile = $spWeb.GetFile($File.Name)
#$spFile = $spWeb.GetFile("http://Server:1408/sites/TestPowerShell/Mylist/DispObservation.aspx")
$flagConfirm = 'y'
if($spFile.Exists -eq $true)
{
$flagConfirm = Read-Host "File $FileName already exists in library $DocLibName, do you want to upload a new version(y/n)?"
}
if ($flagConfirm -eq 'y' -or $flagConfirm -eq 'Y')
{
$fileStream = ([System.IO.FileInfo] (Get-Item $File.FullName)).OpenRead()
#Add file
write-host -NoNewLine -f yellow "Copying file " $File.Name " to "
$folder.ServerRelativeUrl "..."
$spFile = $spWeb.Files.Add('DispObservation.aspx',$fileStream,$true)
try
{
$List.RootFolder.Files['DispObservation.aspx'].Delete()
}
catch{}
$List.RootFolder.Files.Add($spWeb.ServerRelativeUrl,[Microsoft.SharePoint.SPTemplateFileType]::FormPage)
$List.RootFolder.Files.Add("http://nlams10824:1408/sites/TestPowerShell/Observations1/",$spFile.OpenBinary(),$true)
$List.Update()
}
$spWeb.AllowUnsafeUpdates = $false;
Stop-SPAssignment -Global
} UploadFileInLibrary "SharePointServer" "Mylist" "C:\CustomListsPOC\Forms\DispObservation.aspx"
0 commentaires:
Enregistrer un commentaire