I'm creating list and adding fields to it from code (since I need to do it dynamically), but there is a problem with one field, that I create last (Multi line/Note) and when I try to add data to it, I get an error: Field WorkflowData does not exist. Possible, that other user has deleted it

Code part

Field name: private static string _workflowInfo = "WorkflowData";

Creating field:

Field fApproval = newList.Fields.AddFieldAsXml(string.Format("<Field DisplayName='{0}' Type='{1}' />", _workflowInfo, FieldType.Note),

Adding Data to field:

newItem[_workflowInfo] = workflowInfo.ToString(); // Or any data, tried to add just string as well, didn't work


Although that field exsists on my Item and cDestination.ExecuteQuery() works passes without errors:

enter image description here


The field exists on the list

enter image description here

enter image description here

Found the problem

Problem was, that when I was uploading my file to SharePoint, I technically just took old File and added it to new eviorment. So all metadata from that file came through and including Context.Url, which means, when I tried to add my WorkflowData info to it, it didn't find that field, since it didn't exist on old list.

Here is a pice of code, that works:

// Get file collection to add new documents to
FileCollection destFiles = cDestination.Web.GetFolderByServerRelativeUrl(newList.ParentWebUrl.TrimEnd('/') + "/" + newList.Title.Replace(" ", "")).Files;

var fileInform = Microsoft.SharePoint.Client.File.OpenBinaryDirect(cOriginal, file.ServerRelativeUrl); // Get file content from SharePoint

var fi = new FileCreationInformation
      Url = newList.ParentWebUrl.TrimEnd('/') + "/" + newList.Title.Replace(" ", "") + "/" + file.Name, //cOriginal.Web.ServerRelativeUrl.TrimEnd('/') + "/" + newList.Title.Replace(" ", "") + "/" + file.Name,
      Content = ReadFully(fileInform.Stream), //System.IO.File.ReadAllBytes(File.OpenBinaryDirect(cOriginal, file.ServerRelativeUrl)), //System.IO.File.ReadAllBytes(cOriginal + "/" + file.ServerRelativeUrl),
      Overwrite = true

var fileUrl = string.Format("{0}/{1}", newList.RootFolder.ServerRelativeUrl, file.Name);

newItem = destFiles.Add(fi).ListItemAllFields; // Get back new file that has been created

Your Answer

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

Browse other questions tagged or ask your own question.