1

The following line works fine

SPList list = web.Lists["docLibName"];

The following line raises exception "value does not fall within the expected range"

SPFolder = web.Folders["docLibName"];
2

You can't get the folder of your list with only this name. you must pass the server relative URL.

To get the folder (rootfolder) of your list you can try :

SPList list = web.Lists["docLibName"];
SPFolder listFolder = list.RootFolder;
  • already tried this, worked but raise another exception when uploading a file to this folder, I always use web.folders and upload to it normally – SPDev Aug 26 '16 at 10:09
  • what kind of exception ? can you past your code ? – Nico Aug 26 '16 at 13:06
  • it's weekend here now, I'll let you know once hands on code next week, many thanks – SPDev Aug 26 '16 at 16:23
1

Here,

SPList is SharePoint Object of List types.

So this will worked for you

SPList list = web.Lists["docLibName"];

For getting folder you should use

SPFolder folder = list.GetFolder("Folder Name"); 

Let me know if you need some more assists.

  • by using the document library name with web.Folders["DocLibName"] is working with me in all other webparts , it gets the root folder of the docLib, this exception happened with only document libraries created through visual studio as items, other libraries created through the portal it works fine, I'll try your answer Monday :) , Thanks for the assist – SPDev Aug 26 '16 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.