Home > Net >  When creating a Google Sheet with C#, how do I select a folder location?
When creating a Google Sheet with C#, how do I select a folder location?

Time:12-18

I have the following code that creates a Google Sheet in my root drive folder:

    static void CreateSheet()
    {

        // Create a new sheet with a single tab
        string sheetName = "Test Create Sheet";
        var NewSheet = new Google.Apis.Sheets.v4.Data.Spreadsheet();
        NewSheet.Properties = new SpreadsheetProperties();
        NewSheet.Properties.Title = sheetName;
        
        var newSheet = service.Spreadsheets.Create(NewSheet).Execute();

        SpreadsheetId = newSheet.SpreadsheetId;
        Sheet = "Sheet1";

    }

I cannot seem to find syntax to update the location by folderid.

Is this even an option?

CodePudding user response:

Is this even an option? [Answer:] No

According to the official Google documentation for creating a spreadsheet using the Sheets API:

"There’s no option to create a spreadsheet directly within a specified Drive folder using the Sheets API. By default, the created spreadsheet is saved to the user’s root folder on Drive."

However, there are alternative options to saving a file to a Drive folder provided in the official documentation that will point you in the right direction.

  • Related