Created
February 14, 2013 21:36
-
-
Save yetanotherchris/4956622 to your computer and use it in GitHub Desktop.
Umbraco change templates on multiple documents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
using System.Web.Services; | |
using System.Collections; | |
using System.Web.Services.Protocols; | |
using umbraco.cms.businesslogic; | |
using umbraco.cms.businesslogic.web; | |
using umbraco.BusinessLogic; | |
using System.Xml.Serialization; | |
using umbraco.cms.businesslogic.property; | |
using umbraco.cms.businesslogic.macro; | |
[WebService(Namespace = "http://tempuri.org/")] | |
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] | |
public class YourWebservice : System.Web.Services.WebService | |
{ | |
[WebMethod] | |
public void UpdateDocumentParent(int docId, int parentId, bool deep, int templateId) | |
{ | |
if (deep) | |
{ | |
ArrayList list = this.GetDocumentChildren(docId); | |
for (int i = 0; i < list.Count; i++) | |
{ | |
if (list[i] is Document) | |
{ | |
int n; | |
int.TryParse(((Document)list[i]).Id.ToString(), out n); | |
if (n > 0) | |
{ | |
try | |
{ | |
Document d = new Document(n); | |
d.Publish(new User(0)); | |
} | |
catch { } | |
} | |
} | |
} | |
} | |
else | |
{ | |
Document d = new Document(docId); | |
d.Template = templateId; | |
d.Publish(new User(0)); | |
} | |
} | |
private ArrayList GetDocumentChildren(int docId) | |
{ | |
Document doc = new Document(docId); | |
Document[] children = doc.Children; | |
ArrayList list = new ArrayList(); | |
if (children.Length > 0) | |
{ | |
for (int i = 0; i < children.Length; i++) | |
{ | |
if (children[i].HasChildren) | |
{ | |
list.AddRange(GetDocumentChildren(children[i].Id)); | |
} | |
list.Add(children[i]); | |
} | |
} | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment