【问题标题】:SharePoint 365 acting different than local versionSharePoint 365 与本地版本不同
【发布时间】:2012-10-03 12:11:05
【问题描述】:

下面的代码尝试从共享点获取(下载)文件。 如果我在我的本地版本上尝试这个,它就像一个魅力。我可以选择文档库中的所有项目。

我尝试了几种方法,如果您愿意,我可以在这里发布其中的一些方法。我可以下载损坏的文件,但即使链接错误。 如果我在 Office 365 中的 TeamSite 上尝试此操作,则会收到链接错误的异常。但我指的是同一个站点(而不是 localhost/dev/im 指的是http://mysite.com/TeamSite/dev/)。知道有什么区别吗? Microsoft 是否阻止了某些东西,因此不允许外部连接?

  private void btnDownload_Click(object sender, EventArgs e)
    {
        if (comboBox1.Items.Count > 0 && comboBox1.SelectedIndex != -1)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.ShowDialog();

            using (SPSite site = new SPSite("http://localhost/dev/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPFolder myLibrary = web.Folders["Management"];

                    foreach (SPFile file in myLibrary.Files)
                    {
                        if (file.Name == comboBox1.SelectedItem.ToString())
                        {
                            byte[] bytes = file.OpenBinary();

                            try
                            {
                                FileStream fs = new FileStream(dialog.FileName, FileMode.Create, FileAccess.ReadWrite);
                                BinaryWriter bw = new BinaryWriter(fs);
                                bw.Write(bytes);
                                bw.Close();
                                MessageBox.Show("File downloaded to: " + dialog.FileName);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }

                        }                            
                    }
                }
            }
        }
        else
        {
            MessageBox.Show("Select file to download");
        }
    }

这是异常消息:

The Web application at http://www.gtest.nl/TeamSite/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

【问题讨论】:

  • 微软不支持这个。我们公司也试图获得与此解决方案类似的东西。我们不得不终止该项目,因为当前版本的 Office365 不支持此问题。

标签: c# office365


【解决方案1】:

您无法连接到共享点站点,像这样部署在另一台计算机上。 你应该使用Client Context

例如:

    string siteUrl = "http://MyServer/sites/MySiteCollection";

    ClientContext clientContext = new ClientContext(siteUrl);
    Web oWebsite = clientContext.Web;
    ListCollection collList = oWebsite.Lists;

    clientContext.Load(collList);

    clientContext.ExecuteQuery();

    foreach (SP.List oList in collList)
    {
        Console.WriteLine("Title: {0} Created: {1}", oList.Title, oList.Created.ToString());
    }

您可以在 Client Context here 上找到更多示例

已经有一个example 通过clientContext 从sharepoint 下载文件。

【讨论】:

  • OK 现在试试这个,它看起来类似于我已经尝试过的几个“解决方案”,但我最终什么也没做。提前致谢。去看看吧。
  • 这是可能的答案。 C# SharePoint API 只能联系本地服务器,而不能联系远程服务器。
猜你喜欢
  • 2020-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-12
  • 2020-07-16
  • 2022-01-21
  • 2011-10-19
  • 2013-04-01
相关资源
最近更新 更多