【发布时间】:2013-07-03 15:12:18
【问题描述】:
我正在开发一个与 SharePoint 2010 交互的应用程序,其中一个 SP 对象(如果您好奇的话,SPFolder.Subfolders[index])需要一个字符串来索引它返回的项目。问题是我需要向它传递一个字符串变量,但它只接受文字。有没有办法为此目的将变量转换为文字?如果问题不够清楚,请参见下图:
SPFolder folder = rootFolder.SubFolders["Literal folder name"]; // This properly searches the collection (which has already been defined) and returns the folder with the name specified by the literal.
string newFolder = "Literal folder name"; // In this case I'm trying to pass this string as the index.
SPFolder folder = rootFolder.SubFolders[newFolder]; // This is where it throws a "Value does not fall within the expected range" exception when the string is referenced.
如果上下文有帮助,应用程序将获取一组文件夹名称并在库中的特定级别创建它们,然后循环遍历新文件夹以在其中构建复杂的文件夹结构。为此,我必须创建一个文件夹,获取其 url,然后基于该 url 创建其余文件夹。获取新创建的文件夹是我遇到麻烦的地方,因为用我刚刚用来创建它的字符串索引父文件夹是它变得疯狂的地方。
【问题讨论】:
-
你能做吗 string newFolder = @"新文件夹名"; ?
-
只是试了一下,没有运气:/
标签: c# string sharepoint indexing string-literals