0

SPWeb.GetFolder尽管我的输入是一个值,但我无法将字符串值传递给我string

private static void UploadEmlToSp(string sharePointSite, string sharePointDocLib, string emlFullPath, string requestNo)
{
    using (SPSite oSite = new SPSite(sharePointSite))
    {
        using (SPWeb oWeb = oSite.OpenWeb())
        {
            if (!System.IO.File.Exists(emlFullPath))
                throw new FileNotFoundException("File not found.", emlFullPath);

            SPFolder myLibrary = oWeb.Folders[sharePointDocLib];

            if (SPWeb.GetFolder(requestNo).Exists) <--errored
            {
                //Folder Exisits
            }

我可以知道我错过了什么吗?下面是错误信息。

An object reference is required for the non-static field, method, or property SPWeb.GetFolder(string)

4

3 回答 3

0

您正在调用实例方法,例如静态方法。只需使用SPWeb您的实例oWeb

if (oWeb.GetFolder(requestNo).Exists) 

静态类和静态类成员(C# 编程指南)

于 2019-08-26T05:02:35.970 回答
0

使用您创建的对象 oWeb 的实例来获取该方法。代码应该写成如下

 if (oWeb.GetFolder(requestNo).Exists){
         //Folder Exisits
 }
于 2019-08-26T08:24:46.720 回答
0

SPWeb.GetFolder 不是官方文档特定的静态方法:

SPWeb.GetFolder 方法

因此,请改用实例 oWeb:

oWeb.GetFolder(requestNo).Exists
于 2019-08-26T09:21:17.130 回答