Dynamic CRM Plugin download Word document

965 views Asked by At

I have created CRM plugin, which on Case create need to download a document to the client. When I create a case plugin is working but it doesnt download a document. In console i can see a content of document is returned through POST request ..AppWebServices/InlineEditWebService.asmx but not opened or downloaded.

Im new in this so I will be a very thankful on any help. My code is bellow:

My code is bellow:

protected void ExecutePreValidateCaseCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
   throw new ArgumentNullException("localContext");
}
String FileName = "Test.docx";
String FilePath = @"C:\Template\temp\Test.docx"; 

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
HttpContext.Current.Response.ContentType = "application/force-download";
HttpContext.Current.Response.TransmitFile(FilePath);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
} 
1

There are 1 answers

4
Henk van Boeijen On

Tweaking the HttpResponse in a plugin is not supported and should be avoided by all means. In other words, you cannot do this using a plugin.

When you need to offer a download option in Dynamics CRM for (Word) documents, a solution could be to create a separate web site containing a download page. Then you can integrate this page into CRM by means of an IFrame or HTML web resource.