SPWeb.GetFolder 无法传入字符串值



尽管我的输入是string值,但我无法将字符串值传递到我的SPWeb.GetFolder中。

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)

您正在调用实例方法,就像静态方法一样。只需使用您在oWeb中拥有的SPWeb实例

if (oWeb.GetFolder(requestNo).Exists) 
静态类

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

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

if (oWeb.GetFolder(requestNo).Exists){
//Folder Exisits
}

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

SPWeb.GetFolder Method

因此,请改用instace oWeb:

oWeb.GetFolder(requestNo).Exists

最新更新