2

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,   
                webUrl);

        SPFile file = web.GetFile(fullpath);

What can the cause be?

1 Answer 1

2

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

13
  • there's no method CombineUrl
    – ezzaam
    Commented Aug 10, 2014 at 12:52
  • Sorry ConcatUrls! But I think you will still have problems working with layouts files Commented Aug 10, 2014 at 14:00
  • unfortunately still the same error
    – ezzaam
    Commented Aug 11, 2014 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 Commented Aug 11, 2014 at 9:03
  • to clarify more please
    – ezzaam
    Commented Aug 11, 2014 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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