2011-12-14 51 views
0

我正在學習SharePoint與Web部件,我想弄清楚這個示例代碼和我做了什麼。 這裏是樣品Sharepoint控件和webparts C#說明

using System; 
using System.Runtime.InteropServices; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Serialization; 
using Microsoft.SharePoint; 
using Microsoft.SharePoint.WebControls; 
using Microsoft.SharePoint.WebPartPages; 

namespace SampleWebpart1 

    { 
    [Guid("cf5f3fd5-1776-4c47-9587-4f6fe4f3d645")] 

    public class SampleWebpart1 : Microsoft.SharePoint.WebPartPages.WebPart    
     { 

      public SampleWebpart1() { } 

      protected override void CreateChildControls() 
      { 
       base.CreateChildControls(); 
       SharePointCalendar calendar = new SharePointCalendar(); 
       Controls.Add(calendar); 
      } 
     } 

    public class SharePointCalendar : Control 

    { 
     private SPCalendarView _view; 
     /// Create the SharePoint calendar. Uses the SharePoint SPCalendarView object. 
     protected override void CreateChildControls() 
     { 
      base.CreateChildControls(); 
      _view = new SPCalendarView(); 
      _view.EnableViewState = true; 
      _view.Width = Unit.Percentage(100); 
      _view.DataSource = GetCalendarItems(); 
      DataBind(); 
      Controls.Add(_view); 
     } 

     private SPCalendarItemCollection GetCalendarItems() 
     { 

      // Create a new collection for the calendar items 
      // This is an item with a start and end date. 
      SPCalendarItemCollection items = new SPCalendarItemCollection(); 
     // Add the first dummy item 
      SPCalendarItem item = new SPCalendarItem(); 
      item.StartDate = DateTime.Now; 
      item.EndDate = DateTime.Now.AddHours(1); 
      item.hasEndDate = true; 
      item.Title = "First calendar item"; 
      item.DisplayFormUrl = "/News"; 
      item.Location = "USA"; 
      item.Description = "This is the first test item in the calendar rollup"; 
      item.IsAllDayEvent = false; 
      item.IsRecurrence = false; 
      item.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian); 
      items.Add(item); 
     // Add the second item. This is an all day event. 
     SPCalendarItem item2 = new SPCalendarItem(); 
     item2.StartDate = DateTime.Now.AddDays(-1); 
     item.hasEndDate = true; 
     item2.Title = "Second calendar item"; 
     item2.DisplayFormUrl = "/News"; 
     item2.Location = "India"; 
     item2.Description = "This is the second test item in the calendar rollup"; 
     item2.IsAllDayEvent = true; 
     item2.IsRecurrence = false; 
     item2.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian); 
     items.Add(item2); 
     // return the collection 
     return items; 
     } 

     } 

    } 

原來這就是我在我的第一個問題就是工作,這是什麼 [的Guid(「cf5f3fd5-1776-4c47-9587-4f6fe4f3d645」)的意思或做。我在XNA中看到過類似的內容,但這是爲了處理內容。

這是什麼意思:在這一行公共類SharePointCalendar:控制 這是說,類sharpointcalendar擴展控件?

這一切都做了什麼?爲什麼有一個_前查看?

 _view = new SPCalendarView(); 
     _view.EnableViewState = true; 
     _view.Width = Unit.Percentage(100); 
     _view.DataSource = GetCalendarItems(); 

感謝任何幫助:)

+2

這些都是很基本的問題。也許你應該先學習C#。 – 2011-12-14 18:38:12

回答

0

的_破折號聲明,該變量是私有的,這是可選的,只要你喜歡,你可以爲它們命名。但是大多數編程語言遵循這種稱爲命名約定的模式,我認爲在開始在SharePoint中開發之前您應該瞭解這些約定! :)

  • 公共 - 第一個字母是大寫
  • 保護 - 第一個字母是小寫
  • _private - 第一個字母是破折號後面是小寫字母

GUID是表示相關類的COM標識符,它用於標識外部世界的組件。

除非您計劃在遠程系統中運行webpart或通過外部程序集或類似方式訪問它,否則在本示例中我幾乎沒有看到guid存在的原因。

+0

啊非常感謝,幫助了很多。 – MNM 2011-12-14 19:12:46

1

在進入SharePoint開發之前,您應該瞭解C#和ASP.NET - 「C#分步」和「ASP.NET分步」(微軟出版社)可以開始的書數量。先學習C#,然後移到ASP.NET。之後,您已準備好進入SharePoint開發。一個好的起點是一本像「開始SharePoint 2010開發」(WROX)Press這樣的書。

GUID代表「全局唯一標識符」 - 它是一個唯一的ID,可以分配給任何資源在Windows中。 GUID可能被稱爲「Galactically Unique Identfiers」,因爲任何兩個GUID都不會重複。

類聲明中的冒號意味着類從控件繼承。

+0

啊,它繼承形式的控制我現在得到它,謝謝 – MNM 2011-12-19 22:25:34