SharePoint: come creare una cartella in una raccolta documenti utilizzando i servizi Web

StackOverflow https://stackoverflow.com/questions/1630824

  •  06-07-2019
  •  | 
  •  

Domanda

Devo creare una semplice cartella in una raccolta documenti in SharePoint, ma non riesco a trovare una documentazione sull'argomento.

Il servizio web dws sembra essere usato per creare cartelle fisiche in uno spazio di lavoro, ho bisogno di un modo per creare una cartella in una raccolta documenti.

Non sei sicuro di cosa fare, ti preghiamo di aiutare

È stato utile?

Soluzione

Ho trovato questo metodo funzionante:

    HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create("http://mySite/MyList/MyfolderIwantedtocreate");
    request.Credentials = CredentialCache.DefaultCredentials;
    request.Method = "MKCOL";
    HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    response.Close();

Altri suggerimenti

Questo è il codice per richieste simili in JAVA usando apache HttpClient

import org.apache.http.*;

private static HttpResponse makeFolder(
            String url,
            DefaultHttpClient httpClient) throws Exception {
    BasicHttpRequest httpPost = new BasicHttpRequest("MKCOL", url);
    HttpUriRequest httpUriRequest = new RequestWrapper(httpPost);

    HttpResponse status = httpClient.execute(httpUriRequest);
    EntityUtils.consume(status.getEntity());
    return status;
}

Codice per creare httpClient e chiamare la funzione makeFolder

DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(
        AuthScope.ANY,
        new NTCredentials(config.getUserName(), config.getPasswords(),
                        "", config.getDomain()));

So che questa è una domanda piuttosto vecchia, ma nel caso in cui qualcun altro la trovi, ecco come l'ho fatta:

       String CAML =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<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>" +
        "<CreateFolder " + "xmlns=\"http://schemas.microsoft.com/sharepoint/soap/dws/\">"+
            "<url>" + ParentFolder+'/'+NewFolderName+ "</url>"+
        "</CreateFolder>"+
        "</soap:Body>" +
        "</soap:Envelope>";

       String uri = "http://[your site]/_vti_bin/dws.asmx";

       WebClient client = new WebClient();
        client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/dws/CreateFolder";
        client.Headers["content-type"] = "text/xml; charset=utf-8";
        client.Encoding = Encoding.UTF8;
        client.UploadStringCompleted += UploadStringCompleted;
        try
        {
            client.UploadStringAsync(new Uri(uri, UriKind.Absolute), "POST", CAML);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error in upload string async: " + ex.Message);
        }

Stavo usando Silverlight, motivo per cui ho usato la stringa di caricamento asincrona, ma questo può essere fatto in altri modi con lo stesso metodo di post http

Ho lavorato un po 'con i servizi Web ma non riesco a trovare alcun codice che crei una cartella. Tuttavia, ho codice che copia i file da una condivisione di rete in una cartella esistente in una raccolta documenti di SharePoint utilizzando percorsi UNC. Usa System.IO.File - forse potresti usare quella tecnica per creare una cartella?

Create cartelle in sharepoint utilizzando Web dell'area di lavoro del documento Servizio (Dws) . Funziona alla grande.

public static bool CreateSPFolder(string FolderDir, string FolderName, yourCredentialsClass credentials)
{
    FolderName = ReplaceInvalidChars(FolderName);

    // create an instance of the sharepoint service reference
    Dws.Dws dwsWebService = new Dws.Dws();
    dwsWebService.Url = credentials.SharePointUrl + "/_vti_bin/Dws.asmx";
    dwsWebService.Credentials = new NetworkCredential(credentials.UserId, credentials.Password);

    string result = dwsWebService.CreateFolder(string.Format("{0}/{1}",FolderDir,FolderName));
    dwsWebService.Dispose();

    if (result == null)
    {
        throw new Exception("No response creating SharePoint folder");
    }

    if (result.Equals("<Result/>"))
    {
        return true;
    }

    return false;
}

public static string ReplaceInvalidChars(string strIn)
{
    return Regex.Replace(strIn.Replace('"', '-'), @"[.~#%&*{}:<>?|/]", "-");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top