繁体   English   中英

名称 '' 在当前上下文中不存在"

[英]The name '' does not exist in the current context"

我正在尝试使用/构建 API 来提取 SharePoint 日历。 我在 GitHub 中找到了让我入门的代码。 当我开始尝试使用找到的代码时,出现错误 The name 'myUT.SiteUrl' does not exist in the current context"。我在 stackoverflow 中查看了许多其他问题,但似乎找不到解决方案。

using SpRestUtility;

namespace SP_REST_UTILITY
{


    class Class1
    {
        SpRestUtilities myUT = new SpRestUtilities();

        myUT.SiteUrl = "https://yoursharepoint.com/yoursite";
        myUT.Credentials = private new NetworkCredential("USERNAME", "PASSWORD");

        SpList listA = myUT.Get_SpList_By_Title("LISTNAME");
    }
}


//  Found code snip

namespace SpRestUtility
{
    public class SpRestUtilities
    {
        #region Properties
        private string _siteUrl;
        public string SiteUrl
        {
            get
            {
                return _siteUrl;
            }
            set
            {
                // Fix given SiteUrl
                _siteUrl = (!value.EndsWith("/")) ? value += "/" : value;
            }
        }
        public NetworkCredential Credentials { get; set; }

命名空间不同你应该设置相同的命名空间或添加第二个命名空间作为导入到主命名空间。

有人发帖然后删了。 但这是答案。

namespace SpRestUtility

{

class Class1
{
    SpRestUtilities myUT = new SpRestUtilities();

    Class1() {

        myUT.SiteUrl = "https://yoursharepoint.com/yoursite";
        myUT.Credentials = new NetworkCredential("USERNAME", "PASSWORD");

    SpList listA = myUT.Get_SpList_By_Title("LISTNAME");
}
}

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM