Am using Map Network Drive in Windows Explorer to add a Sharepoint folder. This link is valid for the lifetime of the security token that Sharepoint returns (say 10 hours). When the token expires, the only way to access the mapped drive is by re-logging on to Sharepoint online from the browser.

Is it possible to programmatically refresh the token pre or post expiration using cached credentials that avoids this re-logon step, say through a console app that can be run manually or scheduled? I have come across several samples that login to SPO by supplying a username and password, but this won't work in my case because SPO is configured to use windows authentication via ADFS. I have also come across samples that modify the global.asax to refresh the token, but not sure if this will work in my case either, because the SP installation is in the cloud and I don't know if I can modify global.asax in this case.

1 Answer 1


Please take a look at this thread: Mounted Office 365 sharepoint workspaces lose connectivity - how to fix?

I proposed an answer using PowerShell but the original poster has not had a chance to implement it. Basically it is a PowerShell script that logs into the site and then accesses a web page. Please let me know if this works I am very curious about this.

Here is some code adapted for your case:

$request = [System.Net.WebRequest]::Create("http://portal.domain.com/");

$credCache = [System.Net.CredentialCache]::DefaultCredentials;
$request.Credentials = $credCache;

$response = $request.GetResponse();
$requestStream = $response.GetResponseStream();
$readStream = new-object System.IO.StreamReader $requestStream
$data = $readStream.ReadToEnd()
  • Any idea what proxy server is giving the 407 error? Is it same to assume it is on your network? Commented Apr 2, 2012 at 20:08
  • Robert, I tried using your code and ran into: "(407) Proxy Authentication Required." I then added the following lines: ` $request.Proxy = [System.Net.WebRequest].DefaultWebProxy; request.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;` but got: "Property 'Credentials' cannot be found on this object; make sure it exists and is settable. " I then converted the script to a C# program. Now, I get a Unhandled Exception: System.Net.WebException: The remote server returned an error: (403) Forbidden.
    – cs31415
    Commented Apr 2, 2012 at 20:21
  • Yes, it is a proxy on our intranet.
    – cs31415
    Commented Apr 2, 2012 at 20:24
  • The 'Credentials' error was a goof-up on my part. This code now also produces the 403 error: $request.Proxy = [System.Net.WebRequest]::DefaultWebProxy; $request.Proxy.Credentials = $credCache;
    – cs31415
    Commented Apr 2, 2012 at 20:41
  • Found this link which fixed the 403 error: razirais.wordpress.com/2011/05/19/… but now getting back a page with message "Microsoft Online Services requires JavaScript to sign in. This web browser either does not support JavaScript, or scripts are being b locked."
    – cs31415
    Commented Apr 2, 2012 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.