How to solve feild and property not initialized exception in c#.net when retriving sharepoint list

%3CLINGO-SUB%20id%3D%22lingo-sub-1077837%22%20slang%3D%22en-US%22%3EHow%20to%20solve%20feild%20and%20property%20not%20initialized%20exception%20in%20c%23.net%20when%20retriving%20sharepoint%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1077837%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%2C%3C%2FP%3E%3CP%3Ei%20got%20exception%20fieldorproperty%20not%20initialized%26nbsp%3B%20while%20creating%20client%20context%20variable%20when%20fetching%20sharepoint%20list%20data%20in%20c%23.net%20project%3C%2FP%3E%3CP%3Efollowing%20is%26nbsp%3B%20code%26nbsp%3B%3C%2FP%3E%3CP%3Econst%20string%20siteurl%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Findica.sharepoint.com%2Fsites%2FDemoBot%2FLists%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Findica.sharepoint.com%2Fsites%2FDemoBot%2FLists%3C%2FA%3E%22%3B%3CBR%20%2F%3Estring%20login%20%3D%20%22teb%40ind%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F162897i2591CBE4E5A99914%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22error.png%22%20title%3D%22error.png%22%20%2F%3E%3C%2FSPAN%3E.onmicrosoft.com%22%3B%3CBR%20%2F%3Estring%20password%20%3D%20%22abcsd%22%3B%3CBR%20%2F%3Econst%20string%20listname%20%3D%20%22ListDemoBot%22%3B%3CBR%20%2F%3Estring%20result%20%3D%20string.Empty%3B%3CBR%20%2F%3Evar%20securepassword%20%3D%20new%20SecureString()%3B%3C%2FP%3E%3CP%3Etry%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eforeach%20(var%20c%20in%20password)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Esecurepassword.AppendChar(c)%3B%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3Evar%20credential%20%3D%20new%20sp.SharePointOnlineCredentials(login%2C%20securepassword)%3B%3CBR%20%2F%3Esp.ClientContext%20clientcontext%20%3D%20new%20sp.ClientContext(siteurl)%3B%3CBR%20%2F%3Eclientcontext.Credentials%20%3D%20credential%3B%3CBR%20%2F%3Esp.List%20olist%20%3D%20clientcontext.Web.Lists.GetByTitle(listname)%3B%3CBR%20%2F%3Esp.CamlQuery%20calmquery%20%3D%20new%20sp.CamlQuery()%3B%3CBR%20%2F%3Evar%20username%20%3D%20%22Test1%22%3B%3CBR%20%2F%3Ecalmquery.ViewXml%20%3D%20%24%22%3CVIEW%3E%3CQUERY%3E%3CWHERE%3E%22%20%2B%20%24%22%3CEQ%3E%3CFIELDREF%20name%3D%22'Title'%2F%22%3E%26lt%3B%20Value%20Type%20%3D%20'Text'%20%26gt%3B%7Busername%7D%20%20%22%20%2B%20%24%22%3C%2FFIELDREF%3E%3C%2FEQ%3E%3CROWLIMIT%3E1%3C%2FROWLIMIT%3E%3C%2FWHERE%3E%22%3B%3CBR%20%2F%3Esp.ListItemCollection%20collistItem%20%3D%20olist.GetItems(calmquery)%3B%3CBR%20%2F%3Eclientcontext.Load(collistItem)%3B%3CBR%20%2F%3Eclientcontext.ExecuteQuery()%3B%3C%2FQUERY%3E%3C%2FVIEW%3E%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3Ecatch%3CBR%20%2F%3E%7B%3CBR%20%2F%3Ethrow%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1077837%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1078969%22%20slang%3D%22es-ES%22%3ERe%3A%20How%20to%20solve%20feild%20and%20property%20not%20initialized%20exception%20in%20c.net%20when%20retriving%20sharepoint%20l%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1078969%22%20slang%3D%22es-ES%22%3E%3CP%3EExcuse%20me%2C%20but%20could%20you%20guide%20me%20how%20I%20can%20start%20programming%20for%20SharePoint%20Online%3F%20%3CBR%20%2F%3EI'm%20looking%20online%2C%20but%20I%20find%20everything%20for%20onpremise.%20%3CBR%20%2F%3EThank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi ,

i got exception fieldorproperty not initialized  while creating client context variable when fetching sharepoint list data in c#.net project

following is  code 

const string siteurl = "https://indica.sharepoint.com/sites/DemoBot/Lists";
string login = "teb@inderror.png.onmicrosoft.com";
string password = "abcsd";
const string listname = "ListDemoBot";
string result = string.Empty;
var securepassword = new SecureString();

try
{
foreach (var c in password)
{
securepassword.AppendChar(c);

}

var credential = new sp.SharePointOnlineCredentials(login, securepassword);
sp.ClientContext clientcontext = new sp.ClientContext(siteurl);
clientcontext.Credentials = credential;
sp.List olist = clientcontext.Web.Lists.GetByTitle(listname);
sp.CamlQuery calmquery = new sp.CamlQuery();
var username = "Test1";
calmquery.ViewXml = $"<View><Query><Where>" + $"<Eq><FieldRef Name='Title'/>< Value Type = 'Text' >{username}</ Value > </ Eq > " + $"</Where></Query><RowLimit>1</RowLimit></View>";
sp.ListItemCollection collistItem = olist.GetItems(calmquery);
clientcontext.Load(collistItem);
clientcontext.ExecuteQuery();

}

catch
{
throw;
}

1 Reply

Disculpá, pero me podrías orientar como puedo comenzar a programar para SharePoint Online?
Busco por internet pero encuentro todo para onpremise.
Gracias