C# 创建文件后访问该文件

C# 创建文件后访问该文件,c#,sharepoint,sharepoint-2007,moss,C#,Sharepoint,Sharepoint 2007,Moss,我有以下代码在内存中创建一个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 li

我有以下代码在内存中创建一个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”对象,以便更改其属性(如“创建人”)?

您可以使用以下代码获取
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:你考虑过在上发帖吗?

查看文件信息类谢谢你的回复。我从您代码的第5行中得到以下信息:“无法在此作用域中声明名为'newFileInLibrary'的局部变量,因为它将赋予'newFileInLibrary'不同的含义,后者已在'parent or current'作用域中用于表示其他内容。”。我曾考虑将此发布到SharePoint网站,但我认为这更多的是一个语言问题,而不是SharePoint特有的问题。您是否注意到我删除了
using
块中
newFileInLibrary
变量之前的类型?事实上,我将变量的作用域设置为外部作用域(您的方法),但我在using块内部分配了它。