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.
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.
Although not ideal, there is a way to manually fix this issue:
- Open the site in SharePoint Designer and open “All Files” –> [Affected Doc Lib] –> Forms directory
- Right click, New, ASPX, name it “Upload.aspx”, and open the file
- Still in Designer, open another library with a good Upload.aspx file and open that file
- Copy the source from the good Upload.aspx file and paste it into the Upload.aspx source of the new file just created
- Change a few values in the properties of the ListFormWebPart:
- “Title” should be the title of the document library
- “ListName” should be the ID of the list, with curly brackets surrounding the ID
- “ListId” should be the ID of the list, without curly brackets
- Save the file
That should do it. Now you can upload multiple files, and create new folders. Sweet!
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:
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.