I created some mail merge template. It should create some email and sent to some contact. Template is using 'contact' entity.
How to create document from code using that template?
And, for example, send mail to specified contact.
MailMerge in CRM is a bit of a funny one. You upload a Word template (using a wizard) to create the MailMergeTemplate entity, during this process CRM will then inject a little macro into the document.
Downloading the document merged with data, actually just pushes the data into an HTML table that is placed as a comment in the word document, when you open the document (and go through the Word Mail-merge wizard again) the data is moved by the macro from the comment into the form fields.
So if you wan't to complete your mailmerge, you need both the template (stored as an xml blob in CRM), at this point I chose to insert the data manually (so I can't help you getting the sdk to inject the HTML table) by manually creating my own html table of data in a separate file (you need the entity data stored against display name and the calling user entity also against display name but prefixed with User_), you can then simply use the Word SDK to start and finish the mail merge in an automated way.
FYI the technique I used isn't supported by microsoft because Word churns out too many error messages to be automated so I got around this by installing a ClickOnce app on clients that did the merge so there would always be a user present. If you wan't to merge on a server, prepare to wage battle with DCOM also.
I've come across this a few times. When you say document, do you mean a Word attachment?
If so, this isn't a CRM thing, its a Word thing.
Similar Stackoverflow questions are a good place to start.
To get it working is complicated. Once you have populated your Word document, you have to get it back into CRM. It's messy...
Related
I have a template for a loan document that I have saved in the directory of my asp.net MVC website. When the user clicks a clients name, I would like the website to edit the xml document using the clients information, then download the file as a word document. Any suggestions on how to do this?
I am using Docentric Toolkit, which is a OpenXML based tool so no Word installation is necessary on the server. The tool comes with a MS Word Add-in, with which you can prepare templates with placeholders for data.
In your MVC application you then have to:
Prepare data model classes (e.g. with Entity Framework).
Create method which will read the data and fill the data model collection(s) as needed.
Call the method to generate Word document from the chosen template which is filled with data from data collection from step 2.
You can take a look at this CodeProject example, to see detailed steps and download a demo project.
I hope this helps.
hey i'm working on project in which I have webform which includes some editfields. I don't want to enter the data manually into that editfield. what I want is to extract data from a word document and fill that editfields. But the catch is, through which MS doc I fill the editfield?
Suppose We have a bunch of lectures uploaded on some page. so what should I do to retrieve the data from a particular document?
Is it necessary to open the MS-doc file first?
or I should download the file first?
If I goes with option 1 when should I have to use some library? what opens the file within browser, retrieve the data and the a pop-up message appears "the data has been retrieved now you can close the file". and next I can fill the form with that data.
or should I goes with the 2 Option when an individual hit the download button then the file will be stored into the local machine. how can I keep the track that which ms-file is downloaded or stored into the local machine?and is it necessary to open that file for retrieving the data again?
These are my point of views that how I can implement that module. So I need your suggestions? Is this the right way to achieve this goal or should I follow the other path? and which libraries are required to achieve this task or any tutorial similar to this problem ?
Thanks in Advance
I would suggest considering a third option: since the Word document files exist on the server, the cleanest place to pre-populate a form would be by extracting data from the document while it is on the server and filling in the form's fields before sending it down to the user in a codebehind. Trying to extract data on the client side from a recently-downloaded file via an application other than the browser seems ripe for kludgy-ness. Articles such as http://support.microsoft.com/kb/257757 should help get you started in the right direction.
For extracting data from ms word document using free .net word component and fill data to webform,
extract data,
Document doc = new Document();
doc.LoadFromFile("YouDocOrDocx.Docx");
string content = doc.GetText();
There're a data list with hundreds of data items (suppose each item is a customer), and a predefined word document as template, the requirement is - for each data item, fill corresponding data into template fields, and generate a readonly PDF file as result.
Prefered platform is ASP.NET with C#.
I found two solutions:
Change the word document into a PDF form, and use iTextSharp to fill the form fields. But create the PDF form with correct format (font, layout, etc.) is a difficult work, and it needs particular tool and new skill when system user wants to add new template (unless the PDF form is always created by developer).
Add text placeholder in the word file, and the program can read word file, replace text, and convert into PDF. But I'm not sure which components should be used.
I'd like to get some advices on this problem. tks.
Update 20130416:
After some searching & experiments, my conclusion is below:
Client solution: use Microsoft.Office.Interop.Word (Office2007+plugin or Office2012) to read data, convert to pdf, etc. But this method running on server side may be unsafe.
Server solution:
Make PDF form, and use iTextSharp to fill the form fields. The disadvantage has been mentioned above.
Make HTML template, and replace field placeholders, and use iTextSharp+XMLWorker to convert HTML to PDF. The difficulty is create the HTML template manually and optimize the PDF effect.
MS SharePoint Office Automation Service is a server solution based on MS Office, perhaps this method will be easier, but it needs license and SharePoint server cost.
Finally, I chose the HTML template solution for this request. QED.
Another option would be to use Tx Text Control for ASP.NET. They have a
mailmerge feature that allows you to fill data into a word template.
The merged document can easily be saved as a pdf.
For the second option you can use iTextsharp or Aspose which supports the placeholder replacement and generation PDF, it supports creating files based on templates of MSWord and Openoffice which could be usefull for user who do not want to buy MSWord only to create a template.
Another option, you can use nustache templates, fill them with list data and then use xmlworker from ItextSharp to render to pdf.
what I need to achieve is to have a word document template(docx), which will contain Title, Author name, Date, etc.
This template then will be used by users to complete it. I need to create a c# program, that will take in the docx file and read all the information of interest(title, name, date, ..).
So my questions are:
How do I put the metadata into the template saying: this is Title, this is Date, this is Name, etc? (not programatically)
How do I programmatically read that information?
One way to approach this would be to use Content Controls. In Office, you can create your template, and then for each of your respective inputs of interest you can place one of these controls. They're under the Developer tab in Office.
After inserting your controls you'll need for each of them to have a unique name. Office will let them all have the same name, but you'll need to uniquely identify all of them in your template document.
You now need to get the data that's input in to these controls. Again, there's likely to be some better solutions but Eric White has all kinds of great OpenXML stuff, and so here's one of his: Iterating over Content Controls
I think there's problems with finding content controls nested within a table. So, if you do that, then I think you have to specifically loop over the elements of the table to find content controls within.
Also, you're probably going to want to save a .docx from your .doct file, which I don't think there's any built-in "one-liner" method in OpenXML; however, you can create a new Word document, and then write the file stream of the template in to the newly created docx file. Again, of course, there may be better solutions out there.
Have you been here? There's lots of good stuff:
Introduction to OpenXML
Additionally, Eric has been releasing more and more videos on the OpenXML YouTube channel
1) how do I put the metadata into the template saying: this is Title,
this is Date, this is Name, etc? (not programatically)
You could do that on Info tab in MS Word 2010 as shown below:
2) how do I programmatically read that information?
Once you created your document (or template) you could always look inside it with Open XML SDK 2.0 Productivity Tool (wich is installed with OpenXML SDK) to see where (what classes to use) to get/set some information from/to document.
Also I think this post might help you to solve your task:
Add and update custom document properties in a docx
UPDATE:
Hi Dave,
Please have a look at this MSDN Article - Retrieving Application Properties from Word 2010 Documents by Using the Open XML SDK 2.0
Hope this is exactly what you are looking for.
All OpenXML documents have built in core Metadata that will do what you need through System.IO.Packaging. Once you open the word file using the open xml sdk in c#, you can get to these values via the PackageProperties class. There are 11 Properties you can use.
You "encourage" your user to enter the metadata using Word's Document Information Panel (DIP).
You can force this on by default when they open your template, by a setting in the Developer Toolbar for the template. See the following article on how to set this in your template.
I wrote a quick Windows Form app that displays this information using open xml sdk call to the PackageProperties of the Word file that is displayed above.
Here is the full solution with the sample word file included.
Hope this helps.
Are there any existing solutions to create documents in Silverlight? Looking to create purchase orders, contracts, etc.
Printing is a desired feature.
Consider sourcing from your customer, the template of those purchase orders, contracts, etc. Keep those documents on the server, and save their names/filepaths in the database.
Determine which fields need to be filled by the user, and create form elements (textbox, radio, image upload) for each of those document fields.
When the user has finished entering their data, save the data to a DB, and then programmatically insert their data into the document. You could manipulate a Word document/ text file, and then perhaps use a PDF generator to save in the user's 'inbox' on the server.
This likely is very business specific, so you'll have a lot of customization. Sounds like you were looking for an existing open source solution. Would be interesting to see if your solution ended up as a blogpost or open-source project at CodePlex or SourceForge. It really could be handy for others down the road!