CRM 2011 C# Plugin Create and download Word document to client RRS feed

  • Question

  • 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 not even sure if this is possible doing on this way, so any proposal how i can do this or why this dont work will be appreciate.

    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.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
    HttpContext.Current.Response.ContentType = "application/force-download";

    Thursday, June 18, 2015 7:15 AM

All replies

  • This approach won't work. The client is expecting the response from a web service call, and is not expecting a document. You can't force a document download when the client isn't expecting it.

    One alternative would be for the plugin to create the document, and to store it as an attachment (as a note) to the case, and allow the user the download the document from there 

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, June 18, 2015 9:10 AM
  • I supposed it won't work...I could create it as attachment to the case, but i need to find a way to download it to the client autautomatically with case create
    • Edited by Ganedr Thursday, June 18, 2015 1:09 PM
    Thursday, June 18, 2015 1:07 PM
  • The key point is you need something on the client that expects a file. You could try adding an html web resource to the case form to download the file (I'd probably still use the plugin to generate the file and save it as an attachment). The web resource would have to work immediately after the record is saved for the first time, so you'd probably need to use a flag field to control this

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, June 19, 2015 9:30 AM
  • Could I call that Html web resource throught a CRM plugin, and pass to web resource a location of file to download?? is it possible?
    Thursday, June 25, 2015 12:14 PM