Smartsheet.Api.Internal.AttachmentVersioningResourcesImpl.AttachFile C# (CSharp) Method

AttachFile() private method

Attach file.
the file not found exception the Smartsheet exception
private AttachFile ( string path, string file, string contentType ) : Attachment
path string the url path
file string the file
contentType string the content Type
return Smartsheet.Api.Models.Attachment
        private Attachment AttachFile(string path, string file, string contentType)
        {
            Utility.Utility.ThrowIfNull(file);
            if (contentType == null)
            {
                contentType = "application/octet-stream";
            }
            FileInfo fi = new FileInfo(file);
            HttpRequest request = CreateHttpRequest(new Uri(this.Smartsheet.BaseURI, path), HttpMethod.POST);

            request.Headers["Content-Disposition"] = "attachment; filename=\"" + fi.Name + "\"";

            HttpEntity entity = new HttpEntity();
            entity.ContentType = contentType;

            entity.Content = File.ReadAllBytes(file);
            entity.ContentLength = fi.Length;
            request.Entity = entity;

            HttpResponse response = this.Smartsheet.HttpClient.Request(request);

            Attachment attachment = null;
            switch (response.StatusCode)
            {
                case HttpStatusCode.OK:
                    attachment = this.Smartsheet.JsonSerializer.deserializeResult<Attachment>(
                        response.Entity.GetContent()).Result;
                    break;
                default:
                    HandleError(response);
                    break;
            }

            this.Smartsheet.HttpClient.ReleaseConnection();

            return attachment;
        }