/// <summary> /// Writes the XML file. /// </summary> /// <typeparam name="type">The type of the object to serialize.</typeparam> /// <param name="library">The <see cref="SPDocumentLibrary"/> that is a placeholder of the file.</param> /// <param name="itemId">The item unique identifier.</param> /// <param name="content">The object to serialize.</param> public static void WriteXmlFile <type>(SPDocumentLibrary library, int itemId, type content) where type : IStylesheetNameProvider { SPFile _file = library.GetItemByIdSelectedFields(itemId).File; File.WriteXmlFile <type>(_file, content, content.StylesheetNmane); }
/// <summary> /// Writes the XML file to the an existing file that is represented by the item from a document library<paramref name="listName"/>. /// </summary> /// <typeparam name="type">The type of the object to serialize.</typeparam> /// <param name="web">The web.</param> /// <param name="fileId">The file identifier.</param> /// <param name="listName">Name of the list.</param> /// <param name="content">The object to serialize.</param> /// <param name="stylesheetName">Name of the XML style sheet.</param> public static void WriteXmlFile <type>(SPWeb web, int fileId, string listName, type content, string stylesheetName) { SPDocumentLibrary _lib = (SPDocumentLibrary)web.Lists[listName]; SPFile _file = _lib.GetItemByIdSelectedFields(fileId).File; File.WriteXmlFile <type>(_file, content, stylesheetName); }
private void CreateBinCard(object sender, EventArgs e) { try { using (Entities _entities = new Entities(workflowProperties.WebUrl)) { CustomsWarehouse _cw = Element.GetAtIndex <CustomsWarehouse>(_entities.CustomsWarehouse, workflowProperties.ItemId); BinCardContentType _newBinCard = Factory.CreateContent(_cw); if (_cw.CWL_CW2BinCardTitle == null) { string _documentName = Settings.BinCardDocumentName(_entities, workflowProperties.ItemId); SPFile _newFile = File.CreateXmlFile <BinCardContentType>(workflowProperties.Web, _newBinCard, _documentName, BinCardLib.LibraryName, BinCardContentType.StylesheetNmane); BinCardLib _BinCardLibRntry = Element.GetAtIndex <BinCardLib>(_entities.BinCardLibrary, _newFile.Item.ID); _BinCardLibRntry.Archival = false; _cw.CWL_CW2BinCardTitle = _BinCardLibRntry; _entities.SubmitChanges(); } else { int _binCardId = _cw.CWL_CW2BinCardTitle.Id.Value; SPDocumentLibrary _lib = (SPDocumentLibrary)workflowProperties.Web.Lists[BinCardLib.LibraryName]; SPFile _file = _lib.GetItemByIdSelectedFields(_binCardId).File; File.WriteXmlFile <BinCardContentType>(_file, _newBinCard, BinCardContentType.StylesheetNmane); } } logToHistoryListActivity_HistoryOutcome = "Success"; logToHistoryListActivity_HistoryDescription = "Document created successfully"; } catch (CAS.SharePoint.ApplicationError _ap) { logToHistoryListActivity_HistoryOutcome = "ApplicationError"; logToHistoryListActivity_HistoryDescription = _ap.Message; } catch (Exception _ex) { logToHistoryListActivity_HistoryOutcome = "Exeption"; logToHistoryListActivity_HistoryDescription = _ex.Message; } }