Submitting InfoPath Forms Anonymously

There seems to be a few posts floating around that claim that this can be done without any coding and some hacking of the SharePoint GUI e.g. http://www.sharepointblogs.com/ervingayle/archive/2006/10/13/enabling-anonymous-users-to-open-and-submit-data-via-infopath-forms-published-to-sharepoint-2007.aspx

In my experience, and based on the number of disgruntled commenters on the above post- most people’s experience, this is just not true. Modifying a form library’s anonymous access settings page URL from DOCLIB to LISTS will not actually allow anonymous users to “contribute” to the library and successfully SUBMIT a form. The only way I can think of get the job done would be to put some code behind the form (or in a list event handler) that saves the form to the library while running under an admin account. Here is a blog outlining how to do this although I haven’t yet tried this myself.

http://tim-sharepoint.blogspot.com/2008/10/sharepoint-anonymous-infopath-forms.html

Let me know if anyone gets this working as I would see this as a pretty common need.

 

Update: I did actually implement this solution myself but used the ViewSwitched event rather than the submit event as I was doing a few other things in there (like submit as email etc). My working code is below. I build up the form name using details from the form and store it in a hidden field called ‘name’.

public void FormEvents_ViewSwitched(object sender, ViewSwitchedEventArgs e)
        {

            XPathNavigator xPathNav = MainDataSource.CreateNavigator();
            string name = xPathNav.SelectSingleNode(“/my:MessageSection/my:hiddenName”, NamespaceManager).InnerXml;

            string url = “http://****/formlib/” + name + “.xml”;

            //———————————————‘

            //Convert underlying InfoPath XML to byte array’

            //———————————————‘

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            byte[] Data = encoding.GetBytes(xPathNav.OuterXml);

            try
            {

                //————————————————–‘

                //Create webclient, set credentials and upload data.’

                //————————————————–‘

                System.Net.WebClient webclient = new System.Net.WebClient();

                webclient.Credentials = new NetworkCredential(“****”, “****”, “****”);

                webclient.UploadData(url, “PUT”, Data);

            }

            catch (Exception ex)
            {

            }

        }

 

Advertisements

3 thoughts on “Submitting InfoPath Forms Anonymously

  1. Hi I know this is an older post but it seems that you and the person you linked to are the only ones that have the answer. I am trying to do exacltly what you mentioned but im trying to make the name based on the last name and time. I have it working right when allowing a real user to submit. this is the xpath query im using:
    concat(my:Applicant/my:name/my:lastName, xdDate:Now())
    .but Im not sure where to place in the code above. Do i place that in the “string URL=”? also when you add custom code it tells me i have to have an administrator approve it first to publish it to the site. but when i go through the “microsoft” steps to deploy it. it gets deployed to a folder called “form templates” but i need to place it in the form library i created . how can i do this

    I know that this is a alot to ask but i have been everywhere and it seems you are the only one on the net with the anser. any help will be much appreciated thanks.

  2. Hi I though i left a comment but it ddidnt show so im reposting just in case (sorry) I know this is an older post but it seems that you and the person at the link yuo mentioned are the only ones that have the answer. I am trying to do exacltly what you mentioned but im trying to make the name based on the last name and time. I have it working right when allowing a real user to submit. this is the xpath query im using:
    concat(my:Applicant/my:name/my:lastName, xdDate:Now())
    .but Im not sure where to place in the code above. Do i place that in the “string URL=”? also when you add custom code it tells me i have to have an administrator approve it first to publish it to the site. but when i go through the “microsoft” steps to deploy it. it gets deployed to a folder called “form templates” but i need to place it in the form library i created . how can i do this

    I know that this is a alot to ask but i have been everywhere and it seems you are the only one on the net with the anser. any help will be much appreciated thanks.

    • Well its good that you have the form submitting. Sorry for the late response, hopefully this helps you or someone else in a similar situation:
      I would suggest Googling Using InfoPath forms as a CONTENT TYPE. When a form requires Administrator Approval/Deployment it means you basically publish the xsn locally, and then have an Admin (someone with access to SharePoint Central Admin) upload it to the InfoPath Form Services area. You can then activate it against a site collection which adds it as an available content type. You can then enable content types on your form library and add it that way. That will make it show up on the new button of that lib but your Submit data connection in InfoPath, or in this case the code behind an event, is going to dictate where the form ends up on submission. Your line of code above should return you a string representing the submitted form’s unique name so all you need to do is add that to the string file path as a variable:

      string name = xPathNav.SelectSingleNode(“/my:MessageSection/my:hiddenName”, NamespaceManager).InnerXml;
      string url = “http://****/formlib/” + name + “.xml”;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s