【问题标题】:How can I create a new form for a SharePoint list in PowerShell?如何在 PowerShell 中为 SharePoint 列表创建新表单?
【发布时间】:2014-08-01 03:47:56
【问题描述】:

我发现了there's no easy way to just upload a file to a list's SPFolder and make it work as a form 的困难之处。 (如果有,请纠正我,因为尝试这种方法的人似乎和我一样失败了......文件上传但从未被识别为表单。)

有没有一种更简单的方法可以从头开始创建新表单并向其中添加 Web 部件?我已经尝试发送一个空的表单文件,甚至是一个空白的文本文件,并且在大概将 Web 部件添加到它们之后,它们会生成相同的空壳......理论上,这应该有项目,但它是什么都不显示,并且完全忽略了我在“添加”后将项目注入表单的尝试。

“虚拟形式”尝试:

Write-Host > DoubleDummy.aspx
$file = Get-ChildItem -LiteralPath "DoubleDummy.aspx"
Add-SPFormFile $list.rootFolder $file $newname

结果(它实际上在浏览器中什么都不显示):

<%@ Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage..."  %>
<%@ Register Tagprefix="SharePoint"  ... %>
...
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<SharePoint:UIVersionedContent UIVersion="4" runat="server">
    <ContentTemplate>
    <div style="padding-left:5px">
    </ContentTemplate>
</SharePoint:UIVersionedContent>
    <table cellpadding="0" cellspacing="0" id="onetIDListForm" style="width:100%">
     <tr>
     <td>
     <WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"><ZoneTemplate>
        <WebPartPages:DataFormWebPart... PageType="PAGE_EDITFORM" FrameState="Normal" ...>
....

【问题讨论】:

    标签: powershell sharepoint sharepoint-2010


    【解决方案1】:

    对于列表 $list 和网站 $web 上的表单,以下代码有效。 Add() 有很多覆盖,其中没有一个会采用 both 默认表单类型 允许覆盖的布尔值,因此有一个“条件”删除我写到这里。

    $rootFolder = $list.RootFolder
    $part0 = $web.ServerRelativeUrl
    $part1 = $rootFolder.URL
    $newFormUrl = "${part0}/${part1}/${newname}"
    
    # Delete file first.
    try {
        $list.RootFolder.Files.Delete($list.RootFolder.Files[$newFormUrl].url)
    } catch {
        # It's optional.
        Write-Host "Delete failed."
    }
    $done = $list.RootFolder.Files.Add($newFormUrl,
            [Microsoft.SharePoint.SPTemplateFileType]::FormPage)
    

    【讨论】:

      猜你喜欢
      • 2017-08-19
      • 2013-06-09
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-08
      • 1970-01-01
      相关资源
      最近更新 更多