SharePointCommunity
Die deutschsprachige Community für SharePoint, Microsoft 365, Teams, Yammer und mit Azure

SPFx - Alle Seitenkollektionen

bewertet von 0 Usern
Beantwortet Dieser Beitrag hat 1 Geprüfte Antwort | 2 Antworten | 1 Follower

Top-200-Beitragsschreiber
65 Beiträge
Ladislav erstellt in 6 Jan 2021 12:17

Sehr geehrte Damen und Herren,

wie kann ich durch SharePoint Framework alle Seitenkollektionen erhalten, für welche der angemeldete Benutzer Rechte hat?

Es soll im Office 365 auch im SharePoint on Premise funktionieren.

Ich danke Ihnen für Ihre Hilfe.

Mit freundlichen Grüssen

Ladislav

Beantwortet Geprüfte Antwort

Top-200-Beitragsschreiber
65 Beiträge

Folgende Methode ist besser, weil die Position von dem Titel und Path in der Array Cells kann sich ändern, wenn die Variable restApiUrl noch weitere die Parameter hätte:

 

public GetAllSiteCollections5(context: WebPartContext): Promise<ISiteCollection[]> {
        
        let restApiUrl: string = context.pageContext.web.absoluteUrl + "/_api/search/query?querytext='contentclass:sts_site'";
        
        let siteCollections: ISiteCollection[] = [];

        let config: SPHttpClientConfiguration = new SPHttpClientConfiguration({
            defaultODataVersion: ODataVersion.v3
        });

        return new Promise<ISiteCollection[]>(async(resolve, reject) => {

            context.spHttpClient
            .get(restApiUrl, config, {headers: { Accept: "application/json;odata=minimalmetadata;charset=utf-8"}})
            .then((response: SPHttpClientResponse) => {

                console.log("response contains: " + JSON.stringify(response));

                response.json().then((results: any) => {

                    console.log(restApiUrl);
                    console.log("results contains: " + JSON.stringify(results));
                    
                    let resultsList = results.PrimaryQueryResult.RelevantResults.Table.Rows;
                    
                    console.log(resultsList);
                    
                    resultsList.map((result: any) => {                        

                        let cells = result.Cells;
                        console.log("cells: " + JSON.stringify(cells));

                        let title: string = "";
                        let path: string = "";

                        cells.map((cell: any) => {

                            console.log("cell: " + JSON.stringify(cell));

                            let key = cell.Key;

                            if (key == "Title"{

                                title = cell.Value;
                            } else if (key == "Path"{

                                path = cell.Value;
                            }                         
                        });

                        siteCollections.push({
                            Title: title,
                            SPSiteUrl: path,
                        });
                    });

                    console.log(siteCollections);
                    resolve(siteCollections);
                });
            }, (error: any): void => {

                reject("error occured " + error);
            });
        })
    }

Alle Antworten

Top-200-Beitragsschreiber
65 Beiträge

Folgende Methode funktioniert richtig:

public GetAllSiteCollections5(context: WebPartContext): Promise<ISiteCollection[]> {
        
        let restApiUrl: string = context.pageContext.web.absoluteUrl + "/_api/search/query?querytext='contentclass:sts_site'";

        let siteCollections: ISiteCollection[] = [];

        let config: SPHttpClientConfiguration = new SPHttpClientConfiguration({
            defaultODataVersion: ODataVersion.v3
        });

        return new Promise<ISiteCollection[]>(async(resolve, reject) => {

            context.spHttpClient
            .get(restApiUrl, config, {headers: { Accept: "application/json;odata=minimalmetadata;charset=utf-8"}})
            .then((response: SPHttpClientResponse) => {

                console.log("response contains: " + JSON.stringify(response));

                response.json().then((results: any) => {

                    console.log(restApiUrl);
                    console.log("results contains: " + JSON.stringify(results));
                    
                    let resultsList = results.PrimaryQueryResult.RelevantResults.Table.Rows;
                    
                    console.log(resultsList);
                    
                    resultsList.map((result: any) => {

                        console.log(result);

                        let cell3 = result.Cells[3];
                        console.log("cell3: " + JSON.stringify(cell3));

                        let cell6 = result.Cells[6];
                        console.log("cell6: " + JSON.stringify(cell6));

                        let cell3Value = cell3.Value;
                        console.log(cell3Value);

                        let cell6Value = cell6.Value;
                        console.log(cell6Value);

                        siteCollections.push({
                            Title: cell3Value,
                            SPSiteUrl: cell6Value,
                        });
                    });

                    console.log(siteCollections);
                    resolve(siteCollections);
                });
            }, (error: any): void => {

                reject("error occured " + error);
            });
        })
    }

 

Top-200-Beitragsschreiber
65 Beiträge

Folgende Methode ist besser, weil die Position von dem Titel und Path in der Array Cells kann sich ändern, wenn die Variable restApiUrl noch weitere die Parameter hätte:

 

public GetAllSiteCollections5(context: WebPartContext): Promise<ISiteCollection[]> {
        
        let restApiUrl: string = context.pageContext.web.absoluteUrl + "/_api/search/query?querytext='contentclass:sts_site'";
        
        let siteCollections: ISiteCollection[] = [];

        let config: SPHttpClientConfiguration = new SPHttpClientConfiguration({
            defaultODataVersion: ODataVersion.v3
        });

        return new Promise<ISiteCollection[]>(async(resolve, reject) => {

            context.spHttpClient
            .get(restApiUrl, config, {headers: { Accept: "application/json;odata=minimalmetadata;charset=utf-8"}})
            .then((response: SPHttpClientResponse) => {

                console.log("response contains: " + JSON.stringify(response));

                response.json().then((results: any) => {

                    console.log(restApiUrl);
                    console.log("results contains: " + JSON.stringify(results));
                    
                    let resultsList = results.PrimaryQueryResult.RelevantResults.Table.Rows;
                    
                    console.log(resultsList);
                    
                    resultsList.map((result: any) => {                        

                        let cells = result.Cells;
                        console.log("cells: " + JSON.stringify(cells));

                        let title: string = "";
                        let path: string = "";

                        cells.map((cell: any) => {

                            console.log("cell: " + JSON.stringify(cell));

                            let key = cell.Key;

                            if (key == "Title"{

                                title = cell.Value;
                            } else if (key == "Path"{

                                path = cell.Value;
                            }                         
                        });

                        siteCollections.push({
                            Title: title,
                            SPSiteUrl: path,
                        });
                    });

                    console.log(siteCollections);
                    resolve(siteCollections);
                });
            }, (error: any): void => {

                reject("error occured " + error);
            });
        })
    }
Seite 1 von 1 (3 Elemente) | RSS