简体   繁体   中英

Create Folder and Update Title and Custom Field in Sharepoint Online

I try to create folder in sharepoint online, based on some of tutorial. the problem comes since creating folder is not given "Title" column value.

I want to create folder and also update column "Title".

here is the code for create folder

public string CreateDocumentLibrary(string siteUrl, string relativePath)
    {
        //bool responseResult = false;
        string resultUpdate = string.Empty;
        string responseResult = string.Empty;
        if (siteUrl != _siteUrl)
        {
            _siteUrl = siteUrl;
            Uri spSite = new Uri(siteUrl);

            _spo = SpoAuthUtility.Create(spSite, _username, WebUtility.HtmlEncode(_password), false);
        }

        string odataQuery = "_api/web/folders";

        byte[] content = ASCIIEncoding.ASCII.GetBytes(@"{ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '" + relativePath + "'}");

        string digest = _spo.GetRequestDigest();

        Uri url = new Uri(String.Format("{0}/{1}", _spo.SiteUrl, odataQuery));
        // Set X-RequestDigest
        var webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
        webRequest.Headers.Add("X-RequestDigest", digest);

        // Send a json odata request to SPO rest services to fetch all list items for the list.
        byte[] result = HttpHelper.SendODataJsonRequest(
          url,
          "POST", // reading data from SP through the rest api usually uses the GET verb 
          content,
          webRequest,
          _spo // pass in the helper object that allows us to make authenticated calls to SPO rest services
          );

        string response = Encoding.UTF8.GetString(result, 0, result.Length);

        if (response != null)
        {
            //responseResult = true;
            responseResult = response;
        }
        return responseResult;
    }

I already tried to use CAML, but, the problem is, the list of sharepoint is big, so got the error prohibited access related to limit tresshold.

Please help.

Refer below code to update folder name.

function renameFolder(webUrl,listTitle,itemId,name)
{
     var itemUrl =  webUrl + "/_api/Web/Lists/GetByTitle('" + listTitle + "')/Items(" + itemId + ")";
     var itemPayload = {};
     itemPayload['__metadata'] = {'type': getItemTypeForListName(listTitle)};
     itemPayload['Title'] = name;
     itemPayload['FileLeafRef'] = name;
     var additionalHeaders = {};
     additionalHeaders["X-HTTP-Method"] = "MERGE";
     additionalHeaders["If-Match"] =  "*";
     return executeJson(itemUrl,"POST",additionalHeaders,itemPayload);
}


function getItemTypeForListName(name) {
   return"SP.Data." + name.charAt(0).toUpperCase() + name.slice(1) + "ListItem";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM