Search code examples
c#smartsheet-api

Download a row attachment using smart sheet API C#


I am referring below link

link

and used following lines -

     public void downloadAttachment(Attachment attach)
    { 
        SmartsheetRequest getAttachment = new SmartsheetRequest { callURL = "/attachment/" + attach.Id, method = "GET", contentType = "application/json" };
        var jsonGetAttachment = getAttachment.MakeRequest("null");
        getAttachment.DownloadAttachment(jsonGetAttachment["url"], jsonGetAttachment["sizeInKb"], jsonGetAttachment["name"]);
    }

to download an attachment.

But the following line

        Stream responseStream = request.GetResponse().GetResponseStream(); 

in "MakeRequest" method gives "The remote server returned an error: (404) Not Found." error.


Solution

  • I found a solution for my question.

    Solution:-

    The below line of code-

    SmartsheetRequest getAttachment = new SmartsheetRequest { callURL = "/attachment/" + attach.Id, method = "GET", contentType = "application/json" };
    

    was changed to below line-

    SmartsheetRequest getAttachment = new SmartsheetRequest { callURL = "/sheets/" + SheetID + "/attachments/" + attach.Id, method = "GET", contentType = "application/json"};