我有一个在 Visual Studio 中创建的网站。我已经将一些结构信息存储在我使用 C# 文件后面的代码编写的 xml 文件中。现在我必须将整个项目迁移到 SharePoint。我是 SharePoint 的新手,我需要一种方法来编写 xml 文件并将其存储回服务器。可以用 JavaScript 做到吗?如果没有,还有其他方法吗?
编辑我忘了提到我想修改现有的 xml 文件。
我有一个在 Visual Studio 中创建的网站。我已经将一些结构信息存储在我使用 C# 文件后面的代码编写的 xml 文件中。现在我必须将整个项目迁移到 SharePoint。我是 SharePoint 的新手,我需要一种方法来编写 xml 文件并将其存储回服务器。可以用 JavaScript 做到吗?如果没有,还有其他方法吗?
编辑我忘了提到我想修改现有的 xml 文件。
You can do this way 1)Add a Feature to your project sharepoint project 2)Add an event reciever, in the feature.cs file u can create XML file
public class Feature1EventReceiver : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
// Get the Context
SPSite Site = (SPSite)properties.Feature.Parent;
//Get the Web Address
SPWeb Web = Site.OpenWeb();
//Create a Path to Microsoft Shared/14
//string serverPath = SPUtility.GetGenericSetupPath(string.Empty);
string serverPath = "C:\\inetpub\\wwwroot\\wss\\VirtualDirectories\\38118\\config";
// Changes yhe folder permission to the grant access to all chat users
FolderACL(serverPath);
//Create the Congig file
CreateConfigFile(serverPath);
}
/// <summary>
/// Changes yhe folder permission to the grant access to all chat users
/// </summary>
/// <param name="path"></param>
public static void FolderACL(String path)
{
DirectorySecurity Psec = Directory.GetAccessControl(path);
SecurityIdentifier Peveryone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
Psec.AddAccessRule(new FileSystemAccessRule(Peveryone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(path, Psec);
}
/// <summary>
/// Method which Created the Config file
/// </summary>
/// <param name="path"></param>
public static void CreateConfigFile(String path)
{
//Use an xml Writer
using (XmlWriter writer = XmlWriter.Create(path + "/Config.xml"))
{
//Start the Xml Document
writer.WriteStartDocument();
//Create Root element
writer.WriteStartElement("Root");
//Write Element in the root element
writer.WriteElementString("element", "abcd");
writer.WriteElementString("element", "efgh");
//End the root element
writer.WriteEndElement();
//End the Xml Document
writer.WriteEndDocument();
}
}
是的,那么你可以使用 Xdocument
XmlDocument doc = new XmlDocument();
doc.Load("source path");
// Make changes to the document.
XmlTextWriter xtw = new XmlTextWriter("destination path", Encoding.UTF8);