Domanda

Posso caricare un file su sharepoint con il client web come segue

using (System.Net.WebClient webclient = new System.Net.WebClient())
{
    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(
                    Encryptor.Decrypt(ConfigurationManager.AppSettings["username"]),
                    Encryptor.Decrypt(ConfigurationManager.AppSettings["password"]),
                    ConfigurationManager.AppSettings["domain"]);
    webclient.Credentials = credentials;

    string path = Path.Combine("http://sharepoint.domain.com/dir", filename);
    webclient.UploadData(path, "PUT", fileBytes);
}

Ma non so come creare directory se non esistono.

Qualche idea su come posso farlo?

Grazie, -c

È stato utile?

Soluzione

Il termine " Directories " in un sito di SharePoint è ingannevole. La struttura "directory" di un servizio Web di SharePoint è una struttura virtuale che si trova nei database di SharePoint. È necessario identificare quale oggetto nel modello a oggetti di SharePoint la 'directory' è ad esempio: http: //sharepoint.domain .com / dir è probabilmente un sito SPS, con nel sito puoi avere una 'directory' che sono SPFolder, SPList, SPDocumentLibraries ecc.

Quindi se con " crea directory che non esistono " intendi nella struttura della directory del sito di SharePoint, non sarai in grado di fare con WebClient. Sono disponibili due opzioni: il modello a oggetti di Windows SharePoint Services e SharePoint Webservices.

Il modello a oggetti è certamente più facile da usare a mio avviso, ma richiederà di eseguire l'app sullo stesso server del server SharePoint. I servizi Web sono un po 'più impegnativi ma ti consentono di usarli da remoto.

Dovrai identificare il tipo di oggetto che stai tentando di aggiungere (ad es. SPFolder, SPSite, SPList, SPDocumentLibrary ect.).

Esiste un'ampia documentazione per l'utilizzo del modello a oggetti situato Qui ma se si desidera utilizzare i servizi Web è necessario accedervi nei seguenti percorsi:

Administration Service       http://<server-url:port-number>/_vti_adm/admin.asmx
Alerts Service               http://<server-url>/_vti_bin/alerts.asmx
Document Workspace Service   http://<server-url>/_vti_bin/dws.asmx
Forms Service                 http://<server-url>/_vti_bin/forms.asmx
Imaging Service             http://<server-url>/_vti_bin/imaging.asmx
List Data Retrieval Service http://<server-url>/_vti_bin/dspsts.asmx
Lists Service                 http://<server-url>/_vti_bin/lists.asmx
Meetings Service               http://<server-url>/_vti_bin/meetings.asmx
Permissions Service         http://<server-url>/_vti_bin/permissions.asmx
Site Data Service             http://<server-url>/_vti_bin/sitedata.asmx
Site Service                   http://<server-url>/_vti_bin/sites.asmx
Users and Groups Service       http://<server-url>/_vti_bin/usergroup.asmx
Versions Service               http://<server-url>/_vti_bin/versions.asmx
Views Service                 http://<server-url>/_vti_bin/views.asmx
Web Part Pages Service       http://<server-url>/_vti_bin/webpartpages.asmx
Webs Service                   http://<server-url>/_vti_bin/webs.asmx

Suggerisco di esaminare gli elenchi o i servizi di Document Workspace Service.

Spero che sia d'aiuto.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top