If you have ever used SharePoint, you know what I’m talking about. You have a file you want to upload into a document library. Fantastic. You click Upload document from the ribbon, and get the dialog box below.
You have the option to “overwrite existing files” and it is checked by default. You want this under normal circumstances. You want to have versioning turned on in the library, so when you do overwrite an existing file, it retains the previous copy for prosperity and all forms of natural disasters.
However, I had a client (and there are others out there, you know who you are) who wanted the ability to have this setting unchecked by default for a specific library.
This is where everyone on the internet gives the easy answer. This answer is assuming you are on-premise of course (not using SharePoint Online in Office 365 or some other hosting version). The first thing to understand is that the dialog box you see (“Upload Document”) is the same file that is used for every single library in SharePoint!
So you are directed to go to the upload.aspx file in the 14 hive (2010) or 15 hive (2013). This file contains the actual code of the dialog box page. As directed, you crack open the file and go to the line that contains “Overwritesingle”. This is line 248 for me. You change the Checked=”true” to Checked=”false”. Save your file, refresh, and BLAM it’s unchecked.
Great! Except that remember I mentioned this one file is used everywhere? So guess what, it’s unchecked everywhere! That’s actually not what we want. We only want this on ONE library.
What you do is basically place this code in your master page, and the code checks if the library tied to the open dialog box matches the one you want by GUID. If it matches, it can hide or uncheck the control.
I just wanted to uncheck it, so I just used this line after the if statement:
You go back to your library, and you click the “Add document” link, and it works! It’s unchecked. You think your job is done and good to go. Alas, you’re not. And this brings me to the point of this blog.
if (location.href.indexOf('A9A5E8AC-3FC6-4279-AE8D-A7C8B9688209') >= 0)
) >= 0)
When you click Add document from the bottom of the page, it matches because the URL the code checks is in the same format (encoded):
Because this is encoded, it works. Now let’s look at the format when loaded from the Upload Document ribbon button:
Well strike one for Microsoft for consistency. Notice how the GUIDs are not encoded, meaning ugly raw HTML. Ok now we know why, and it’s an easy fix.
if ((location.href.indexOf(8CBCBFB4-B45D-43BD-A261-4BC3D8A09CC2') >= 0) || (location.href.indexOf(8CBCBFB4%2DB45D%2D43BD%2DA261%2D4BC3D8A09CC2) >= 0))
Of course be sure to replace the GUID with the ID of YOUR library. NOW our solution is fully functional!
After you’re done congratulating yourself, be sure to check out our upcoming events at https://events.c5insight.com. There are some great free webinars on SharePoint and other topics coming up for sure. But I want to call out that you’ve only got a few day left to get the lower price of our Business Workshop: Building A Roadmap for Intranet Collaboration Success. We hope to see you there!
The complementary paper includes over 12 years of research, recent survey results, and CRM turnaround success stories.
This 60-second assessment is designed to evaluate your organization's collaboration readiness.
Learn how you rank compared to organizations typically in years 1 to 5 of implementation - and which areas to focus on to improve.
This is a sandbox solution which can be activated per site collection to allow you to easily collect feedback from users into a custom Feedback list.
Whether you are upgrading to SharePoint Online, 2010, 2013 or the latest 2016, this checklist contains everything you need to know for a successful transition.