1

We are currently Planning to use link to documents to add reference to items that cannot be stored in SharePoint to be able to be reached by the users.

Is there a way to run a workflow or scheduled job to tell if the link document source exists or is available ?

SP Version: SP O365

1
  • Where are the real documents going to be stored? Somewhere on a shared drive? Apr 12, 2018 at 21:18

1 Answer 1

3

Yes, You can create a simple scheduled console application to be run on Prim using Windows scheduler, this app can check for the file existence, the below example for how you can check if the file URL is valid or not

private static bool IsFileExists(string fileUrl)
        {
            bool IsExists = false;
            try {

                HttpWebRequest request = WebRequest.Create(fileUrl) as HttpWebRequest;
                HttpStatusCode StatusCode = ((HttpWebResponse)request.GetResponse()).StatusCode;
                if (StatusCode == HttpStatusCode.OK)//file exist
                    IsExists = true;
                else // file does not exist
                    IsExists = false;
            }
            catch
            { IsExists=false; }

            return IsExists;
        }   

First you need to use System.Net add the below line

using System.Net;

If the storage location require authentication , you should handle the authentication in your code.

To use this app to connect to SharePoint online

you will need to add those reference

 Microsoft.SharePoint.Client
 Microsoft.SharePoint.Client.Runtime

and you need to add below using lines

using Microsoft.SharePoint.Client;
using System.Security;

The below example shows how to connect to SharePoint online from console application

 private static void SPConnect(string SiteUrl, string UserName, string Password)
        {

            ClientContext clientContext = new ClientContext(SiteUrl);
            SecureString securePassword = new SecureString();
            foreach (char c in Password.ToCharArray()) securePassword.AppendChar(c);
            clientContext.Credentials = new SharePointOnlineCredentials(UserName, securePassword); 
            Web web = clientContext.Web;
            clientContext.Load(web);
            clientContext.ExecuteQuery();

        }

For How Schedule Console Application Using Windows Scheduler check here

1
  • we are using SSO, so to connect to SPO we would need to use the authentication manager. other than that, this provides a good solution
    – Mike
    Apr 20, 2018 at 18:27

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.