5

Is there any way to dynamically add metadata in the upload file. I am using the following code in this regard.

File uploadFile = context.Web.GetFileByServerRelativeUrl(location);
//check out to make sure not to create multiple versions
if (!list.ForceCheckout)
    uploadFile.CheckOut();

//setting metadata here
uploadFile.ListItemAllFields["Status"] = "In-Progress";
uploadFile.ListItemAllFields.Update();
context.Load(uploadFile);
context.ExecuteQuery();

//overwrite to make sure not to create multiple versions
uploadFile.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
context.Load(uploadFile);
context.ExecuteQuery();

Upon running above code, i am getting this error:

Column 'Status' does not exist. It may have been deleted by another user.

Now is there any way to dynamically create it programmatically because i preferably don't want to create it using designer?

0

For adding status column :

            List list = web.Lists.GetByTitle(listname);
            Field fild = web.Fields.GetByInternalNameOrTitle("Status");
            list.Fields.Add(fild);
            list.Update();
            context.ExecuteQuery();

Try with internal name of status column:

uploadFile.ListItemAllFields["_Status"] = "In-Progress";

  • Still the same error. – Furqan Safdar May 27 '14 at 9:33
  • At what line you are getting error. There are 2 status columns in sharepoint. One with static name "_Status" and one with "DecisionStatus". You can try with 2nd one. – Aanchal May 27 '14 at 9:51
  • So you have not added the status column in sharepoint library? – Aanchal May 27 '14 at 9:58
  • First add the status column then update. I have added the code to add create site column – Aanchal May 27 '14 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.