/// <summary> /// <para>Get a sheet as a file.</para> /// /// <para>It mirrors To the following Smartsheet REST API method:<br /> /// GET /sheets/{sheetId} with "application/pdf", "application/vnd.ms-excel", or "text/csv" as Accept HTTP header</para> /// </summary> /// <param name="sheetId"> the Id of the sheet </param> /// <param name="paperSize"> the size of the PDF file </param> /// <param name="outputStream"> the output stream To which the CSV file will be written. </param> /// <param name="contentType"> the Accept header </param> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> private void GetSheetAsFile(long sheetId, PaperSize? paperSize, BinaryWriter outputStream, string contentType) { Utils.ThrowIfNull(outputStream, contentType); StringBuilder path = new StringBuilder("sheets/" + sheetId); if (paperSize.HasValue) { path.Append("?paperSize=" + paperSize.Value); } HttpRequest request = null; request = CreateHttpRequest(new Uri(this.Smartsheet.BaseURI, path.ToString()), HttpMethod.GET); request.Headers["Accept"] = contentType; Api.Internal.Http.HttpResponse response = Smartsheet.HttpClient.Request(request); switch (response.StatusCode) { case HttpStatusCode.OK: try { response.Entity.GetBinaryContent().BaseStream.CopyTo(outputStream.BaseStream); } catch (IOException e) { throw new SmartsheetException(e); } break; default: HandleError(response); break; } Smartsheet.HttpClient.ReleaseConnection(); }
/// <summary> /// <para>Get a sheet as a PDF file.</para> /// /// <para>It mirrors To the following Smartsheet REST API method:<br /> /// GET /sheets/{sheetId} with "application/pdf" Accept HTTP header</para> /// </summary> /// <param name="sheetId">the Id of the sheet</param> /// <param name="outputStream">the output stream To which the PDF file will be written.</param> /// <param name="paperSize">the paper size</param> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual void GetSheetAsPDF(long sheetId, BinaryWriter outputStream, PaperSize? paperSize) { GetSheetAsFile(sheetId, paperSize, outputStream, "application/pdf"); }