How to download attachment using an url "sys_attachment.do?sys_id"

jitesh_zende1
Tera Contributor

Hi,

I want to download attachment using url "sys_attachment.do?sys_id" directly instead of usinf rest API.

I have developed the C# Rest Service and inside this service I am calling the service now url directly to download the attachment.

My C# code is as below,

                      var client = new WebClient();

                      string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + password));

                      client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

                      client.DownloadFile(new Uri("https://myinstance.service-now.com/sys_attachment.do?sys_id=1234567890"), "E://new_CIP.txt");

It downloads the file as a html code and not the expected one. I want to download large file in one go, I don't want use REST API.  

Could you please help me on the same?          

Thanks,

Jitesh Zende

6 REPLIES 6

Hi Jitesh,

 

Are you done with this requirement. If yes, then pls share the code.

 

 

Thanks,

Nikita

Debarpita Basak
Giga Contributor

HI Jitesh, 

please share the code