2012-10-03 17 views
1

下面的代碼是嘗試從共享點獲取(下載)文件。 如果我在我的本地版本上嘗試這個,它就像一個魅力。我可以選擇文檔庫中的所有項目。SharePoint 365的行爲與本地版本不同

有幾種方法我嘗試過,如果你喜歡,我可以在這裏發佈一些。我可以下載損壞的文件,但即使鏈接錯誤。 如果我在Office 365中的TeamSite上嘗試此操作,我會遇到一個例外情況,即我的鏈接錯誤。但我指的是同一個站點(而不是localhost/dev/im,指的是http://mysite.com/TeamSite/dev/)。任何想法有什麼不同?微軟是否阻止了某些東西,因此不允許外部連接?

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. 
+0

Microsoft不支持此操作。我們公司也試圖得到類似於這個解決方案的東西。我們不得不中止這個項目,因爲當前版本的Office365不支持這個問題。 –

回答

2

您無法連接到SharePoint站點,部署這樣的另一臺計算機上。 您應該使用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()); 
    } 

,你可以找到更多的例子在客戶端上下文here

有媒體鏈接從SharePoint通過clientContext文件下載的example

+0

好吧,現在就試試這個,它看起來類似於我已經嘗試過的幾個「解決方案」,而且我什麼都沒有結束。提前致謝。去檢查一下。 – Rob

+0

這是可能的答案。 C#SharePoint API只能聯繫本地服務器,而不能使用遠程服務器。 –

相關問題