public static String SaveXamlToFile(this String xaml, Guid id, OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileConnectorBase connector, ListCollection lists) { // Tokenize XAML to replace any ListId attribute with the corresponding token XElement xamlDocument = XElement.Parse(xaml); var elements = (IEnumerable)xamlDocument.XPathEvaluate("//child::*[@ListId]"); if (elements != null) { foreach (var element in elements.Cast <XElement>()) { var listId = element.Attribute("ListId").Value; element.SetAttributeValue("ListId", TokenizeListIdProperty(listId, lists)); } xaml = xamlDocument.ToString(); } using (Stream mem = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(mem, Encoding.Unicode, 2048, true)) { sw.Write(xaml); } mem.Position = 0; String xamlFileName = String.Format("{0}.xaml", id.ToString()); connector.SaveFileStream(xamlFileName, mem); return(xamlFileName); } }
public static String SaveXamlToFile(this String xaml, Guid id, OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileConnectorBase connector) { using (Stream mem = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(mem, Encoding.Unicode, 2048, true)) { sw.Write(xaml); } mem.Position = 0; String xamlFileName = String.Format("{0}.xaml", id.ToString()); connector.SaveFileStream(xamlFileName, mem); return(xamlFileName); } }
public static String SaveXamlToFile(this String xaml, Guid id, OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileConnectorBase connector, ListCollection lists) { // Tokenize XAML to replace any ListId or ToListId attribute with the corresponding token XElement xamlDocument = XElement.Parse(xaml); string[] listIdAttributes = { "ListId", "ToListId" }; var elements = (IEnumerable)xamlDocument.XPathEvaluate($"//child::*[@{listIdAttributes[0]}|@{listIdAttributes[1]}]"); if (elements != null) // always true, consider removing { foreach (var element in elements.Cast <XElement>()) { foreach (var listIdAttribute in listIdAttributes) { if (element.Attribute(listIdAttribute) != null) { var listId = element.Attribute(listIdAttribute).Value; element.SetAttributeValue(listIdAttribute, TokenizeListIdProperty(listId, lists)); } } } xaml = xamlDocument.ToString(); } using (Stream mem = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(mem, Encoding.Unicode, 2048, true)) { sw.Write(xaml); } mem.Position = 0; String xamlFileName = $"{id.ToString()}.xaml"; connector.SaveFileStream(xamlFileName, mem); return(xamlFileName); } }