1

In my project, I have to upload a new file to SharePoint library which base on specific existing item.

For example:

The original library have 2 items which has 10 custom columns:
itemA: c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
itemB: v1 v2 v3 v4 v5 v6 v7 v8 v9 v10

But now, I have to upload a new item (itemC) which its all columns value are clone from itemA (include build-in columns, Author,Editor, etc.).

Now:
itemA: c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
itemB: v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
itemC: c1 c2 c3 c4 c5 c6 c7 c8 c9 c10

I have tried to get all columns and its value, dataType via SPFieldCollection. However, there are too many columns (75) which I don't know which one should be kept.

var interalName = field.InternalName;
var TypeDisplayName  = field.TypeDisplayName;
var dataType:  field.Type;
var value = item[interalName];

Result: too many, I list 3 of those build-in column:

--------------------------------------
field name: MetaInfo
field TypeDisplayName : Lookup
field dataType: Lookup
field value: vti_thumbnailexists:BW|false
------------------------------------------
field name: DocIcon
field TypeDisplayName : Computed
field dataType: Computed
field value: png
-----------------------------------------
field name: _EditMenuTableStart2
field TypeDisplayName : Computed
field dataType: Computed
field value: 146
2

You need to copy only c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 columns. Other columns are internal columns to maintain some other metadata. Also Created By/ modified by cannot be copied from itemA, it will be updated based on the user uploading / updating the metadata.

  • Thank you for your answer, but i do need to keep the Created By/ modified .. value of the newest item as same as the specific item (itemA). I find that there are a System.Update(). Do you have any idea to do this? – king yau Nov 17 '16 at 7:16
  • If you are using server side code then you can keep the created by / modified by same as itemA but in case you are using CSOM code (jQuery/ javascript) to update the values then you cannot update Created by / modified by. – Monica Jagani Nov 17 '16 at 8:00
  • Sorry, two more questions, 1) how can i identify which column is custom column or build-in column? 2) how to handle some column which of type Look up? – king yau Nov 17 '16 at 8:42
  • Are you using server side code or client side scripting ? – Monica Jagani Nov 17 '16 at 8:43
  • 1
    You have two options: 1. Check if the field is a built-in field: SPBuiltInFieldId.Contains(field.Id) 2. Check on the SPField.SourceId (from MSDN): Gets either the namespace that defines a built-in field or, if it a custom field, the GUID that identifies the list or Web site where it was created. Reference from stackoverflow.com/questions/5340746/… – Monica Jagani Nov 17 '16 at 8:46

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.