sharepoint online - HttpContext is null when running an HangFire job in provider hosted app -


i have set scheduled background job @ point when user uploads document

backgroundjob.schedule(() => moveuserdocument(document.filename), timespan.fromdays(1)) 

the background job should trigger below code, problem httpcontext null.

i grateful if can point me in right direction.

public actionresult moveuserdocument(string filename) {      var documentcomments = new list<string>();     user spuser = null;     var username = "";     var id = "";     var title = "";     var emailaddress = "";     var spcontext = sharepointcontextprovider.current.getsharepointcontext(httpcontext);     var document = spcontext.documents.singleordefault(c => filename == c.documentname);     id = document.id.tostring();     title = document.title;     emailaddress = document.emailaddress;     using (var clientcontext = spcontext.createuserclientcontextforsphost()) {         if (clientcontext != null) {             spuser = clientcontext.web.currentuser;             clientcontext.load(spuser, user => user.title);             clientcontext.executequery();             viewbag.username = spuser.title;             username = spuser.title;         }         var targeturl = "/masterlibrary";         var targetfileurl = string.format("{0}/{1}", targeturl, filename);         var targetdocumenturl = "masterlibrary";         var documenturl = string.format("{0}{1}/{2}", spcontext.sphosturl.absoluteuri, targetdocumenturl, filename);         listitem item = clientcontext.web.lists.getbytitle("documentreview").getitembyid(id);         clientcontext.load(item);         clientcontext.executequery();         if (item.filesystemobjecttype == filesystemobjecttype.file) {             microsoft.sharepoint.client.file file = item.file;             clientcontext.load(file);             clientcontext.executequery();             file.moveto(targetfileurl, moveoperations.overwrite);             var uploadedfile = clientcontext.web.getfilebyserverrelativeurl(targetfileurl);             var listitem = uploadedfile.listitemallfields;             listitem["originaldocumentid"] = id;             listitem["documenturl"] = documenturl;             listitem.update();             clientcontext.executequery();         }         var commentsurl = string.format("{0}/{1}/{2}/{3}?sphosturl={4}", "https://localhost:44323", "home", "viewdocumentcomments", id, spcontext.sphosturl.absoluteuri);         var email = new commentsemail(emailaddress, username, commentsurl, title);         email.send();     }     return redirecttoaction("documentreviewlibrary", new { sphosturl = sharepointcontext.getsphosturl(httpcontext.request).absoluteuri }); } 

thanks


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -