<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      VSTO學習筆記(四)從SharePoint 2010中下載文件

      上一次我們開發了一個簡單的64位COM加載項,雖然功能很簡單,但是包括了開發一個64位COM加載項的大部分過程。本次我們來給COM加載項添加一些功能:從SharePoint 2010的文檔庫中下載一個Excel文檔到本地。

      示例代碼下載

      本系列所有示例代碼均在 Visual Studio 2010 Ultimate RC + Office 2010 Professional Plus Beta x64 上測試通過。

       

      1、首先創建一個Shared AddIn項目(具體細節請參閱上一篇文章):

       

      2、添加引用:

      Microsoft.SharePoint

      System.Windows.Forms

      System.Drawing

      System.DirectoryServices

       

      3、在Connect類中創建Application和COMAddIn的實例:

       

      代碼
          /// <summary>
          
      ///   The object for implementing an Add-in.
          
      /// </summary>
          
      /// <seealso class='IDTExtensibility2' />
          [GuidAttribute("6D3788F4-9529-429E-BA5D-09695F85687A"), ProgId("SimpleExcelServicesDemo.Connect")]
          
      public class Connect : Object, Extensibility.IDTExtensibility2
          {
              
      private Microsoft.Office.Interop.Excel.Application app;
              
      private Microsoft.Office.Core.COMAddIn addIn;

       

       

      3、在OnConnection事件里初始化:

       

      代碼
              public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
              {
                  
      this.app = application as Microsoft.Office.Interop.Excel.Application;
                  
      this.addIn = addInInst as Microsoft.Office.Core.COMAddIn;
              }

       

       

      4、在OnStartupComplete事件中設置一個按鈕,關聯事件處理邏輯: 

      代碼
              public void OnStartupComplete(ref System.Array custom)
              {
                  CommandBars commandBars;
                  CommandBar standardBar下載數據;
                  CommandBarButton simpleButton下載數據;
                  commandBars 
      = this.app.CommandBars;

                  
      // Get the standard CommandBar from Word
                  standardBar下載數據 = commandBars["Standard"];

                  
      try
                  {
                      
      // try to reuse the button is hasn't already been deleted
                      simpleButton下載數據 = (CommandBarButton)standardBar下載數據.Controls["下載數據"];
                  }
                  
      catch (System.Exception)
                  {
                      
      // If it's not there add a new button
                      simpleButton下載數據 = (CommandBarButton)standardBar下載數據.Controls.Add(1);
                      simpleButton下載數據.Caption 
      = "下載數據";
                      simpleButton下載數據.Style 
      = MsoButtonStyle.msoButtonCaption;
                  }

                  
      // Make sure the button is visible
                  simpleButton下載數據.Visible = true;
                  simpleButton下載數據.Click 
      += new _CommandBarButtonEvents_ClickEventHandler(btnDownload_Click);

                  standardBar下載數據 
      = null;
                  commandBars 
      = null;
              }

       


             

      5、做一個域用戶驗證,當用戶輸入了合法的與用戶名和密碼后,才允許下載。這里添加了一個WindowsForm到項目中:

       

      6、域用戶驗證邏輯,我本機是一臺域控制器BROOKS.COM,使用的靜態IP: 192.168.1.100,【LDAP://192.168.1.100/DC=BROOKS,DC=com】是LDAP的路徑語法:

      代碼
              private bool fn數據驗證()
              {
                  
      if (this.txt用戶名.Text.Trim() == string.Empty)
                  {
                      MessageBox.Show(
      "用戶名不能為空!");
                      
      this.txt用戶名.Focus();
                      
      return true;
                  }

                  
      if (this.txt密碼.Text.Trim() == string.Empty)
                  {
                      MessageBox.Show(
      "密碼不能為空!");
                      
      this.txt密碼.Focus();
                      
      return true;
                  }

                  
      if (this.fn域用戶驗證(@"LDAP://192.168.1.100/DC=BROOKS,DC=com"this.txt用戶名.Text.Trim(), this.txt密碼.Text.Trim()))
                  {
                      MessageBox.Show(
      "您輸入的用戶名或密碼錯誤,請重新輸入!");
                      
      this.txt密碼.Clear();
                      
      this.txt密碼.Focus();
                      
      return true;
                  }
                  
      return false;
              }

              
      private bool fn域用戶驗證(string path, string username, string pwd)
              {
                  
      try
                  {
                      DirectoryEntry entry 
      = new DirectoryEntry(path, username, pwd);
                      DirectorySearcher search 
      = new DirectorySearcher(entry);
                      search.Filter 
      = "(SAMAccountName=" + username + ")";
                      SearchResult result 
      = search.FindOne();

                      
      if (null == result)
                      {
                          
      return true;
                      }
                      
      else
                      {
                          
      return false;
                      }
                  }
                  
      catch
                  {
                      
      return true;
                  }
              }

       

       

      7、使用Windows Server 2008 R2的AD管理器創建一個域用戶:test

       

       

      8、在Connect中編寫下載文件邏輯:

       SharePoint 2010 網站是:http://brookspc/sites/doc,我們要下載的就是其Document庫中的Excel Services Test.xlsx

      代碼
              private void fn下載文件()
              {
                  
      //保存文件            
                  using (SPSite site = new SPSite("http://brookspc/sites/doc"))
                  {
                      SPWeb web 
      = site.OpenWeb();
                      
      string __fileName = "http://brookspc/sites/doc/Documents/Excel Services Test.xlsx";
                      SPFile file 
      = web.GetFile(__fileName);
                      
      string __localFilePath = @"C:\ExcelServices.xlsx";
                      
      //將文件下載到本地
                      byte[] content = file.OpenBinary();
                      
      if (File.Exists(__localFilePath))
                      {
                          File.Delete(__localFilePath);
                      }
                      FileStream fs 
      = new FileStream(__localFilePath, FileMode.Create);
                      fs.Write(content, 
      0, content.Length);
                      fs.Flush();
                      fs.Close();
                  }
              }

       

       

       9、按鈕事件處理邏輯:

      代碼
              public void btnDownload_Click(CommandBarButton sender, ref bool cancelDefault)
              {
                  FrmLogin login 
      = new FrmLogin();
                  
      if (login.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                  {
                      
      this.fn下載文件();
                  }
              }

       

       

      10、編譯一下,安裝生成的setup.exe:

       

      11、打開Excel,點擊【下載數據】:

       

      12、輸入域用戶名、密碼后,點擊【登錄】,即把SharePoint中的文件下載到了本地,默認在C盤:

       

       

      小結:

      本次只是添加了一些功能,和SharePoint 2010進行了交互,下載了一個文檔,其中用到了域用戶的驗證。后續篇章會繼續將VSTO與其他技術進行整合,構建一個完善的解決方案。

      posted @ 2010-03-08 23:46  江蘇瑞步科技  閱讀(3587)  評論(8)    收藏  舉報
      主站蜘蛛池模板: 久章草在线毛片视频播放| 三上悠亚久久精品| 久久香蕉国产线看观看精品yw| 国产一精品一av一免费爽爽 | 诏安县| 激情综合色区网激情五月| 亚洲成人免费一级av| 91老肥熟女九色老女人| 国产成人a在线观看视频| 国内自拍视频一区二区三区| 国产精品中文av专线| 无码AV无码免费一区二区| 99国产欧美久久久精品蜜芽 | 久久永久视频| 日本狂喷奶水在线播放212| 久久久久久久波多野结衣高潮| a级国产乱理伦片在线观看al| 河北真实伦对白精彩脏话| 日本视频一区二区三区1| 亚洲韩国精品无码一区二区三区| 亚洲无码在线免费观看| 国产亚洲精品AA片在线爽| 熟妇激情一区二区三区| 激情综合网激情五月俺也想| 国产视频一区二区三区四区视频| 亚洲精品中文字幕尤物综合| 久久精品国产亚洲av高| 国产精品无码专区| 宾馆人妻4P互换视频| 国产睡熟迷奷系列网站| 天天躁日日躁狠狠躁中文字幕| 亚洲日韩欧美丝袜另类自拍 | 国产一级三级三级在线视| 国产99久久精品一区二区| 漂亮的保姆hd完整版免费韩国 | 精品国产午夜福利在线观看| 白丝乳交内射一二三区| 国产首页一区二区不卡| 国产伦精品一区二区亚洲| 久久国产乱子伦免费精品无码 | 五级黄高潮片90分钟视频|