Wasn’t the point of sharepoint to make your life easier?

okay I give up 🙂

You know it’s bad when I do this in my blog. I have tried the newsgroups and googled myself to death and the clock is ticking…

I have been having a problem with getting file objects with SPWeb.GetFile for about a day. No matter what file name/path I pass into GetFile(), I get strange results: SPFile.Exists=false and many operations such as SPFile.Checkout fail. However, SPFile.OpenBinary works just fine. I have had this happen coding this directly into an ASP.NET page as well as when buildling a web service. All of the documentation says “this is the way to do it” but I find nothing that says “but if it doesn’t work…” – you know like when you are working with Beta software. I can’t imagine I am the first person who has had this problem!

To dig further into the problem, I built a test where I iterate through the webs and folders and then files in the folder, I am then taking a string representing the file (either ServerRelativeURL or some flavor of it) and creating a new file from it. Then if I attempt to SPWeb.GetFile(filepath) using the various paths and you can see that still, I consistently get SPFile.Exists=false even when I know the file is there.

Having iterated to a file in a folder with “For Each fileA As SPFile In folder.Files”

fileA.exist : True
fileA.Name: “ABR.XLS”
fileA.URL: “Shared Documents/ABR.XLS”
fileA.ServerRelativeURL: “/mysite/nn/Shared Documents/ABR.XLS”

create new files with spweb.getfile and test file.exists
(ServerRelativeURL) File Exists? ( /mysite/nn/Shared Documents/ABR.XLS ) False
File Exists?? ( mysite/nn/Shared Documents/ABR.XLS ) False
File Exists? ( nn/Shared Documents/ABR.XLS ) False

So, what gives here?



www.acehaid.org

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.