I'm searching high and low on the net on how to automate the relink process and there's only one I found to be the closest. I don't think there's a custom workflow that can be made within SharePoint.

I'm still a newbie to powershell so I don't know how to incorporate this to SharePoint. Pls help

Here's the one I found on the net: public override void ItemAdding(SPItemEventProperties properties) { base.EventFiringEnabled = false; RelinkFormTemplate(properties); base.ItemAdding(properties); }

public override void ItemUpdating(SPItemEventProperties properties) { base.EventFiringEnabled = false; RelinkFormTemplate(properties); base.ItemUpdating(properties); }

private string GetTemplateURL(SPContentTypeId contentTypeId, SPList spList, SPWeb spWeb, string strSolutionURL) { // this code is mostly modified from Microsoft.SharePoint.ApplicationPages.SubmitRepair, repackaged as an Event Receiver

SPContentType type = spList.ContentTypes[contentTypeId];
if (type == null)
    return strSolutionURL;
string documentTemplate = type.DocumentTemplate;
if (documentTemplate.StartsWith("http://", StringComparison.Ordinal) || 

documentTemplate.StartsWith("https://", StringComparison.Ordinal)) { return SPHttpUtility.UrlPathEncode(documentTemplate, true); } if (documentTemplate.StartsWith("/", StringComparison.Ordinal)) { return SPHttpUtility.UrlPathEncode(spWeb.Site.MakeFullUrl(documentTemplate), true); } return SPHttpUtility.UrlPathEncode(spWeb.Url + '/' + spList.RootFolder + '/' + documentTemplate, true); }

public void RelinkFormTemplate(SPItemEventProperties properties) { // this code is mostly modified from Microsoft.SharePoint.ApplicationPages.SubmitRepair, repackaged as an Event Receiver

SPList spList = properties.List;
object property = properties.AfterProperties["ContentTypeId"];
if (property == null)
    // publishing template from InfoPath?
string contentTypeId = property.ToString();

SPWeb spWeb = properties.Web;
SPDocumentLibrary spLibrary = (SPDocumentLibrary)spList;
string strSolutionURL = SPHttpUtility.UrlPathEncode(spWeb.Url + "/" + spLibrary.DocumentTemplateUrl, true);

string newTemplateUrl = this.GetTemplateURL(new SPContentTypeId(contentTypeId), spList, spWeb, strSolutionURL);
if ((properties.AfterProperties["TemplateUrl"] != null) && 

(!string.Equals(newTemplateUrl, properties.AfterProperties["TemplateUrl"].ToString(), StringComparison.CurrentCultureIgnoreCase))) { properties.AfterProperties["TemplateUrl"] = newTemplateUrl; } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.