Saturday, January 31, 2009

The template you have selected is invalid or cannot be found


We were trying to create a site collection using a template uploaded in to Global template gallery using the stsadm command. But while creating the site collection we were getting the following error.

"The template you have selected is invalid or cannot be found"

After some investigation, again this is due to the Publishing feature. We deactivated the "Publishing feature" in the source site. Recreated the template. Uploaded it again using the Stsadm command. Now the site collection got created successfully.

Cannot find or parse web template file

I was trying to create a SharePoint site collection based on a template saved with lot of site level customizations. Site collection templates should be available in global template gallery and it can be added there using the Stsadm commands I tried to add the template in the global template gallery by using the following command

"stsadm -o addtemplate -filename "c:\mysitecollection" -title "Ari Site collection" "

But it was giving the following error

"Cannot find or parse web template file c:\mysitecollection."

It was a simple error to resolve. But was on a bad day and made me to sweat lot. Yes, the think i missed is the extension of the file name . I modified the command like below and it worked :( another bad day.

"stsadm -o addtemplate -filename "c:\mysitecollection.stp" -title "Ari Site collection" "

Cannot debug project with both ASP and unmanaged debugging enabled

"Cannot debug project with both ASP and unmanaged debugging enabled"

The above mentioned error was occurring when we tried to debug an old .net project in VisualStudio2003. Even though the error was pretty clear it was taking a while for us to find this settings under the property pages of the project. :(

The assembly does not allow partially trusted callers

I was creating a Custom page (code in separate code behind file) for sharepoint. I had to deploy both the .aspx file and .dll file. I deployed the .aspx file and the web.config in a separate folder under layouts folder. The .dll file was deployed to the bin folder of the web application. But while trying to see the page, it was showing the following error message.

"The assembly does not allow partially trusted callers"

After some investigation i found that the error will be happening when we try to call some trusted assemblies from not trusted or partially trusted assemblies.
I was able to resolve the problem by doing the following steps.

  1. Signing the assembly with "Mark assemblies with AllowPartiallyTrustedCallerAttribute(APTCA)" option checked in website project properties-->MSBuild Options
  2. Deployed the dll in to the GAC
  3. Added the assembly in the safe control list of the web.config of SharePoint site.

OpenXML a replacement for serverside automation

As per one of our project requirement we had to do lot of word automation. Since the project is based on SharePoint we had to do all these automation in the code behind of custom.aspx page. But later we found that there are some challenges while invoking the word instance in server using a logged in user. We were able to overcome this problem by impersonating a local user. However we found that server side automation is not supported by Microsoft because of the reasons mentioned in the article(http://support.microsoft.com/kb/257757).

They are suggesting the OpenXML approach for word automation. This seems to be a feasible approach compared to the server automation. To start with OpenXML we should understand the structure of it. We can do it easily by renaming a MSWord2007 .docx format file to .zip extension.

Steps

  1. Create a new MSWord2007 document with the name OpenXMLStructure.docx
  2. Rename the file to OpenXMLStructure.zip
  3. Open the archive file using archiving tool.
  4. It will show the entire structure of the MSWord2007 file in OpenXML format.
  5. To have better understanding about each XML file refer the following MSDN link.http://msdn.microsoft.com/en-us/library/aa338205.aspx
  6. Main part is the word.xml file containing the text of the document. we can read the documentXML in a XML DOM object and do all the automation. The following sites are having lot of information about various automation techniques http://msdn.microsoft.com/en-us/library/aa982683.aspx, http://openxmldeveloper.org/archive/category/1007.aspx

Saving a file only with extension

I was trying to create an OpenXML package manually. For that, a file named ".rel" (only with .rel extension) needs to be created. But if generally if we try to rename a file only with extension we will be getting the message "You must type a file name" and we can't rename the file.

There is a workaround to get rid of this problem. Instead of renaming the file, open the file in NotePad. Use the "Save as" option and type only the extension name in the File Name box. It will be saved only with the extension.