Microsoft are treating the new document generation facility in Dynamics 2016 as the best thing since sliced bread. There are some genuine limitations with it at the moment which I've seen posted elsewhere.
But I've come across an issue with custom entities. I managed to create a template alright but then tried to install it in another environment. I wasn't trying anything fancy, just a manual install of the template. But when I added the template it bound it to the wrong entity. Now it doesn't offer me the option to choose the entity, just goes ahead and binds it to the wrong thing.
It is to due to the object type code or sometimes called the entity type code. That code is fixed for all the standard entities, but custom entities are given a number in the 10,000 range. What I've discovered is this number is not the same across environments. It's not that I've been stupid and manually created the entity, I deployed a solution as you normally do, but it issues a different type code in the new environment. You can see it easily if you can access the full url for an entity record, you know when you want to find the unique guid. The etc parameter is the entity type code.
Now this wouldn't be a problem except when you create a Word document template it adds the entity type code to the end of the namespace. you can see it when in Word and you are in the Xml mapping pane. It's there at the end of the urn. That then causes it to bind to the wrong entity when deployed into the new environment.
If you spent hours creating the template you don't want to have to repeat this in each environment.
To solve it, take the template and rename the extension from docx to zip. You will see in the extract a customxml folder and in there a file that contains the urn of the source data. You have to change the etc at the end to match the correct one in the target environment. Change any other related custom entities. Zip it back up and rename it back to docx. Load it back into the target environment and it should work. Maybe I'll find the time to write an app to do this for me because I don't see Microsoft fixing this anytime soon. Damn, sometimes Microsoft just don't think things through.
Showing posts with label Template. Show all posts
Showing posts with label Template. Show all posts
Thursday, May 19, 2016
Tuesday, February 4, 2014
SharePoint 2013 - Word has encountered a problem trying to open the file
I experienced this error "Word has encountered a problem trying to open the file" when trying to open a Word template (dotx) from SharePoint 2013. I should explain that I was using Word 2010 and could open the template from its location in the file system, but when I uploaded it as a content type into SharePoint 2013 I received this error when trying to use the template.
Some blogs suggested the following
a) install Office 2010 32bit instead of Office 2010 64bit
b) upgrade to SP2
c) remove the SharePoint Foundation Services as a component of Office, and then do a repair.
I tried all of that and yet it still would not open the template. Then I found a blog that advised switching off Protected mode - go to File, Options, and Trust Centre Settings and disable all the Protected options which are enabled by default. That did the trick.
My advice - try switching Protected mode off first before trying anything else. Now I come to think of it I had seen this before and had forgotten about it. Hence the blog.
Some blogs suggested the following
a) install Office 2010 32bit instead of Office 2010 64bit
b) upgrade to SP2
c) remove the SharePoint Foundation Services as a component of Office, and then do a repair.
I tried all of that and yet it still would not open the template. Then I found a blog that advised switching off Protected mode - go to File, Options, and Trust Centre Settings and disable all the Protected options which are enabled by default. That did the trick.
My advice - try switching Protected mode off first before trying anything else. Now I come to think of it I had seen this before and had forgotten about it. Hence the blog.
Labels:
dotx,
Office,
SharePoint 2013,
Template,
Word 2010
Friday, January 24, 2014
Downloading a Document Template from SharePoint
Since I've wasted a couple of hours on this I'll share my findings. I'm creating a web service that will do a mail merge for me using Aspose Words. The document template is stored in a SharePoint document library as a content type and the merged document I want to store back into the document library.
I tackled the upload first. Since my web service and SharePoint will be installed on separate servers, I call the SharePoint Copy.asmx web service to upload the document. That works fine. My next task was to use the document template from SharePoint which I need to retrieve as a memory stream.
The preferred method is to use the GetItem method of the Copy.asmx service. No problem I thought as I already has a reference to it.
But try as I might I could not manage to download the template. When you install a content type as a template the path to the document is something like this
DocLib/Forms/Some Letter/SomeLetter.dotx
I suspect it was something to do with this location that it would not work. If I tried the same code on a document in the library itself it worked fine. I gave up in frustration and started Googling for alternatives.
I came up with this incredibly simple approach which I share below. It simply uses the DownloadData method of the WebClient. Since I know the absolute path of the template, it works a treat.
public MemoryStream DownloadSharePointDocument(string sourceUrl)
{
string sharePointSiteUrl = ConfigurationManager.AppSettings["sharepointsiteurl"];
if (!sharePointSiteUrl.EndsWith("/"))
{
sharePointSiteUrl = sharePointSiteUrl + "/";
}
sourceUrl = sharePointSiteUrl + sourceUrl;
WebClient wc = new WebClient();
wc.UseDefaultCredentials = true;
byte[] response = wc.DownloadData(sourceUrl);
MemoryStream ms = HelperMethods.MemoryStreamFromBytes(response);
return ms;
}
I tackled the upload first. Since my web service and SharePoint will be installed on separate servers, I call the SharePoint Copy.asmx web service to upload the document. That works fine. My next task was to use the document template from SharePoint which I need to retrieve as a memory stream.
The preferred method is to use the GetItem method of the Copy.asmx service. No problem I thought as I already has a reference to it.
But try as I might I could not manage to download the template. When you install a content type as a template the path to the document is something like this
DocLib/Forms/Some Letter/SomeLetter.dotx
I suspect it was something to do with this location that it would not work. If I tried the same code on a document in the library itself it worked fine. I gave up in frustration and started Googling for alternatives.
I came up with this incredibly simple approach which I share below. It simply uses the DownloadData method of the WebClient. Since I know the absolute path of the template, it works a treat.
public MemoryStream DownloadSharePointDocument(string sourceUrl)
{
string sharePointSiteUrl = ConfigurationManager.AppSettings["sharepointsiteurl"];
if (!sharePointSiteUrl.EndsWith("/"))
{
sharePointSiteUrl = sharePointSiteUrl + "/";
}
sourceUrl = sharePointSiteUrl + sourceUrl;
WebClient wc = new WebClient();
wc.UseDefaultCredentials = true;
byte[] response = wc.DownloadData(sourceUrl);
MemoryStream ms = HelperMethods.MemoryStreamFromBytes(response);
return ms;
}
Labels:
Aspose,
content type,
Download,
SharePoint,
Template
Subscribe to:
Posts (Atom)