How To Upload And Download Attachments Using Zoho CRM In ASP.NET MVC

Introduction

In this article, we will learn how to upload and download attachments using Zoho CRM in ASP.NET MVC Web application.

Let’s begin

Please read this article first of all here.

If you have not seen How to Create Lead using Zoho CRM then I recommend you to see that first. in that article, I described how to Create lead using Zoho CRM.

C# Code Example

Open the HomeController.cs file and add the below code in it.

Upload Attachments

public void UploadAttachmets()
  {
      ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
      BulkAPIResponse<ZCRMRecord> response1 = moduleIns.GetRecords();
      List<ZCRMRecord> relatedLists = response1.BulkData;
      ZCRMRecord recordIns = ZCRMRecord.GetInstance("Leads", relatedLists[0].EntityId);//module api name with record id
      APIResponse response = recordIns.UploadAttachment("Your File Path");
      ZCRMAttachment uploadAttachment = (ZCRMAttachment)response.Data;
  }

 

Get List Of Attachments

public void GetListOfAttachments()
 {
         ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
         BulkAPIResponse<ZCRMRecord> response1 = moduleIns.GetRecords();
         List<ZCRMRecord> relatedLists = response1.BulkData;
         ZCRMRecord recordIns = ZCRMRecord.GetInstance("Leads", relatedLists[0].EntityId); //module api name with record id
         BulkAPIResponse<ZCRMAttachment> response = recordIns.GetAttachments();
         List<ZCRMAttachment> attachments = response.BulkData; //attachments - list of ZCRMAttachment instance
 }

 

Download Attachments

public void DownloadAttachments()
 {
        ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
         BulkAPIResponse<ZCRMRecord> response1 = moduleIns.GetRecords();
         List<ZCRMRecord> relatedLists = response1.BulkData;

         ZCRMRecord recordIns = ZCRMRecord.GetInstance("Leads", relatedLists[0].EntityId); //module api name with record id
        
         FileAPIResponse response = recordIns.DownloadAttachment(your attachment id); //attachmentID

         Stream file = response.GetFileAsStream();
         CommonUtil.SaveStreamAsFile("Your File Save Path", file, response.GetFileName());
        
  }

 

if you have any questions or issues about this article, please let me know and more details here.

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories