Monday, January 29, 2018

Refresh Mapped SharePoint Folders & Fix the "Not Accessible" Error Message

PROBLEM

If you have mapped network drives to SharePoint document libraries, when accessing it from File Explorer you'll occasionally get the error:

[path to your folder] is not accessible.  You might not have permission to use this network resource.  Contact the administrator of this server to find out if you have access permissions.

Access Denied.  Before opening files in this location, you must first add the website to your trusted sites list, browse to the web site, and select the option to login automatically.
There doesn't seem to be any way you can make this completely go away, but by using some javascript to mimic the action, you can create an easy way for your end users to correct that problem.

SOLUTION

Our solution was to create a desktop shortcut, which users can double-click, that will reauthenticate the user and remedy the issue.

When clicked, an instance of IE will be opened, to a page where we will mimic the "Open with Explorer" functionality, and ultimately the File Explorer will be displayed.

So let's get started.

If you create a page on your site (e.g. OpenWithExplorer.aspx), add a content web part, and in the html add the following code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

$(document).ready(function() {
// This is the default url to open if no parameter is passed
var url = 'https://vivity.sharepoint.com/Documents';

// See if there is a url parameter, if so grab it.
var qsUrl = getParameterByName("url", window.location.href);

// If it exists, change the default url
if (qsUrl != null)
{
url = qsUrl;
}

// Open up Explorer with our url
CoreInvoke('NavigateHttpFolder', url, '_blank');
});
</script>

Then create a desktop shortcut (right-click on the Desktop, select New -> Shortcut), and set the target to:

"C:\Program Files\Internet Explorer\iexplore.exe" https://vivity.sharepoint.com/Pages/OpenWithExplorer.aspx?url=https://vivity.sharepoint.com/sites/HR/Shared%20Documents

with the url parameter the path to the folder you want to open.

and set the Start in to:  "C:\Program Files\Internet Explorer", and optionally change the icon.


You'll then have an icon on your desktop, which when you double-click it will:

      1) Open up an instance of IE
      2) Open up the library in File Explorer


Or you can just as easily create a powershell script and run it with a hidden IE window:

$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("https://vivity.sharepoint.com/Pages/OpenWithExplorer.aspx")

No comments: