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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Sharepoint学习笔记---Sandbox Solution-- Full Trust Proxy--开发实例之(2、在Webpart中访问Full Trust Proxy)...

發布時間:2023/12/15 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Sharepoint学习笔记---Sandbox Solution-- Full Trust Proxy--开发实例之(2、在Webpart中访问Full Trust Proxy)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

上一篇Sharepoint學習筆記---Sandbox Solution-- Full Trust Proxy--開發實例之(1、創建一個能訪問DataBase的Full Trust Proxy), 我們在Sharepoint的Farm Solution中創建,部署并注冊了一個能訪問數據庫的Full trust Proxy,這一篇我們將在Sharepoint的Sandbox Solution中創建一個Webpart,并通過前面創建的Full trust proxy訪問數據庫,把訪問結果顯示在我們創建的Webpart中。
進入操作步驟。
一、創建和設置項目
? 1、打開VS2010,創建一個空項目Empty SharePoint Project,命名為MyTestSandBoxAccessDBWebPart,如下圖
??

? 此項目為Sandbox類型的


? 2、在Solution Explorer中,右擊References目錄,選擇Add reference,在跳出的Add Reference窗口,選擇Browse欄,瀏覽到你部署的Full trust Proxy類所在目錄
C:\Windows\assembly\GAC_MSIL\My.Sharepoint.SandBox


進入對應的版本


選擇My.Sharepoin.SandBox.dll類


引用成功后,可以雙擊此類,看到它里面定義的對應內容


?

二、創建Webpart并調用Full Trust Proxy
1、在Solution Explorer中,右擊項目,選擇Add,添加New Item,選擇Webpart(注意:不能選擇添加Visual Web Part),并命名為TestSandboxSolutionAccessDataBaseWebPart
?
2、在Solution Explorer中,雙擊TestDBWebpart.webpart,編輯內容如下:

此處我們設置了它的Title和Description.


3、右擊Feature1,重命名為DataBaseWebPart,
?

然后雙擊DataBaseWebPart,打開Feature Designer,在此窗口中設置如下圖


?

4、修改TestDBWebpart.cs代碼如下:

using?System;
using?System.ComponentModel;
using?System.Web;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?Microsoft.SharePoint;
using?Microsoft.SharePoint.WebControls;

using?Microsoft.SharePoint.UserCode;
using?Microsoft.SharePoint.Administration;
using?Microsoft.SharePoint.Utilities;
using?System.Data;
using?My.Sharepoint.SandBox;

namespace?MyTestSandBoxAccessDBWebPart.TestDBWebpart
{
????[ToolboxItemAttribute(
false)]
????
public?class?TestDBWebpart?:?WebPart
????{
????????
private?TextBox?txtDBConnection?=?new?TextBox()?{?Text?=?@"Data?Source=Data?Source=serverDB;Initial?Catalog=MyDb;User?ID=MyApp;Password=mypwd"?};
????????
private?TextBox?txtSQLCommand?=?new?TextBox()?{?Text?=?@"SELECT?TOP(100)*?FROM?dbo.myTable"?};

????????
private?Label?results?=?new?Label();
????????
private?Label?lblFileContent?=?new?Label()?{?Text?=?"Input?DBConnectionStr?:"?};
????????
private?Label?lblFileName?=?new?Label()?{?Text?=?"Input?SQL?Command?:"?};

????????
private?Button?btnAccessDatabase?=?new?Button()?{?Text?=?"Access?Database"?};
????????
private?GridView?gv?=?new?GridView();

????????
public?TestDBWebpart()
????????{
????????????
#region??ProxyOne

????????????
string?assemblyName?=?"My.Sharepoint.SandBox,?Version=1.0.0.0,?Culture=neutral,?PublicKeyToken=9f460c3b7a15fdf1";
????????????
string?typeName?=?"My.Sharepoint.SandBox.MyTestSandBoxAccessDBInfo.TestProxyCode.SQLProxyExecute";

????????????
try
????????????{
????????????????btnAccessDatabase.Click?
+=?(object?sender,?EventArgs?e)?=>
????????????????{
????????????????????
string?DBConnectionString?=?txtDBConnection.Text.ToString().Trim();
????????????????????
string?SQLCommandStr?=?txtSQLCommand.Text.ToString().Trim();

????????????????????DataTable?dt?
=?((DataSet)SPUtility.ExecuteRegisteredProxyOperation(assemblyName,?typeName,
????????????????????????
new?My.Sharepoint.SandBox.MyTestSandBoxAccessDBInfo.TestProxyCode.SQLProxyArgs(DBConnectionString,?SQLCommandStr))).Tables[0];
????????????????????gv.DataSource?
=?dt;
????????????????????gv.DataBind();
????????????????};
????????????}
????????????
catch?(Exception?ex)
????????????{
????????????????results.Text?
=?ex.ToString();
????????????}
????????????
#endregion

????????}

????????
protected?override?void?CreateChildControls()
????????{
????????????Table?layoutTable?
=?new?Table();

????????????
#region?Create?Table
????????????
//Input?File?Content?Row
????????????layoutTable.Rows.Add(new?TableRow());
????????????layoutTable.Rows[
0].Cells.Add(new?TableCell());
????????????layoutTable.Rows[
0].Cells.Add(new?TableCell());

????????????
//Input?File?Location?Row
????????????layoutTable.Rows.Add(new?TableRow());
????????????layoutTable.Rows[
1].Cells.Add(new?TableCell());
????????????layoutTable.Rows[
1].Cells.Add(new?TableCell());

????????????
//Create?File?button?Row
????????????layoutTable.Rows.Add(new?TableRow());
????????????layoutTable.Rows[
2].Cells.Add(new?TableCell()?{?ColumnSpan?=?2?});

????????????
//Show?Result?Row
????????????layoutTable.Rows.Add(new?TableRow());
????????????layoutTable.Rows[
3].Cells.Add(new?TableCell()?{?ColumnSpan?=?2?});

????????????txtDBConnection.Width?
=?400;
????????????txtSQLCommand.Width?
=?400;

????????????layoutTable.Rows[
0].Cells[0].Controls.Add(lblFileContent);
????????????layoutTable.Rows[
0].Cells[1].Controls.Add(txtDBConnection);

????????????layoutTable.Rows[
1].Cells[0].Controls.Add(lblFileName);
????????????layoutTable.Rows[
1].Cells[1].Controls.Add(txtSQLCommand);

????????????layoutTable.Rows[
2].Cells[0].Controls.Add(btnAccessDatabase);
????????????layoutTable.Rows[
3].Cells[0].Controls.Add(results);

????????????
#endregion

????????????
this.Controls.Add(layoutTable);
????????????
this.Controls.Add(gv);
????????????
base.CreateChildControls();
????????}


????????
protected?override?void?RenderContents(HtmlTextWriter?writer)
????????{
????????????
base.RenderContents(writer);
????????}
????}
}

?在上面的代碼中,如何取得Assembly Name中的相應值,可參見此文 :

Sharepoint學習筆記--- 快速確定VisualStudio2010當前Project的assembly name

?在此Webpart中,我們創建了兩個TextBox,一個用于輸入數據庫連接字符串,一個用于輸入SQL語句。同時還定義了一個按鈕,并Attach了此按鈕的Click事件,當點擊此按鈕后,后臺代碼會通過取得的參數,傳遞給Full Trust Proxy類,通過Full Trust Proxy類去訪問數據庫內容,然后把取得的結果傳遞回來,顯示在Webpart上的GridView控件中。

?

三、部署并使用Webpart呈現DataBase數據庫數據
?Build并部署此項目。成功后,在測試Sharepoint網站上創建一個Web Part Page,在此Page上加入部署的Webpart,然后在此Webpart的相應Text框中輸入相應內容再點擊Access Database按鈕

可看到結果



總結

以上是生活随笔為你收集整理的Sharepoint学习笔记---Sandbox Solution-- Full Trust Proxy--开发实例之(2、在Webpart中访问Full Trust Proxy)...的全部內容,希望文章能夠幫你解決所遇到的問題。

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