1

I have a library, that have items and each item has additional File field.

I can upload them programmicaly - firsly file is uploaded, then empty item is updated with other info.

Example of filled item:

< z:row xmlns:z='#RowsetSchema' ows_ContentTypeId='0x010100A5914B6F2BB5492BBAF497E66640A8990050C4F6DFA243FB4080ABA9EF719BCA65' ows_FileLeafRef='8;#debug.log' ows_Modified_x0020_By='SHAREPOINT\system' ows_Created_x0020_By='SHAREPOINT\system' ows_File_x0020_Type='log' ows_Title='dghdfg' ows_PublicDocument_FullName='dghdfgh' ows_PublicDocument_Type='Официальное уведомление органа, проводящего расследование' ows_PublicDocument_Number='127055' ows_PublicDocument_Investigations='1;#1;#2;#2;#3;#3' ows_PublicDocument_Investigations_Nav='<a href="/ru/act/trade/podm/Inv1207/1">1</a>; <a href="/ru/act/trade/podm/Inv1207/2">2</a>; <a href="/ru/act/trade/podm/Inv1207/3">3</a>' ows_PublicDocument_Published='2016-02-19 00:00:00' ows_ID='8' ows_ContentType='Публичный документ' ows_Created='2016-02-19 14:48:15' ows_Author='1073741823;#Системная учетная запись' ows_Modified='2016-02-19 14:48:55' ows_Editor='1073741823;#Системная учетная запись' ows__ModerationStatus='0' ows_FileRef='8;#ru/act/trade/podm/Inv1207/PublicDocuments/debug.log' ows_FileDirRef='8;#ru/act/trade/podm/Inv1207/PublicDocuments' ows_Last_x0020_Modified='8;#2016-02-19 14:48:55' ows_Created_x0020_Date='8;#2016-02-19 14:48:16' ows_File_x0020_Size='8;#7381' ows_FSObjType='8;#0' ows_SortBehavior='8;#0' ows_PermMask='0x400001f07fff1bff' ows_CheckedOutUserId='8;#' ows_IsCheckedoutToLocal='8;#0' ows_UniqueId='8;#{07AEA512-E9CE-4CED-95E3-412B8F909F8A}' ows_ProgId='8;#' ows_ScopeId='8;#{79A0C68F-5687-43E3-95FF-3C74890D21FB}' ows_VirusStatus='8;#7381' ows_CheckedOutTitle='8;#' ows__CheckinComment='8;#' ows__EditMenuTableStart='debug.log' ows__EditMenuTableStart2='8' ows__EditMenuTableEnd='8' ows_LinkFilenameNoMenu='debug.log' ows_LinkFilename='debug.log' ows_LinkFilename2='debug.log' ows_DocIcon='log' ows_ServerUrl='/ru/act/trade/podm/Inv1207/PublicDocuments/debug.log' ows_EncodedAbsUrl='http://localhost/ru/act/trade/podm/Inv1207/PublicDocuments/debug.log' ows_BaseName='debug' ows_FileSizeDisplay='7381' ows_MetaInfo='8;#vti_parserversion:SR|14.0.0.7149 PublicDocument_Published:SW|2016-02-19T00:00:00Z vti_folderitemcount:IR|0 ContentTypeId:SW|0x010100A5914B6F2BB5492BBAF497E66640A8990050C4F6DFA243FB4080ABA9EF719BCA65 vti_title:SW|dghdfg vti_author:SR|SHAREPOINT\system PublicDocument_Investigations_Nav:SW|<a href='/ru/act/trade/podm/Inv1207/1'>1</a>; <a href='/ru/act/trade/podm/Inv1207/2'>2</a>; <a href='/ru/act/trade/podm/Inv1207/3'>3</a> PublicDocument_FullName:SW|dghdfgh PublicDocument_Number:SW|127055 PublicDocument_Type:SW|Официальное уведомление органа, проводящего расследование PublicDocument_Investigations:SW|1;#1;#2;#2;#3;#3 vti_modifiedby:SR|SHAREPOINT\system vti_foldersubfolderitemcount:IR|0 ' ows__Level='1' ows__IsCurrentVersion='1' ows_ItemChildCount='8;#0' ows_FolderChildCount='8;#0' ows_SelectTitle='8' ows_SelectFilename='8' ows_Edit='0' ows_owshiddenversion='2' ows__UIVersion='512' ows__UIVersionString='1.0' ows_Order='800.000000000000' ows_GUID='{B6216FC1-0FA4-4356-AA53-988A7CFBE65F}' ows_WorkflowVersion='1' ows_ParentVersionString='8;#' ows_ParentLeafName='8;#' Etag="{07AEA512-E9CE-4CED-95E3-412B8F909F8A},2" ows_Combine='0' ows_RepairDocument='0' ows_ServerRedirected='0' />

Now I want to upload it programmicaly. I do it like that:

var docs = web.Lists[publicDocumentsName];
var item = docs.AddItem();
item["PublicDocument_FullName"] = value.Name;
item["PublicDocument_Number"] = value.No;
item.File.SaveBinary(value.Data);

where Value.Data is byte[] - file body. But it doesn't work. Every example I found are about documents library where files are the items itselfs, but in my case it's just an attachment. But it's not a true attachment, becuase as I can see it's added as File property, when attachments are empty. item.Update();

0

This code adds a file and then fills all fields. Thanks to google and this site, I found several good ideas here and somewhere on the internet:

var docs = web.Lists[listName]; // get list
var file = docs.RootFolder.Files.Add(HttpUtility.UrlEncode(filePath), value.Data); // upload file
file.Item["PublicDocument_FullName"] = fileName; // modify custom fields
file.Item["PublicDocument_Number"] = value.No;
file.Item["PublicDocument_Type"] = value.Type;
file.Item["PublicDocument_Published"] = value.PublishedDateTime;
file.Item["PublicDocument_Investigations"] = GetInvestigationsLookup(value.Investigations);
file.Item.Update(); // update item
file.Update(); // update file

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.