私は、SharePoint 2010 と連携するアプリケーションに取り組んでおり、SP オブジェクトの 1 つ (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 に基づいて残りのフォルダーを作成する必要があります。新しく作成されたフォルダーを取得するときに問題が発生します。作成に使用したばかりの文字列で親フォルダーにインデックスを付けると、問題が発生するためです。