IsReadOnly Doesn't Always Work for Attached Forms - Patrick Halstead
in

InfoPath Dev

Patrick Halstead

IsReadOnly Doesn't Always Work for Attached Forms

If your form contains logic that checks to see if it is read-only (thisXDocument.IsReadOnly), there is an issue with Outlook where InfoPath will report false positives depending on your Outlook cache settings.

Most of the time, it doesn't make sense to call IsReadOnly for an attachment, so the workaround would be to determine if your code is an attachment or not and only use IsReadOnly when it is opened from a shared website or local folder.

Here's some C# code to determine if your form is an attachment or not:

private string getFormPath()
{
    string sFormUri = thisXDocument.URI;
    int iPosition = sFormUri.LastIndexOf("/");

    // if path is outlook file cache, this will return ""
    if (-1 != iPosition)
        // Just return path
        return sFormUri.Substring(0, iPosition + 1);
    else
        return "";
}

private string getSharePointFolder()
{
    string sUri = thisXDocument.Solution.URI;
    int iPosition = sUri.LastIndexOf("/Forms/");
 
    return -1 != iPosition ? sUri.Substring(0, iPosition + 1) : "";
}
 
_fOpenedLocally = (0 != string.Compare(getFormPath(), getSharePointFolder()));

Published Jul 06 2004, 05:24 PM by Patrick Halstead
Filed under:

Comments

No Comments

About Patrick Halstead

Hello! I am the founder of Qdabra Software, a small bootstrap software company focused on electronic forms for customers of all stripes. We help organizations design and implement solutions using off-the-shelf technologies such as Office 365, SharePoint and InfoPath. We help you build form solutions in the cloud or on premises. My hobbies include running, hiking, independent film, and Japanese culture.
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.