我有以下代码在内存中创建XML文件,更新它然后将其添加到表单库。
// Creates a new XML document in memory
XmlDocument newCRF = new XmlDocument();
// Loads an existing XML file into that in-memory document
newXMLdoc.Load("Template.xml");
// Write the XML file to a document library
using (SPSite newSite = new SPSite("http://sharepoint/newsite"))
{
using (SPWeb newWeb = newSite.OpenWeb())
{
SPList newLibrary = newWeb.Lists["Test Library"];
byte[] xmlData = System.Text.Encoding.UTF8.GetBytes(newXMLdoc.OuterXml);
// Save file to form library
using (MemoryStream ms = new MemoryStream(xmlData))
{
SPFile newFileInLibrary = newLibrary.RootFolder.Files.Add("Filename.xml", ms);
}
}
}
如何访问'newFileInLibrary'对象以便我可以更改它的属性(例如“Created By”)?
答案 0 :(得分:0)
您可以使用以下代码获取SPListItem
对象:
// Save file to form library
SPFile newFileInLibrary = null;
using (MemoryStream ms = new MemoryStream(xmlData))
{
newFileInLibrary = newLibrary.RootFolder.Files.Add("Filename.xml", ms);
}
SPListItem fileItem = newFileInLibrary.Item;
DoSomethingWith(fileItem["Created"]);
Ps:您考虑过http://sharepoint.stackexchange.com吗?