我的工作是與SharePoint 2010接口的應用程序,而SP的一個對象(SPFolder.Subfolders[index]
如果你好奇)需要一個字符串來索引它返回的項目。問題是我需要傳遞一個字符串變量,但它只接受文字。有沒有一種方法可以將變量轉換爲文字?如果問題是不夠清楚,見下圖:C# - 把一個字符串變量轉換爲字符串字面
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創建剩餘的文件夾。抓取新創建的文件夾是我遇到麻煩的地方,因爲用我剛剛用來創建它的字符串索引父文件夾就是它發瘋的地方。
你可以做字符串newFolder = @「新建文件夾名稱」; ? – Sherlock
只是給了它一個鏡頭,沒有運氣:/ – thanby