2011年9月23日 星期五

利用 C# 開啟 SharePoint 的 DashBoard 的功能

1. 開啟 Visual Studio 2010 ,建立一個 Windows Form 應用程式

2. 在畫面上佈置控制項如下

3. 要加入參考,「Microsoft.SharePoint」

4. 要選 NET Framework 3.5、平台要選 Any CPU


5. 貼上以下的程式碼

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint.Administration;

namespace SPSDashBoard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SPWebService contentService = SPWebService.ContentService;
            SPDeveloperDashboardSettings developerDashboard =
              contentService.DeveloperDashboardSettings;
            developerDashboard.DisplayLevel = SPDeveloperDashboardLevel.On; //關閉是Off
            developerDashboard.Update();
            MessageBox.Show("Developer Dashboard updated.");

        }
    }
}


6. 回到網頁上,可以看到下方已經開啟 DashBoard了


沒有留言:

張貼留言