【问题标题】:Open InfoPath xml from Sharepoint for xml processing从 Sharepoint 打开 InfoPath xml 以进行 xml 处理
【发布时间】:2016-09-28 00:14:55
【问题描述】:

我目前正在开发一个项目(WinForms、C#、VS2012),我需要从 SharePoint(我认为是 2010 年)文档库中加载 InfoPath-XML 文件,并对其中的特殊元素进行一些嗅探。

我不是在 SharePoint 服务器上开发,因为与 SharePoint 的连接只是程序实际执行的一小部分。我只是插入一些 SharePoint 列表来假装我正在查询数据库。 (我知道,SharePoint 列表不是正确的数据库意义上的数据库表,但这不是重点)列表包含对我的程序至关重要的数据,并且通过 Web 服务获取列表内容非常简单。

我没有使用 SharePoint 对象模型 (SharePoint*.dll),因为我没有这些对象模型并且无法正确引用它们,所以 Web 服务直到现在都可以正常工作。

查询列表后,我知道存储在文档库中的文件的文件名。当我组装此文件的 url 并将其粘贴到我选择的浏览器中时,SharePoint 在其 GUI 中显示该文件,因为它显示在 InfoPath 中(当我粘贴完全相同的 url 时)。

我有一份保存在本地的 xml 副本。这我可以轻松地打开和处理为 xml。但是,当我尝试直接从服务器打开文件时,我的 Stream(或 FileStream)包含 SharePoint 网站的 HTML 代码,显示我的 InfoPath 文档。这是我的打开代码:

string Path = @"awesome-correct-url";
WebRequest request = WebRequest.Create(Path);
request.UseDefaultCredentials = true; //SharePoint needs to know I am allowed to open the file
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream fs = response.GetResponseStream();
StreamReader sr = new StreamReader(fs);
string text = sr.ReadToEnd();
Console.WriteLine(text);

在查看写入控制台的内容时,我发现它是网站的 HTML 代码。

有没有办法说服 SharePoint 给我文件的内容,而不是给我很好的评论网站?

【问题讨论】:

    标签: c# sharepoint-2010 infopath


    【解决方案1】:

    好吧,事实证明我在发布问题后不久就偶然发现了解决方案。

    this 所示,可以使用另一个网络服务 - copy.asmx - 从共享点下载文件,这足以满足我的需要。 如果链接被破坏,这里是代码:

    string Path = @"awesome-valid-url";
    //CopyService is the reference to the webservice
    CopyService.Copy cs = new CopyService.Copy();
    cs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
    CopyService.FieldInformation myFieldInfo = new CopyService.FieldInformation();
    CopyService.FieldInformation[] myFieldInfoArray = { myFieldInfo };
    byte[] myByteArray;
    // Call the web service
    uint myGetUint = cs.GetItem(Path, out myFieldInfoArray, out myByteArray);
    
    // Convert into Base64 String
    string base64String;
    base64String = Convert.ToBase64String(myByteArray, 0, myByteArray.Length);
    
    // Convert to binary array
    byte[] binaryData = Convert.FromBase64String(base64String);
    
    // Create a temporary file to write the text of the form to
    string tempFileName = @"where-to-put-it.xml";
    
    // Write the file to temp folder
    FileStream fs = new FileStream(tempFileName, FileMode.CreateNew, FileAccess.ReadWrite);
    fs.Write(binaryData, 0, binaryData.Length);
    fs.Close();
    

    也许我什至可以解决实际保存文件的问题,反正我有我需要的所有字节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-24
      • 2020-05-11
      • 1970-01-01
      相关资源
      最近更新 更多