日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一步一步SharePoint 2007之二十三:编写一个最简单的WebPart(1)——创建工程

發布時間:2025/7/25 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一步一步SharePoint 2007之二十三:编写一个最简单的WebPart(1)——创建工程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
摘要
  在前面的文章中,我們講解了很多基礎的內容,主要包括安裝配置、Form認證等。可能這些對很多朋友來說,是太容易了。那么,從下一篇文章開始,就讓我們進入SharePoint的高級課題之旅吧。
  本篇文章將介紹如何編寫一個最簡單的WebPart。
  跟所有的編程技術一樣,都是從編寫第一個Hello World程序開始的。筆者自嘆也是一個俗人,所以當然也不能免俗,我們就也從編寫一個Hello World的WebPart開始吧!
正文
  考慮到編寫一個最簡單的WebPart的文章共有20多幅截圖,截圖總大小近2M,為了盡量減少打開網頁的時間,本篇文章將被分割成幾個小的部分。因此而給大家帶來的閱讀不便,就請海涵了:)
  本篇文章將創建一個WebPart工程。
  為了方便您的學習,您可以下載本篇文章所創建的工程。單擊此處下載。

  下面將記錄每一步的操作過程。
  1、首先Visual Studio 2005,在菜單中依次選擇File,New,Project。


  2、單擊Project后,即彈出New Project對話框。這里我們選擇創建一個C#語言的Class Library工程,工程名稱為Eallies.WebParts.Hello。


  3、新建工程完畢后,將默認的Class1改名為Instance,則整個工程就是這樣的:


  4、在右邊的Solution Explorer中,右鍵單擊References,在彈出的菜單中選擇Add Reference,則彈出Add Reference對話框。這里我們選擇Component Name為System.Web。


  5、添加完Reference后,我們打開Instance.cs,將其代碼更改為:

????1?using System;

????2?using System.Collections.Generic;

????3?using System.Text;

????4?using System.Web.UI.WebControls.WebParts;

????5?

????6?namespace Hello

????7?{

????8???? public class Hello : WebPart

????9???? {

???10???? ??? private string _Text = "Hello World!";

???11?

???12???? ??? [WebBrowsable(true), Personalizable(true)]

???13???? ??? public string Text

???14???? ??? {

???15???? ??? ??? get { return _Text; }

???16???? ??? ??? set { _Text = value; }

???17???? ??? }

???18???? ??? protected override void Render(System.Web.UI.HtmlTextWriter writer)

???19???? ??? {

???20???? ??? ??? writer.Write(_Text);

???21???? ??? }

???22???? }

???23?}



  6、然后再打開Properties\AssemblyInfo.cs,將其代碼更改為:

????1?using System.Reflection;

????2?using System.Runtime.CompilerServices;

????3?using System.Runtime.InteropServices;

????4?using System.Security;

????5?

????6?// General Information about an assembly is controlled through the following

????7?// set of attributes. Change these attribute values to modify the information

????8?// associated with an assembly.

????9?[assembly: AssemblyTitle("Hello")]

???10?[assembly: AssemblyDescription("")]

???11?[assembly: AssemblyConfiguration("")]

???12?[assembly: AssemblyCompany("Eallies Corporation")]

???13?[assembly: AssemblyProduct("Hello")]

???14?[assembly: AssemblyCopyright("Copyright ? Eallies Corporation 2006")]

???15?[assembly: AssemblyTrademark("")]

???16?[assembly: AssemblyCulture("")]

???17?

???18?// Setting ComVisible to false makes the types in this assembly not visible

???19?// to COM components.? If you need to access a type in this assembly from

???20?// COM, set the ComVisible attribute to true on that type.

???21?[assembly: ComVisible(false)]

???22?

???23?// The following GUID is for the ID of the typelib if this project is exposed to COM

???24?[assembly: Guid("8318200d-9059-4b4e-81db-c146659bd89d")]

???25?

???26?// Version information for an assembly consists of the following four values:

???27?//

???28?//??? ? Major Version

???29?//??? ? Minor Version

???30?//??? ? Build Number

???31?//??? ? Revision

???32?//

???33?// You can specify all the values or you can default the Revision and Build Numbers

???34?// by using the '*' as shown below:

???35?[assembly: AssemblyVersion("1.0.0.0")]

???36?[assembly: AssemblyFileVersion("1.0.0.0")]

???37?

???38?[assembly: AllowPartiallyTrustedCallers()]

  這里,我們實際上只是引用了System.Security,然后加上了[assembly: AllowPartiallyTrustedCallers()]這一行代碼。


  至此,WebPart工程即創建完畢。
  下一篇文章我將記錄如何編寫一個最簡單的WebPart的第二部分。歡迎大家繼續關注:)多謝!

轉載于:https://www.cnblogs.com/wayne-ivan/archive/2007/09/15/894148.html

總結

以上是生活随笔為你收集整理的一步一步SharePoint 2007之二十三:编写一个最简单的WebPart(1)——创建工程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。