private void ApplyMetadataRecordToListItem(SPDataRecord record, string urlTarget, ContentType ct) { var uploadedFile = _spList.RootFolder.Files.GetByUrl(urlTarget); var listItem = uploadedFile.ListItemAllFields; listItem["ContentTypeId"] = ct.Id.ToString(); foreach (var spfield in record) { try { if (spfield.SPDataType != "Taxonomy") { listItem[_spFieldList[spfield.SPColumnInternalName]] = spfield.SPValue; } else { try { listItem[_spTaxFields[spfield.SPColumnInternalName].InternalName] = GetTermIdForTaxonomyField(_spTaxFields[spfield.SPColumnInternalName], spfield.SPValue, listItem, uploadedFile); } catch { } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } CommitToSP(listItem, uploadedFile); }
public static SPDataRecord ToSPDataRecord(this DBFieldCollection fieldData, SPColumnMappings mapping, string keyValue) { var dataRecordOut = new SPDataRecord(keyValue); foreach (SPColumnMapping item in mapping) { var spfield = new SPDataField(); spfield.SPColumnInternalName = item.SharePointDestinationField; spfield.SPDataType = item.SharePointDataType; try { spfield.SPValue = fieldData[item.DBSourceField].ToString(); } catch { spfield.SPValue = string.Empty; } dataRecordOut.Add(spfield); } return dataRecordOut; }
public static SPDataRecord ToSPDataRecord(this DBFieldCollection fieldData, SPColumnMappings mapping, string keyValue) { var dataRecordOut = new SPDataRecord(keyValue); foreach (SPColumnMapping item in mapping) { var spfield = new SPDataField(); spfield.SPColumnInternalName = item.SharePointDestinationField; spfield.SPDataType = item.SharePointDataType; try { spfield.SPValue = fieldData[item.DBSourceField].ToString(); } catch { spfield.SPValue = string.Empty; } dataRecordOut.Add(spfield); } return(dataRecordOut); }
public void UploadFile(string sourceFolder, SPDataRecord record, string libraryTitle, string contentType, bool overwrite = false) { var ct = GetContentType(ctx, libraryTitle, contentType); if (_spFieldList == null) { LoadSPFieldList(libraryTitle, ct); } if (!SPFileExistInLibrary(libraryTitle, record.FileName)) { var urlTarget = PushFileToSP(sourceFolder, record.FileName, libraryTitle, overwrite); ApplyMetadataRecordToListItem(record, urlTarget, ct); } else { var urlTarget = string.Format("{0}/{1}", _spList.RootFolder.ServerRelativeUrl, record.FileName.Trim()); ApplyMetadataRecordToListItem(record, urlTarget, ct); } }
private void ApplyMetadataRecordToListItem(SPDataRecord record, string urlTarget, ContentType ct) { var uploadedFile = _spList.RootFolder.Files.GetByUrl(urlTarget); var listItem = uploadedFile.ListItemAllFields; listItem["ContentTypeId"] = ct.Id.ToString(); foreach (var spfield in record) { try { if (spfield.SPDataType != "Taxonomy") listItem[_spFieldList[spfield.SPColumnInternalName]] = spfield.SPValue; else { try { listItem[_spTaxFields[spfield.SPColumnInternalName].InternalName] = GetTermIdForTaxonomyField(_spTaxFields[spfield.SPColumnInternalName], spfield.SPValue, listItem, uploadedFile); } catch { } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } CommitToSP(listItem, uploadedFile); }
public void UploadFile(string sourceFolder, SPDataRecord record, string libraryTitle, string contentType, bool overwrite = false) { var ct = GetContentType(ctx, libraryTitle, contentType); if (_spFieldList == null) LoadSPFieldList(libraryTitle, ct); if (!SPFileExistInLibrary(libraryTitle, record.FileName)) { var urlTarget = PushFileToSP(sourceFolder, record.FileName, libraryTitle, overwrite); ApplyMetadataRecordToListItem(record, urlTarget, ct); } else { var urlTarget = string.Format("{0}/{1}", _spList.RootFolder.ServerRelativeUrl, record.FileName.Trim()); ApplyMetadataRecordToListItem(record, urlTarget, ct); } }