c# - SharePoint - Reference file in item properties -


(disclaimer: first time deal sharepoint)

i trying add file in sharepoint , reference in property of list item. property type 'sparqube lookup classic' (i had no idea quick search led me this: http://www.sparqube.com/sharepoint-lookup-column/).

what ever try seem fail. have searched on-line, no relevant results came (wrong search terms probably?).

here half-functioning code. item has no file attached in (_x03a8__x03b7__x03c6__x03b9__x03) property when code finishes.

    public void publishdoctosp()     {         var clientcontext = getclient();         sp.client.file file;         var foldername = "doclib";          // upload file - works ok.         {             var filename = @"c:\users\user\desktop\file.pdf";             var folder = clientcontext.web.folders.getbyurl(clientcontext.url + '/' + foldername);              var info = new filecreationinformation             {                 contentstream = new filestream(filename, filemode.open, fileaccess.read, fileshare.read),                 overwrite = false,                 url = clientcontext.url + '/' + foldername + '/' + path.getfilename(filename),             };             file = folder.files.add(info);             folder.update();             clientcontext.executequery();         }          // add item in list , reference file in property. not working!         {             var list = clientcontext.web.lists.getbyid(guid.parse("{6f15aacd-1132-4bd8-ac7d-36ea1a336d5c}"));              var itemcreateinfo = new listitemcreationinformation()                                      {                                          //folderurl                                          //leafname                                          //underlyingobjecttype                                      };             var li = list.additem(itemcreateinfo);             li["docmanid"] = 111;             li["title"] = "adfadfadfaf";             li["email_x0020__x039a__x03b1__x03c4"] = "trehagireue@mailcom"; // email             li["_x0391__x0394__x0391_"] = "ΑΗ-ΓΑ...";             li["_x0391__x03c1__x03b9__x03b8__x03"] = "dfgdfg-sdf";             li["_x03a8__x03b7__x03c6__x03b9__x03"] = new sp.spfieldurlvalue(clientcontext.url + '/' + foldername + '/' + "file.pdf"){description = "test desc"};             li.update();             list.update();             clientcontext.executequery();             var insertedid = li.id;         }     } 

any idea missing?

update:

retrieving existing list item , looking @ field data this:

var lv0 = item["_x03a8__x03b7__x03c6__x03b9__x03"] microsoft.sharepoint.client.fieldlookupvalue[]; {microsoft.sharepoint.client.fieldlookupvalue[1]}     [0]: {microsoft.sharepoint.client.fieldlookupvalue} lv0[0] {microsoft.sharepoint.client.fieldlookupvalue}     base {microsoft.sharepoint.client.clientvalueobject}: {microsoft.sharepoint.client.fieldlookupvalue}     lookupid: 532     lookupvalue: "σσσ"     typeid: "{f1d34cc0-9b50-4a78-be78-d5facfcccfb7}" 

now, guess have find how data. lookupid seems file id. wonder how client. saw no such property being returned back.

update2:

finally, have managed uploaded file id that: https://stackoverflow.com/a/22254339/2173353. when send of in field, either error or nothing linked files:

using sp = microsoft.sharepoint;  string.format("{0};#{1}", fileid, file.name); string.format("{0};#{1:b}", fileid, listid); //listid guid new microsoft.sharepoint.client.fieldlookupvalue[] { new microsoft.sharepoint.client.fieldlookupvalue { lookupid = fileid } }; new sp.spfieldlookupvaluecollection { new sp.spfieldlookupvalue(fileid, file.name) }; 

i have tried no array, simple fieldlookupvalue. didn't work either. :(

ok. seems sparqube lookup classic uses file title , cannot work files have no title. so, first have set title , works:

    public static void publishdoctosp()     {         var clientcontext = getclient();         sp.client.file file;         var foldername = "doclib";          // upload file         {             var filename = @"c:\users\user\desktop\file.pdf";             var folder = clientcontext.web.folders.getbyurl(clientcontext.url + '/' + foldername);              var info = new filecreationinformation             {                 contentstream = new filestream(filename, filemode.open, fileaccess.read, fileshare.read),                 overwrite = false,                 url = clientcontext.url + '/' + foldername + '/' + path.getfilename(filename),             };             file = folder.files.add(info);              // !!! set value title field, because in case, title column display column of sparqube lookup classic             listitem itemfile = file.listitemallfields;             itemfile["title"] = path.getfilename(filename);             itemfile.update();             clientcontext.load(itemfile);              clientcontext.executequery();         }          // add item in list , reference file in property. not working!         {             var list = clientcontext.web.lists.getbyid(guid.parse("{f682c057-9715-4f1c-be1e-d451803ff389}"));             var itemcreateinfo = new listitemcreationinformation()             {                 //folderurl                 //leafname                 //underlyingobjecttype             };             var li = list.additem(itemcreateinfo);             li["title"] = "adfadfadfaf";              // set value lookup classic single value selection             li["sqlookupclassic"] = new sp.client.fieldlookupvalue()             {                 lookupid = file.listitemallfields.id             };             // !!! or             // li["sqlookupclassic"] = string.format( "{0};#{1}", file.listitemallfields.id, file.listitemallfields["title"] );              // !!! if 'allow multiple values' option selected lookup classic, should set value in following way:             //li["sqlookupclassic"] = string.format( "{0};#{1};#{2};#{3}", item1.id, item1["title"], item2.id, item2["title"] );              li.update();             clientcontext.executequery();             var insertedid = li.id;         }     } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -