Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 Sharepoint 2010自定义Web部件-拒绝访问错误_Visual Studio 2010_Sharepoint 2010 - Fatal编程技术网

Visual studio 2010 Sharepoint 2010自定义Web部件-拒绝访问错误

Visual studio 2010 Sharepoint 2010自定义Web部件-拒绝访问错误,visual-studio-2010,sharepoint-2010,Visual Studio 2010,Sharepoint 2010,我们已经创建了一个自定义Web部件来显示用户有权访问的所有列表中的公告,删除了一些。我们遇到的错误是,对于管理员来说,Web部件在页面上工作正常,但是当使用常规用户帐户进行测试时,他们根本看不到该页面,并且会收到来自Web部件本身的拒绝访问错误 只有将用户添加为网站集管理员时,他们才能查看页面并访问Web部件。我想要一些建议,关于如何能够在代码本身中对一个选择组应用完全读取权限 下面是后端代码 using System; using System.Data; using System.Web.U

我们已经创建了一个自定义Web部件来显示用户有权访问的所有列表中的公告,删除了一些。我们遇到的错误是,对于管理员来说,Web部件在页面上工作正常,但是当使用常规用户帐户进行测试时,他们根本看不到该页面,并且会收到来自Web部件本身的拒绝访问错误

只有将用户添加为网站集管理员时,他们才能查看页面并访问Web部件。我想要一些建议,关于如何能够在代码本身中对一个选择组应用完全读取权限

下面是后端代码

using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace Test.TestWebPart
{

    public partial class TestWebPartUserControl : UserControl
    {
        //Global variable call
        private SPSite thisSite = SPContext.Current.Site;
        private SPWebCollection thisWeb;
        private DataTable dt;
        private SPListCollection siteLists;
        private DataTableWrapper myDataTable;

        //Occurs when the page loads
        protected void Page_Load(object sender, EventArgs e)
        {
            //Pulls all the websites in the site into a webcollection
            thisWeb = thisSite.AllWebs;

            //If the page is not postback call BindToGrid()
            if (!Page.IsPostBack)
            {
                BindToGrid();
            }
        }

        private void BindToGrid()
        {
            //Create a new DataTable along with the columns and headers
            dt = new DataTable();
            dt.Columns.Add("Title");
            dt.Columns.Add("Created");
            dt.Columns.Add("List");

            //Call to populate the DataTable
            dt = SelectData();

            //Populate DataTableWrapper class and get the type
            myDataTable = new DataTableWrapper(dt);
            Type t = myDataTable.GetType();

            //Create a ObjectDataSource to hold data and bind to spgridview
            ObjectDataSource ds = new ObjectDataSource();
            ds.ID = "myDataSource";
            ds.TypeName = t.AssemblyQualifiedName;
            ds.SelectMethod = "GetTable";
            ds.ObjectCreating += new ObjectDataSourceObjectEventHandler(ds_ObjectCreating);
            this.Controls.Add(ds);

            grid.ID = "gridID";

            BoundField column = new BoundField();
            column.DataField = "Title";
            column.HtmlEncode = false;
            //column.SortExpression = "Title";
            column.HeaderText = "Title";
            grid.Columns.Add(column);

            BoundField column1 = new BoundField();
            column1.DataField = "Created";
            column1.HtmlEncode = true;
            //column1.SortExpression = "Created";
            column1.HeaderText = "Created";
            grid.Columns.Add(column1);

            BoundField column2 = new BoundField();
            column2.DataField = "List";
            column2.HtmlEncode = false;
            //column2.SortExpression = "List";
            column2.HeaderText = "List";
            grid.Columns.Add(column2);


            //Provide the SPGridview with the DataSource
            grid.DataSourceID = "myDataSource";
            this.Controls.Add(grid);

            //grid.PageSize =10;
            //grid.AllowPaging = true;

            //Default Pagination - commented out due to not working
            //grid.PageIndexChanging += new GridViewPageEventHandler(grid_PageIndexChanging);
            //grid.PagerTemplate = null;

            //Bind the data to the grid
            grid.DataBind();

        }

        //private void GenerateColumns()
        //{

        //}

        //Used to deal with the PageIndexChange event
        void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grid.PageIndex = e.NewPageIndex;
            grid.DataBind();
        }

        //Used to deal with the ObjectCreated event
        void ds_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            myDataTable = new DataTableWrapper(dt);
            e.ObjectInstance = myDataTable;
        }

        //Pulls the data from lists which will be displayed
        public DataTable SelectData()
        {
            try
            {
                //Create a new instance of type DataRow
                DataRow row;

                //Loop through each website in the webcollection
                foreach (SPWeb web in thisWeb)
                {
                    //Pull the lists from the site into a list collection
                    siteLists = web.Lists;
                    //Display only lists the current user has access to
                    siteLists.ListsForCurrentUser = true;

                    //Loop through each list within the list collection
                    foreach (SPList list in siteLists)
                    {

                            //If the list is an announcement list continue otherwise skip
                            if (list.BaseTemplate.ToString() == "Announcements")
                            {
                                //Exclude the lists stated from those whose data will be collected
                                if (list.Title.ToString() == "Bulletins" || list.Title.ToString() == "The Buzz - Curriculum" || list.Title.ToString() == "The Buzz - Personal" || list.Title.ToString() == "The Buzz - Support" || list.Title.ToString() == "Critical Annoucements")
                                {
                                }
                                else
                                {
                                    //Create a item collection for each item within the current list
                                    SPListItemCollection listItem = list.Items;

                                    //Loop through each item within the item collection
                                    foreach (SPListItem item in listItem)
                                    {
                                        //Get the url of the current website
                                        string weburl = web.Url;
                                        //Gets the URL of the current item
                                        string dispurl = item.ContentType.DisplayFormUrl;
                                        dispurl = list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url;

                                        //Joins together the full URL for the current item into a single variable
                                        dispurl = string.Format("{0}/{1}?ID={2}", weburl, dispurl, item.ID);
                                        //Create a new in the datatable as an instance of row
                                        row = dt.Rows.Add();

                                        //Put the correct information and links into the correct column
                                        row["Title"] = "<a target=_blank href=\"" + dispurl + "\">" + item["Title"].ToString() + "</a>";
                                        row["Created"] = item["Created"].ToString();
                                        row["List"] = "<a target=_blank href=\"" + list.DefaultViewUrl + "\">" + list.Title + "</a>";
                                    }
                                }
                            }
                    }
                }
                //Return the completed DataTable
                return dt;
            }

            //Exception to catch any errors
            catch (Exception s)
            {
                return dt;
            }
        }
    }
}
使用系统;
使用系统数据;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用System.Web.UI.WebControl.WebParts;
使用Microsoft.SharePoint;
命名空间Test.TestWebPart
{
公共部分类TestWebPartUserControl:UserControl
{
//全局变量调用
私有SPSite thisSite=SPContext.Current.Site;
私人SPWebCollection thisWeb;
专用数据表dt;
私人收藏网站列表;
私有数据表包装器myDataTable;
//在页面加载时发生
受保护的无效页面加载(对象发送方、事件参数e)
{
//将站点中的所有网站拉入webcollection
thisWeb=thisSite.AllWebs;
//如果页面不是回发,请调用BindToGrid()
如果(!Page.IsPostBack)
{
BindToGrid();
}
}
私有void BindToGrid()
{
//创建一个新的DataTable以及列和标题
dt=新数据表();
dt.列。添加(“标题”);
dt.列。添加(“已创建”);
dt.列。添加(“列表”);
//调用以填充数据表
dt=SelectData();
//填充DataTableWrapper类并获取类型
myDataTable=新的DataTableWrapper(dt);
类型t=myDataTable.GetType();
//创建ObjectDataSource以保存数据并绑定到spgridview
ObjectDataSource ds=新的ObjectDataSource();
ds.ID=“myDataSource”;
ds.TypeName=t.AssemblyQualifiedName;
ds.SelectMethod=“GetTable”;
ds.ObjectCreating+=新的ObjectDataSourceObjectEventHandler(ds_ObjectCreating);
this.Controls.Add(ds);
grid.ID=“gridID”;
BoundField列=新的BoundField();
column.DataField=“Title”;
column.HtmlEncode=false;
//column.SortExpression=“Title”;
column.HeaderText=“Title”;
grid.Columns.Add(column);
BoundField column1=新的BoundField();
column1.DataField=“已创建”;
column1.HtmlEncode=true;
//column1.SortExpression=“已创建”;
column1.HeaderText=“已创建”;
grid.Columns.Add(column1);
BoundField column2=新的BoundField();
column2.DataField=“List”;
column2.HtmlEncode=false;
//column2.SortExpression=“List”;
column2.HeaderText=“列表”;
grid.Columns.Add(column2);
//为SPGridview提供数据源
grid.DataSourceID=“myDataSource”;
this.Controls.Add(网格);
//grid.PageSize=10;
//grid.allowpage=true;
//默认分页-由于不工作而被注释掉
//grid.PageIndexChanging+=新的GridViewPageEventHandler(grid\u PageIndexChanging);
//grid.PagerTemplate=null;
//将数据绑定到网格
grid.DataBind();
}
//私有void GenerateColumns()
//{
//}
//用于处理PageIndexChange事件
无效网格\u页面索引交换(对象发送方,GridViewPageEventArgs e)
{
grid.PageIndex=e.NewPageIndex;
grid.DataBind();
}
//用于处理ObjectCreated事件
void ds_ObjectCreating(对象发送方,ObjectDataSourceEventArgs e)
{
myDataTable=新的DataTableWrapper(dt);
e、 ObjectInstance=myDataTable;
}
//从将显示的列表中提取数据
公共数据表SelectData()
{
尝试
{
//创建DataRow类型的新实例
数据行;
//在webcollection中循环浏览每个网站
foreach(此web中的SPWeb)
{
//将列表从站点拉入列表集合
siteLists=web.Lists;
//仅显示当前用户有权访问的列表
siteLists.ListsForCurrentUser=true;
//循环浏览列表集合中的每个列表
foreach(站点列表中的SPList列表)
{
//如果列表是公告列表,则继续,否则跳过
if(list.BaseTemplate.ToString()=“公告”)
{
//从将要收集数据的列表中排除所述列表
如果(list.Title.ToString()=“公告”| | list.Title.ToString()=“热门课程”| | list.Title.ToString()=“热门个人”| | list.Title.ToString()=“热门支持”| | list.Title.ToString()=“关键公告”)
{
}
其他的
{
//为当前列表中的每个项目创建项目集合
SPListItemCollection listItem=列表项;
//环路
thisWeb = thisSite.AllWebs;
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace Test.TestWebPart
{
    public partial class TestWebPartUserControl : UserControl
    {
        //Global variable call
        private SPSite thisSite = SPContext.Current.Site;
        //private SPWebCollection thisWeb;//
        private SPWeb thisWeb = SPContext.Current.Web;
        private DataTable dt;
        private SPListCollection siteLists;
        private DataTableWrapper myDataTable;


        //Occurs when the page loads
        protected void Page_Load(object sender, EventArgs e)
        {
            //Pulls all the websites in the site into a webcollection
            //thisWeb = thisSite.AllWebs.;//

            //If the page is not postback call BindToGrid()
            if (!Page.IsPostBack)
            {
                BindToGrid();
            }
        }

        private void BindToGrid()
        {
            //Create a new DataTable along with the columns and headers
            dt = new DataTable();
            dt.Columns.Add("Title");
            dt.Columns.Add("Created");
            dt.Columns.Add("List");

            //Call to populate the DataTable
            dt = SelectData();

            //Populate DataTableWrapper class and get the type
            myDataTable = new DataTableWrapper(dt);
            Type t = myDataTable.GetType();

            //Create a ObjectDataSource to hold data and bind to spgridview
            ObjectDataSource ds = new ObjectDataSource();
            ds.ID = "myDataSource";
            ds.TypeName = t.AssemblyQualifiedName;
            ds.SelectMethod = "GetTable";
            ds.ObjectCreating += new ObjectDataSourceObjectEventHandler(ds_ObjectCreating);
            this.Controls.Add(ds);

            grid.ID = "gridID";


            //Sorting, Filtering & paging does not work so has been commented out for now
            //this.grid.AllowSorting = true;


            //Bind the three columns to the SPGridView
            //HtmlEncode must be false for the links to appear as true html
            BoundField column = new BoundField();
            column.DataField = "Title";
            column.HtmlEncode = false;
            //column.SortExpression = "Title";
            column.HeaderText = "Title";
            grid.Columns.Add(column);

            BoundField column1 = new BoundField();
            column1.DataField = "Created";
            column1.HtmlEncode = true;
            //column1.SortExpression = "Created";
            column1.HeaderText = "Created";
            grid.Columns.Add(column1);

            BoundField column2 = new BoundField();
            column2.DataField = "List";
            column2.HtmlEncode = false;
            //column2.SortExpression = "List";
            column2.HeaderText = "List";
            grid.Columns.Add(column2);


            //Has been commented out due to these sections not working
            //grid.AllowFiltering = true;

            //grid.FilterDataFields = "Title";
            //grid.FilteredDataSourcePropertyName = "FilterExpression";
            //grid.FilteredDataSourcePropertyFormat = "{1} like '{0}'";

            //grid.FilterDataFields = "Created";
            //grid.FilteredDataSourcePropertyName = "FilterExpression";
            //grid.FilteredDataSourcePropertyFormat = "{1} like '{0}'";

            //grid.FilterDataFields = "ListName";
            //grid.FilteredDataSourcePropertyName = "FilterExpression";
            //grid.FilteredDataSourcePropertyFormat = "{1} like '{0}'";

            //Provide the SPGridview with the DataSource
            grid.DataSourceID = "myDataSource";
            this.Controls.Add(grid);

            //grid.PageSize =10;
            //grid.AllowPaging = true;

            //Default Pagination - commented out due to not working
            //grid.PageIndexChanging += new GridViewPageEventHandler(grid_PageIndexChanging);
            //grid.PagerTemplate = null;

            //Bind the data to the grid
            grid.DataBind();

        }

        //private void GenerateColumns()
        //{

        //}

        //Used to deal with the PageIndexChange event
        void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grid.PageIndex = e.NewPageIndex;
            grid.DataBind();
        }

        //Used to deal with the ObjectCreated event
        void ds_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            myDataTable = new DataTableWrapper(dt);
            e.ObjectInstance = myDataTable;
        }

        //Pulls the data from lists which will be displayed
        public DataTable SelectData()
        {
            try
            {
                //Create a new instance of type DataRow
                DataRow row;

                //Loop through each website in the webcollection

                {
                    //Pull the lists from the site into a list collection
                    siteLists = thisWeb.Lists;
                    //Display only lists the current user has access to
                    siteLists.ListsForCurrentUser = true;

                    SPBasePermissions perms = SPBasePermissions.ViewListItems;

                    //Loop through each list within the list collection
                    foreach (SPList list in siteLists)
                    {
                        if (list.DoesUserHavePermissions(perms))
                        {
                            //If the list is an announcement list continue otherwise skip
                            if (list.BaseTemplate.ToString() == "Announcements")
                            {
                                //Exclude the lists stated from those whose data will be collected
                                if (list.Title.ToString() == "The Buzz" || list.Title.ToString() == "Test 2 list")
                                {
                                }
                                else
                                {
                                    //Create a item collection for each item within the current list
                                    SPListItemCollection listItem = list.Items;

                                    //Loop through each item within the item collection
                                    foreach (SPListItem item in listItem)
                                    {
                                        //Get the url of the current website
                                        string weburl = thisWeb.Url;
                                        //Gets the URL of the current item
                                        string dispurl = item.ContentType.DisplayFormUrl;
                                        dispurl = list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url;

                                        //Joins together the full URL for the current item into a single variable
                                        dispurl = string.Format("{0}/{1}?ID={2}", weburl, dispurl, item.ID);
                                        //Create a new in the datatable as an instance of row
                                        row = dt.Rows.Add();

                                        //Put the correct information and links into the correct column
                                        row["Title"] = "<a target=_blank href=\"" + dispurl + "\">" + item["Title"].ToString() + "</a>";
                                        row["Created"] = item["Created"].ToString();
                                        row["List"] = "<a target=_blank href=\"" + list.DefaultViewUrl + "\">" + list.Title + "</a>";
                                    }
                                }
                            }
                        }
                    }
                }
                //Return the completed DataTable
                return dt;
            }

            //Exception to catch any errors
            catch (Exception s)
            {
                return dt;
            }
        }
    }
}