Codebanking.com Bank your code here...
HOME REGISTER TECHNICAL Q&A GENERAL Q&A SUBMIT CODE SNIPPET LOGIN
 
Question:

How to check if a SPFile exists. Because spweb.GetFile method throws exception. value does not fall within the expected range.?



Answers Posted:

In CommonHelper internal class Microsoft has this code:

internal static SPFile GetExistingFile(SPWeb web, string serverRelativeUrl)
{
    SPFile file = null;
    bool exists = false;
    try
    {
        file = web.GetFile(serverRelativeUrl);
        if (file != null)
        {
            exists = file.Exists;
        }
    }
    catch (ArgumentException)
    {
        exists = false;
    }
    if (!exists)
    {
        return null;
    }
    return file;
}


Username:sharepointer  Posted Date:2/15/2010

Please login to leave a reply
 
 2010 codebanking.com      contactus@codebanking.com