PowerShell, SharePoint, Technical

Missing Upload.aspx in a Document Library

A departure from my normal post…I usually try to stick to only posting solutions to weird situations I run into, or recommendations from real world experiences, or the occasional post on community or work activities. Not this time. This post technically falls into the first category (solution to a weird situation), but is really a cry for help. Smile

Problem Definition
The problem is having a document library that is missing the Upload.aspx form, which should be associated to the SPList.DefaultNewFormUrl property of the library. There are a few different ways to get there. I ran into it because of a web template I built that was missing the creation of the Upload.aspx file, so as sites were created with this template, everything worked fine except for “Upload Multiple Documents” and “New Folder” functionality. Both require the existence of the Upload.aspx file mapped to the DefaultNewFormUrl property to work properly. My bad.

Once the bug was identified, I fixed it in the template, but we still had existing sites that had the problem. Deploying a new version of the web template doesn’t retroactively fix existing sites, so we needed to find another solution.

Manual Fix
Although not ideal, there is a way to manually fix this issue:

  1. Open the site in SharePoint Designer and open “All Files” –> [Affected Doc Lib] –> Forms directory
  2. Right click, New, ASPX, name it “Upload.aspx”, and open the file
  3. Still in Designer, open another library with a good Upload.aspx file and open that file
  4. Copy the source from the good Upload.aspx file and paste it into the Upload.aspx source of the new file just created
  5. Change a few values in the properties of the ListFormWebPart:
    1. “Title” should be the title of the document library
    2. “ListName” should be the ID of the list, with curly brackets surrounding the ID
    3. “ListId” should be the ID of the list, without curly brackets
  6. Save the file

That should do it. Now you can upload multiple files, and create new folders. Sweet!

Desired Fix
Here’s where I deviate from my normal theme of blog postings. Although the manual fix is nice, what I really wanted was a way to script the fix so we could quickly and repeatedly update multiple libraries that were affected. This need leads me to PowerShell and figuring out how to add the Upload.aspx file to the affected libraries through a script.

After a bit of searching, I found a blog post on how to programmatically add a custom list form to a list. This was a great kick start to what I wanted to do. Converting that to PowerShell led to:

   1: $web = Get-SPWeb http://svr1/sites/teamportal/ProjectSite

   2: $badlib = $web.Lists["Change Requests"]

   3: $uploadfile = $badlib.RootFolder.Files.Add("/sites/teamportal/ProjectSite/ChangeRequests/Forms/Upload.aspx", [Microsoft.SharePoint.SPTemplateFileType]::FormPage)

   4: $limitedwebpartmanager = $uploadfile.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

   5: $webpart = New-Object Microsoft.SharePoint.WebPartPages.ListFormWebPart

   6: $webpart.ListId = $badlib.ID

   7: $webpart.PageType = [Microsoft.SharePoint.PAGETYPE]::PAGE_NEWFORM

   8: $limitedwebpartmanager.AddWebPart($webpart, "Main", 0)

   9: $badlib.DefaultNewFormUrl = "/sites/teamportal/ProjectSite/ChangeRequests/Forms/Upload.aspx"

Running this script added the Upload.aspx file to the library and properly associated it with the DefaultNewFormUrl property of the library. Multiple upload worked great. Adding a new folder was looking good…clicking on New Folder would open the correct form with the ribbon and Name field, but after clicking Save, would throw an error “Value does not fall within the expected range” for SPFileSystemObjectType when trying to create the folder.

For the life of me, I cannot figure out how to fix that! So here’s the challenge:  Duplicate this in your environment by creating a document library, opening the site in SharePoint Designer, open the Forms directory in the library, delete the Upload.aspx file, and then create a PowerShell script to add a new Upload.aspx file that works. If you make more progress than I did, please comment.

Thanks!

0 thoughts on “Missing Upload.aspx in a Document Library

  1. Hi Ryan,

    Thanks a lot for posting this script!
    It works just fine in my case and folders a created successfully.
    The only thing I have changed – the list url starts with “Lists” e.g. “Lists/ChangeRequests/Forms/Upload.aspx”
    Did you try to allow for management of content types in your library and add a Folder type as an allowed one?
    In my case that was not needed though…

  2. Hi, your manual approach to fixing the list worked great for me, thanks! Since we are on Office365 I can’t run the script…

  3. Hi Ryan,

    Thank you for your post.

    It was very much helpful for most of the document libraries.
    I d0 not know the reason why script is throwing below error for some libraries?

    ++++++++++++
    Add : You cannot call a method on a null-valued expression.
    At C:UploadFormcorrection.ps1:3 char:43
    + $uploadfile = $badlib.RootFolder.Files.Add <<<< ("/NosDocs/Ref/RH/PVInstances/Forms/Upload.aspx",
    [Microsoft.SharePoint.SPTemplateFileType]::FormPage)
    + CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    GetLimitedWebPartManager : You cannot call a method on a null-valued expression.
    At C:UploadFormcorrection.ps1:4 char:62
    + $limitedwebpartmanager = $uploadfile.GetLimitedWebPartManager <<<< ([System.Web.UI.WebControls.We
    bParts.PersonalizationScope]::Shared)
    + CategoryInfo : InvalidOperation: (GetLimitedWebPartManager:String) [], RuntimeExcep
    tion
    + FullyQualifiedErrorId : InvokeMethodOnNull

    . : Exception setting "ListId": "Cannot convert null to type "System.Guid"."
    At C:UploadFormcorrection.ps1:6 char:10
    + $webpart. <<<< ListId = $badlib.ID
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

    AddWebPart : You cannot call a method on a null-valued expression.
    At C:UploadFormcorrection.ps1:8 char:34
    + $limitedwebpartmanager.AddWebPart <<<< ($webpart, "Main", 0)
    + CategoryInfo : InvalidOperation: (AddWebPart:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    . : Property 'DefaultNewFormUrl' cannot be found on this object; make sure it exists and is settabl
    e.
    At C:UploadFormcorrection.ps1:9 char:9
    + $badlib. <<<< DefaultNewFormUrl = "/NosDocs/Ref/RH/PVInstances/Forms/Upload.aspx"
    + CategoryInfo : InvalidOperation: (DefaultNewFormUrl:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
    ++++++++++++

    Is is specific to List or Libraries?
    Or it works for both?

    Do we have any prerequisites before running the scrip?

    Thanks in advance
    Vikram

  4. Hi Ryan, great post !
    This worked for me but while I fixed one library, another one got corrupted.
    I have a site collection with 8 Libraries. 4 of them didn’t have the upload.aspx. I started to fix the first one. Worked! While I fixed the second one, the first one stopped working again…while I fixed third one, first and second one failed again…etc.
    I wonder if there are more values to fix than described in your blog above?

    Any further ideas are highly appreciated.
    Thanks in advance
    Wolfgang

Leave a Reply

Your email address will not be published. Required fields are marked *