File downloaded but file is corrupted

i am put some code for file download. Its downloaded successfully but created file get corrupted no content is shown there. Please help me …my code is

client = new RestClient(“https://api.pipedrive.com/v1/files/” + id + “/download?api_token=” + token);
client.Timeout = -1;
client.FollowRedirects = true;
request = new RestRequest(Method.GET);
request.AlwaysMultipartFormData = true;
response = client.Execute(request);
if (response.StatusCode == HttpStatusCode.OK)
{

                                            objfiledetail.Filedata = Encoding.ASCII.GetBytes(response.Content);
                                            objfiledetail.FileType = response.ContentType;
                                        
                                            string pdefaultpath = Path.Combine(Directory.GetCurrentDirectory(), "File");
                                            string newPath = Path.Combine(pdefaultpath, objfiledetail.EamilId.ToString());
                                            if (!Directory.Exists(newPath))
                                            {
                                                Directory.CreateDirectory(newPath);
                                            }
                                            string filePath = Path.Combine(newPath, objfiledetail.FileName);
                                            File.WriteAllBytes(filePath, objfiledetail.Filedata);

                                        }

.png is okay but other file format not supported

Thanks in advance…

Hey Priti,

Just curious, but is the file also showing as corrupt when you try directly from the API page?
https://developers.pipedrive.com/docs/api/v1/#!/Files/get_files_id_download

Hi David,
Some files are corrupted. But some are not but still I am getting corrupted which I can see by using Pipedrive API interface .

Are you able to check out the files directly from UI? Maybe the files were already corrupted when uploaded?

Yes I am able to check that file from UI its showing…

Hi Priti,

Just to clarify, you’re able to download the same file directly from the Pipedrive UI and it’s not corrupted, but when this same file is downloaded via API then it is corrupt?

i’ll verify again it and update u