public AppContextSite(string json) { if (json == String.Empty) { return; } dynamic jobject = Newtonsoft.Json.JsonConvert.DeserializeObject(json); dynamic refObj = jobject; if (jobject.d != null) { refObj = jobject.d; } string errInfo = ""; if (refObj.results != null) { if (refObj.results.Count > 1) { errInfo = "Result is Collection, only 1. entry displayed."; } refObj = refObj.results[0]; } List <string> usedFields = new List <string>(); usedFields.Add("__HMSError"); HMS.SP.SPUtil.dyn_ValueSet("__HMSError", refObj, this); usedFields.Add("__deferred"); this.__deferred_ = new SP.__deferred(HMS.SP.SPUtil.dyn_toString(refObj.__deferred)); usedFields.Add("__metadata"); this.__metadata_ = new SP.__metadata(HMS.SP.SPUtil.dyn_toString(refObj.__metadata)); usedFields.Add("Site"); this.Site_ = new SP.Site(HMS.SP.SPUtil.dyn_toString(refObj.Site)); usedFields.Add("Web"); this.Web_ = new SP.Web(HMS.SP.SPUtil.dyn_toString(refObj.Web)); this.__rest = new Dictionary <string, string>(); var dyn = ((Newtonsoft.Json.Linq.JContainer)refObj).First; while (dyn != null) { string Name = ((Newtonsoft.Json.Linq.JProperty)dyn).Name; string Value = ((Newtonsoft.Json.Linq.JProperty)dyn).Value.ToString(); if (!usedFields.Contains(Name)) { this.__rest.Add(Name, Value); } dyn = dyn.Next; } if (errInfo != "") { this.__HMSError_.info = errInfo; } }
public ClientContext(string json) { if (json == String.Empty) { return; } dynamic jobject = Newtonsoft.Json.JsonConvert.DeserializeObject(json); dynamic refObj = jobject; if (jobject.d != null) { refObj = jobject.d; } string errInfo = ""; if (refObj.results != null) { if (refObj.results.Count > 1) { errInfo = "Result is Collection, only 1. entry displayed."; } refObj = refObj.results[0]; } List <string> usedFields = new List <string>(); usedFields.Add("__HMSError"); HMS.SP.SPUtil.dyn_ValueSet("__HMSError", refObj, this); usedFields.Add("__deferred"); this.__deferred_ = new SP.__deferred(HMS.SP.SPUtil.dyn_toString(refObj.__deferred)); usedFields.Add("__metadata"); this.__metadata_ = new SP.__metadata(HMS.SP.SPUtil.dyn_toString(refObj.__metadata)); usedFields.Add("ApplicationName"); HMS.SP.SPUtil.dyn_ValueSet("ApplicationName", refObj, this); usedFields.Add("Current"); this.Current_ = new SP.ClientContext(HMS.SP.SPUtil.dyn_toString(refObj.Current)); usedFields.Add("FormDigestHandlingEnabled"); HMS.SP.SPUtil.dyn_ValueSet("FormDigestHandlingEnabled", refObj, this); usedFields.Add("HasPendingRequest"); HMS.SP.SPUtil.dyn_ValueSet("HasPendingRequest", refObj, this); usedFields.Add("PendingRequest"); HMS.SP.SPUtil.dyn_ValueSet("PendingRequest", refObj, this); usedFields.Add("RequestTimeout"); HMS.SP.SPUtil.dyn_ValueSet("RequestTimeout", refObj, this); usedFields.Add("ServerLibraryVersion"); HMS.SP.SPUtil.dyn_ValueSet("ServerLibraryVersion", refObj, this); usedFields.Add("ServerSchemaVersion"); HMS.SP.SPUtil.dyn_ValueSet("ServerSchemaVersion", refObj, this); usedFields.Add("ServerVersion"); HMS.SP.SPUtil.dyn_ValueSet("ServerVersion", refObj, this); usedFields.Add("Site"); this.Site_ = new SP.Site(HMS.SP.SPUtil.dyn_toString(refObj.Site)); usedFields.Add("TraceCorrelationId"); HMS.SP.SPUtil.dyn_ValueSet("TraceCorrelationId", refObj, this); usedFields.Add("Url"); HMS.SP.SPUtil.dyn_ValueSet("Url", refObj, this); usedFields.Add("Web"); this.Web_ = new SP.Web(HMS.SP.SPUtil.dyn_toString(refObj.Web)); this.__rest = new Dictionary <string, string>(); var dyn = ((Newtonsoft.Json.Linq.JContainer)refObj).First; while (dyn != null) { string Name = ((Newtonsoft.Json.Linq.JProperty)dyn).Name; string Value = ((Newtonsoft.Json.Linq.JProperty)dyn).Value.ToString(); if (!usedFields.Contains(Name)) { this.__rest.Add(Name, Value); } dyn = dyn.Next; } if (errInfo != "") { this.__HMSError_.info = errInfo; } }
internal void SPUploader(Stream fs, string fn) { ClientContext context = new ClientContext("http://Sharepointsite");///SitePages/Home.aspx"); System.Net.ICredentials creds = System.Net.CredentialCache.DefaultCredentials; context.Credentials = creds; context.RequestTimeout = 60000000; // Time in milliseconds string url = "/Members/"; string fileName = Path.GetFileName(fn); string fnUrl = url + fn; Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, fnUrl, fs, true); string uniqueRefNo = GetNextDocRefNo(); SP.Web web = context.Web; Microsoft.SharePoint.Client.File newFile = web.GetFileByServerRelativeUrl(fnUrl); context.Load(newFile); context.ExecuteQuery(); Web site = context.Web; List docList = site.Lists.GetByTitle("Members"); context.Load(docList); context.ExecuteQuery(); context.Load(docList.Fields.GetByTitle("Workflow Number")); context.Load(docList.Fields.GetByTitle("Agreement Number")); context.Load(docList.Fields.GetByTitle("First Name")); context.Load(docList.Fields.GetByTitle("Surname")); context.Load(docList.Fields.GetByTitle("ID Number")); context.Load(docList.Fields.GetByTitle("Date of Birth")); context.Load(docList.Fields.GetByTitle("Country")); context.Load(docList.Fields.GetByTitle("Document Description")); context.Load(docList.Fields.GetByTitle("Document Type")); context.Load(docList.Fields.GetByTitle("Document Group")); context.ExecuteQuery(); *********NEED TO GET THE INTERNAL COLUMN NAMES FROM SHAREPOINT************ var name = docList.Fields.GetByTitle("Workflow Number").InternalName; var name2 = docList.Fields.GetByTitle("Agreement Number").InternalName; var name3 = docList.Fields.GetByTitle("First Name").InternalName; var name4 = docList.Fields.GetByTitle("Surname").InternalName; var name5 = docList.Fields.GetByTitle("ID Number").InternalName; var name6 = docList.Fields.GetByTitle("Date of Birth").InternalName; var name7 = docList.Fields.GetByTitle("Country").InternalName; var name8 = docList.Fields.GetByTitle("Document Description").InternalName; var name9 = docList.Fields.GetByTitle("Document Type").InternalName; var name10 = docList.Fields.GetByTitle("Document Group").InternalName; var name11 = docList.Fields.GetByTitle("Unique Document Ref No").InternalName; **********NOW SAVE THE METADATA TO SHAREPOINT********** newFile.ListItemAllFields[name] = "927015"; newFile.ListItemAllFields[name2] = "1234565"; newFile.ListItemAllFields[name3] = "Joe"; newFile.ListItemAllFields[name4] = "Soap"; newFile.ListItemAllFields[name5] = "7502015147852"; newFile.ListItemAllFields[name6] = "1975-02-01"; newFile.ListItemAllFields[name7] = "ZA"; newFile.ListItemAllFields[name8] = "Test"; newFile.ListItemAllFields[name9] = "Requirements"; newFile.ListItemAllFields[name10] = "Requirements"; newFile.ListItemAllFields[name11] = uniqueRefNo; newFile.ListItemAllFields.Update(); context.Load(newFile); context.ExecuteQuery();