I suffer from a problem of

value does not fall within the expected range

from below code.

         string webUrl = "/_layouts/15/wfcourrierdep/ArticlesList.aspx";
                string fullpath = SPUtility.GetFullUrl(SPContext.Current.Site,   

        SPFile file = web.GetFile(fullpath);

What can the cause be?


It could be a problem of SPUtility.GetFullUrl not being able to work with layouts URLs (since they are shared between all sites in your farm, and not site specific)

Try if

string fullPath=SPUtility.ConcatUrls(SPContext.Current.Site.Url, webUrl)

works better.

Don't really now why you are trying to get a file from the virtual directory layouts though! Check for example here of how to read from this directory: How to read a file from a folder in _Layouts?

If possible, you should consider to deploy the file into a library in SharePoint instead. That way you could do CRUD on it just like any other file in SharePoint

| improve this answer | |
  • there's no method CombineUrl – ezzaam Aug 10 '14 at 12:52
  • Sorry ConcatUrls! But I think you will still have problems working with layouts files – Robert Lindgren Aug 10 '14 at 14:00
  • unfortunately still the same error – ezzaam Aug 11 '14 at 8:36
  • As I said, I think the problem is that you can not use GetFile for files in the layouts folder! Check the link in my post for how to work with those files like you would in regular asp.net – Robert Lindgren Aug 11 '14 at 9:03
  • to clarify more please – ezzaam Aug 11 '14 at 9:04

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.