Error: Value does not fall within expected range
Code Sample:
SPFileCollection files = currentlist.RootFolder.SubFolders[curfileitem.Url.Substring(0, curfileitem.Url.LastIndexOf('/'))].Files;
I found that if I have hierarchy of folder then the above code will throw an error.
Solution:
Through google I found out a new method to get files collection. Here is the code sample:
SPFolder folder = properties.Web.GetFolder(curfileitem.Url.Substring(0, curfileitem.Url.LastIndexOf('/')));
SPFileCollection files = folder.Files;
Make sure you provide full path of your folder. i.e. your web path / doc library title / folder path.
No comments:
Post a Comment