download a file from sharepoint online using caml and by filename

  • Thread starter Thread starter msdnpublic1234
  • Start date Start date
M

msdnpublic1234

Guest
Hi,

Here is my code and i am getting exception "The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. - "

in the this line of the code: var list = context.Web.Lists.GetByTitle(library);

Below is the whole code:-

public void Main()
{
var site = (string)Dts.Variables["$Package::SiteUrl"].Value;
var library = (string)Dts.Variables["$Package::Library"].Value;
var directory = (string)Dts.Variables["$Package::fileDestination"].Value;
var ErrorFile = (string)Dts.Variables["$Package::ErrorLog"].Value;
var filename_1 = (string)Dts.Variables["User::fileName_1"].Value;

try
{
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =

@"<View>

<Query>

<Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + filename_1 + @"</Value></Eq></Where>

</Query>

<ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /></ViewFields>

</View>";
ClientContext context = new ClientContext(site);
var securePassword = new SecureString();
var password = "1234abc";

foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials(@"johnd@xyz.com", securePassword);
var list = context.Web.Lists.GetByTitle(library);
ListItemCollection listItems = list.GetItems(camlQuery);

context.Load(listItems);

context.ExecuteQuery();

var listItem = listItems.FirstOrDefault();

}

Pls guide me through this.

Continue reading...
 

Similar threads

M
Replies
0
Views
224
msdnpublic1234
M
M
Replies
0
Views
79
msdnpublic1234
M
I
Replies
0
Views
83
IndigoMontoya
I
Back
Top