Como criar uma pasta na biblioteca de documentos do SharePoint 2010 usando métodos de descanso ou http

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/50997

  •  09-12-2019
  •  | 
  •  

Pergunta

Eu estou usando o Java para fazer chamadas para a interface de descanso do SharePoint para obter itens de lista de uma biblioteca de documentos e métodos HTTP para carregar documentos para o SharePoint.Mas, estou tendo dificuldade em tentar descobrir como criar uma pasta programaticamente usando os métodos de descanso ou http.Sempre que tento fazer um post com um item de dados, recebo o seguinte erro

Cabeçalho de Slug inválido para blobs.Cabeçalhos SLUG devem ser URL do servidor ou da Web do arquivo.URLs relativos ao servidor começa com uma barra de avanço (\ "/ \").

Alguém pode ajudar.

Muito obrigado antecipadamente.

dinesh

Foi útil?

Solução

Get items

To get all items you can either call this url:

http://yourhost/_vti_bin/ListData.svc/YourLib

Or you can call this url:

http://yourhost/_vti_bin/Lists.asmx

with this payload:

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
    xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
  <soap:Body>
    <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
      <listName>YourLib</listName>
    </GetListItems>
  </soap:Body>
</soap:Envelope>

Create folder

I can't say if this is the correct approach, but it should work.
It uses Batch which I find a bit scary, but I have used this myself with success.
To create a folder you can call this url:

http://yourhost/sites/wf/_vti_bin/Lists.asmx

with this payload:

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
    xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
    xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
  <soap:Body>
    <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
      <listName>YourLib</listName>
      <updates>
        <Batch OnError='Continue' PreCalc='TRUE' ListVersion='0' >
          <Method ID='1' Cmd='New'>
            <Field Name='FSObjType'>1</Field>
            <Field Name='BaseName'>YourFolder</Field>
          </Method>
        </Batch>
      </updates>
    </UpdateListItems>
  </soap:Body>
</soap:Envelope>

Outras dicas

As Tommy pointed out and according to 3.1.4.3 Document:

Inserting new documents to a document library involve sending a POST request containing the contents of the document to the EntitySet representing the document library. The protocol client MUST include the SLUG header (as specified in RFC5023 section 9.7) whose value is the name of the file that is being created in their POST requests.

How to create Folder via REST in SharePoint 2010

function createFolder(webUrl,listName,folderName,folderPath, success, failure) {

    var folderPayload = {
      'ContentType': 'Folder',
      'Title' : folderName,
      'Path' : folderPath
    };

    $.ajax({
        url: webUrl + "/_vti_bin/listdata.svc/" + listName,
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(folderPayload),
        headers: {
            "Accept": "application/json;odata=verbose",
            "Slug": folderPath + "/" + folderName + "|0x0120" 
        },
        success: function (data) {
            success(data.d);
        },
        error: function (data) {
            failure(data.responseJSON.error);
        }
    });
}

Examples:

1 Create root folder named Orders in the Documents library

createFolder('https://intranet.contoso.com','Documents','Orders', '/Shared Documents',function(folder){
    console.log('Folder ' + folder.Name + ' has been created succesfully'); 
  },
  function(error){
    console.log(JSON.stringify(error));
  }
); 

2 Create sub folder named 2014 under the folder Orders in the Documents library

createFolder('https://intranet.contoso.com','Documents','2014', '/Shared Documents/Orders',function(folder){
    console.log('Folder ' + folder.Name + ' has been created succesfully'); 
  },
  function(error){
    console.log(JSON.stringify(error));
  }
); 

I don't have high enough reputation to comment, but I already gave the answer to this over here: Folder creation in Document library using listdata.svc

On creating folders in lists, its the same way, but without the "slug" header and you just add "/Lists" to beginning of the "Path" property.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top