簡體   English   中英

使用JavaScript在Sharepoint中編寫xml文件

[英]Write an xml file in Sharepoint using JavaScript

我有一個在Visual Studio中創建的網站。 我已經在xml文件中存儲了一些結構信息,該信息是使用C#文件后面的代碼編寫的。 現在,我必須將整個項目遷移到SharePoint。 我是SharePoint的新手,我需要一種方法來編寫xml文件並將其存儲回服務器。 使用JavaScript可以做到嗎? 如果沒有,還有其他方法嗎?

編輯我忘了提我要修改現有的xml文件。

您可以通過以下方式進行操作:1)將功能添加到項目共享點項目中2)添加事件接收者,可以在feature.cs文件中創建XML文件

    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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM