MOSS通用类 通用方法整理

OM通用:

提升权限读取:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SPSecurity

 

 

.RunWithElevatedPrivileges( delegate

()

{

 

 

 

 

      SPWeb web = SPControl .GetContextWeb(context);

 

 

      using ( SPSite elevSite = new SPSite (web.Site.ID))

      {

 

 

         using ( SPWeb  elevWeb = elevSite.OpenWeb(web.ID))

           {

 

 

               SPList list = elevWeb.Lists[ "ListName" ];

 

 

               SPListItemCollection items = list.Items;

 

 

               if (items != null)

              {

 

 

                for ( int i = 0; i < items.Count; i++)

                {

                    //....

                 }

              }

            }

       }

 

 

});

 

如果为权限读取:

SPList list = elevWeb.Lists["ListName"];

 

 

SPListItemCollection items = list.Items;

 

 

if (items != null)

{

 

 

      for (int i = 0; i < items.Count; i++)

       {

                    //....

        }

}

 

在js中Share Point web Service方法:只列出有用的几个类型的读取。

 

//-------------------------the following code is core source code , you can use it directly.---------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

//Below is the core js source code.

 

 

 

function

SPAPI_Lists() {

 

 

this .core = new

SPAPI_Core();

 

 

this .serviceUrl = baseUrl + '/_vti_bin/lists.asmx'

;

 

 

/* List template IDs */

 

 

this .LIST_ID_DOCUMENT_LIBRARY = 101

// Document library

 

 

this .LIST_ID_USER_INFO = 112

// User Information list

 

 

this .LIST_ID_GENERIC = 100

// Generic list

 

 

/*-------------------*/

 

 

this .getListItems = function

(listName, viewName, query, viewFields, rowLimit, queryOptions, webID) {

 

 

if (queryOptions == null || queryOptions == '' ) queryOptions = '<QueryOptions/>'

;

 

 

var action = 'http://schemas.microsoft.com/sharepoint/soap/GetListItems'

;

 

 

var

params = [listName, viewName, query, viewFields, rowLimit, queryOptions, webID];

 

 

var packet = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>{0}</listName><viewName>{1}</viewName><query>{2}</query><viewFields>{3}</viewFields><rowLimit>{4}</rowLimit><queryOptions>{5}</queryOptions><webID>{6}</webID></GetListItems></soap:Body></soap:Envelope>'

;

 

 

return this .core.executeRequest( this

.serviceUrl, action, packet, params);

}

}

function

 

 

SPAPI_Core() {

 

 

this .createXMLHttpRequest = function

() {

 

 

if ( typeof XMLHttpRequest != "undefined"

) {

 

 

return new

XMLHttpRequest();

}

 

 

else if ( typeof ActiveXObject != "undefined"

) {

 

 

return new ActiveXObject( "Microsoft.XMLHTTP"

);

}

 

 

else

{

 

 

throw new Error( "XMLHttpRequest not supported"

);

}

}

 

 

this .executeRequest = function

(serviceUrl, action, packet, params) {

 

 

var oXMLHttpRequest = this

.createXMLHttpRequest();

 

 

var result = null

;

 

 

var

resultName;

oXMLHttpRequest.open(

 

"POST" , serviceUrl, false

);

oXMLHttpRequest.setRequestHeader(

 

"Content-Type" , "text/xml; charset=utf-8"

);

oXMLHttpRequest.setRequestHeader(

 

"SOAPAction"

, action);

 

 

if (params != null

) {

 

 

for ( var

i = 0; i < params.length; i++) {

packet = packet.replace(

 

'{' + i.toString() + '}' , (params[i] == null ? ''

: params[i]));

}

}

oXMLHttpRequest.send(packet);

resultName = action.substring(action.lastIndexOf(

 

'/' ) + 1) + 'Result'

;

 

 

var

resBatch;

 

 

var

status;

 

 

var

statusText;

status = oXMLHttpRequest.status;

statusText = oXMLHttpRequest.statusText;

 

 

if

(status == 200) {

 

 

// Check for SharePoint error code

resBatch = oXMLHttpRequest.responseXML.getElementsByTagName(resultName);

 

 

var codeEl = oXMLHttpRequest.responseXML.getElementsByTagName( 'ErrorCode'

);

 

 

if (codeEl != null

&& codeEl.length > 0) {

 

 

var

spStatus = parseInt(codeEl[0].childNodes[0].nodeValue);

 

 

if

(spStatus != 0) {

status = 0 - spStatus;

 

// Note we make this -ve to prevent confusion with the HTTP code

 

 

var messageEl = oXMLHttpRequest.responseXML.getElementsByTagName( 'ErrorText'

);

 

 

if (messageEl != null

&& messageEl.length >= 0) {

statusText = messageEl[0].childNodes[0].nodeValue;

}

}

}

}

result = {

status: status,

statusText: statusText,

responseXML: oXMLHttpRequest.responseXML,

responseText: oXMLHttpRequest.responseText,

resultNode: (resBatch ==

 

null || resBatch.length == 0 ? null

: resBatch[0])

};

 

 

return

result;

//-------------------------------end--------------------------

 

 

 

使用方法示例:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

function

 

 

searchIssueByID() {

 

 

var lists = new SPAPI_Lists( ''

);

 

 

 

 

var items = lists.getListItems( 'Issues' , '' , '<Query><Where><Eq><FieldRef Name="ID"/><Value Type="Counter">' + issueId + '</Value></Eq></Where></Query>' ,

// query

 

 

'<ViewFields><FieldRef Name="Name"/></ViewFields>'

,

1,

 

// rowLimit

 

 

''

// queryOptions

);

 

 

if (items.status == 200)

{

 

 

     var rows = items.responseXML.getElementsByTagName( 'z:row' );

 

 

}

);

 

 

return false

;

 

以上是在应用开发中常用到的。随时补充。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值