TableauServerUrls.Url_DatasourceDownload C# (CSharp) Method

Url_DatasourceDownload() public method

URL to download a datasource
public Url_DatasourceDownload ( TableauServerSignIn, session, SiteDatasource, contentInfo ) : string
session TableauServerSignIn,
contentInfo SiteDatasource,
return string
    public string Url_DatasourceDownload(TableauServerSignIn session, SiteDatasource contentInfo)
    {
        string workingText = _urlDownloadDatasourceTemplate;
        workingText = workingText.Replace("{{iwsSiteId}}", session.SiteId);
        workingText = workingText.Replace("{{iwsRepositoryId}}", contentInfo.Id);

        ValidateTemplateReplaceComplete(workingText);
        return workingText;
    }

Usage Example

        /// <summary>
        /// Execute the REST API call for a list of data sources
        /// </summary>
        public List <SiteDatasource> ExecuteRequest()
        {
            var statusLog         = OnlineSession.StatusLog;
            var downloadedContent = new List <SiteDatasource>();

            //Depending on the HTTP download file type we want different file extensions
            var typeMapper = new DownloadPayloadTypeHelper("tdsx", "tds");

            var datasources = _datasources;

            if (datasources == null)
            {
                statusLog.AddError("NULL datasources. Aborting download.");
                return(null);
            }

            //For each datasource, download it and save it to the local file system
            foreach (var dsInfo in datasources)
            {
                //Local path save the workbook
                string urlDownload = _onlineUrls.Url_DatasourceDownload(OnlineSession, dsInfo);
                statusLog.AddStatus("Starting Datasource download " + dsInfo.Name);
                try
                {
                    //Generate the directory name we want to download into
                    var pathToSaveTo = FileIOHelper.EnsureProjectBasedPath(
                        _localSavePath,
                        _downloadToProjectDirectories,
                        dsInfo,
                        this.StatusLog);

                    var fileDownloaded       = this.DownloadFile(urlDownload, pathToSaveTo, dsInfo.Name, typeMapper);
                    var fileDownloadedNoPath = System.IO.Path.GetFileName(fileDownloaded);
                    statusLog.AddStatus("Finished Datasource download " + fileDownloadedNoPath);

                    //Add to the list of our downloaded data sources
                    if (!string.IsNullOrEmpty(fileDownloaded))
                    {
                        downloadedContent.Add(dsInfo);
                    }
                    else
                    {
                        //We should never hit this code; just being defensive
                        statusLog.AddError("Download error, no local file path for downloaded content");
                    }
                }
                catch (Exception ex)
                {
                    statusLog.AddError("Error during Datasource download " + dsInfo.Name + "\r\n  " + urlDownload + "\r\n  " + ex.ToString());
                }
            } //foreach


            //Return the set of successfully downloaded content
            return(downloadedContent);
        }