OM通用:

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/%22%3E%3Csoap:Body%3E%3Cgetlistitems xmlns="http://schemas.microsoft.com/sharepoint/soap/%22%3E%3Clistname%3E%7B0%7D%3C/listname%3E%3Cviewname%3E%7B1%7D%3C/viewname%3E%3Cquery%3E%7B2%7D%3C/query%3E%3Cviewfields%3E%7B3%7D%3C/viewfields%3E%3Crowlimit%3E%7B4%7D%3C/rowlimit%3E%3Cqueryoptions%3E%7B5%7D%3C/queryoptions%3E%3Cwebid%3E%7B6%7D%3C/webid%3E%3C/getlistitems%3E%3C/soap:Body%3E%3C/soap:Envelope%3E'
;

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
;

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


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/nathan_romain/archive/2009/10/15/4674549.aspx

posted @ 2010-09-09 11:49  China2008  阅读(341)  评论(0编辑  收藏  举报