The Web application at SITE could not be found.

Error:

The Web application at http://site/Forms/AllItems.aspx could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)

at Microsoft.SharePoint.SPSite..ctor(String requestUrl)

at MOVE.FormCode.CTRL1_5_Clicked(Object sender, ClickedEventArgs e)

at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)

at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

/error

I spent the better part of week working on this error. The problem was related to my trying to use InfoPath Forms when I should have been using Browser enabled forms. Once I published the  form and uploaded into to Central Administration I was able to use Managed Code.

InfoPath Hyplerlink opens as Read Only

Recently ran into an issue where you place a hyperlink on a InfoPath form, user clicks the link, the item opens as read-only, no Edit Document option.

The fix is to do a regedit to allow for editing of the document.

example

[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\Internet]
“OpenDocumentsReadWriteWhileBrowsing”=dword:00000001

in the Common\Internet folder you would create a new DWORD value OpenDocumentsReadWriteWhileBrowsing and assign it a Value of 1.

http://support.microsoft.com/kb/870853

InfoPath Loop in a Repeating Table

This will help you loop through a Repeating Table in InfoPath.  group2 is the name of my Repeating Table. sFunction is a function I use to check if a value has been updated in a SharePoint Library or List. If the value returned from the function does not match what I have in my drop down list, I update it with the function value.

 

Dim rootX As XPathNavigator = MainDataSource.CreateNavigator
Dim rowX As XPathNodeIterator = rootX.Select(“/my:myFields/my:group1/my:group2”, NamespaceManager)

While rowX.MoveNext
Dim sStatus As String = rowX.Current.SelectSingleNode(“my:field4”, NamespaceManager).Value
Dim sI As String = rowX.Current.SelectSingleNode(“my:field2”, NamespaceManager).Value
Dim sS As String = sFunction(sI)

If sStatus <> sS Then
rowX.Current.SelectSingleNode(“my:field4”, NamespaceManager).SetValue(sS)
End If
End While

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Trying to use an Event Handler in SharePoint 2007 my test user was seeing this error:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

The error was being triggered by an ItemUpdated or ItemAdded event.

fix:

Public Overrides Sub ItemUpdated(ByVal properties As SPItemEventProperties)
SPSecurity.RunWithElevatedPrivileges(AddressOf mCode)
End Sub

Private Sub mCode()
Dim eFire As hEventFiring = New hEventFiring
Using spsSite As SPSite = New SPSite(sPi.WebUrl)
Using spwWeb As SPWeb = spsSite.OpenWeb

Dim iSPl As SPListItem = spwWeb.Lists(sPi.ListId).GetItemById(sPi.ListItem.ID)

Try

eFire.dEventFire()
Dim roleAssig As New SPRoleAssignment(spwWeb.SiteGroups(mGroup))
roleAssig.RoleDefinitionBindings.Add(spwWeb.RoleDefinitions(“Contribute”))

If iSPl.HasUniqueRoleAssignments = False Then
iSPl.BreakRoleInheritance(True)
End If

For Each spra As SPRoleAssignment In iSPl.RoleAssignments
spra.RoleDefinitionBindings.RemoveAll()
spra.Update()
Next

iSPl.RoleAssignments.Add(roleAssig)
iSPl(“CommentField”) = mGroup
iSPl.Update()
eFire.eEventFire()

Catch ex As Exception
iSPl(“CommentField”) = ex.Message.ToString
iSPl.Update()
Finally
End Try
End Using
End Using
End Sub

Class hEventFiring
Inherits SPItemEventReceiver

Public Sub dEventFire()
Me.DisableEventFiring()
End Sub

Public Sub eEventFire()
Me.EnableEventFiring()
End Sub

End Class

————

What I’m doing:

1. Use RunWithElevatedPrivileges to call the code that updates the item.

2. Disable event firing with eFire.dEventFire

3. Break role inheritance using BreakRoleInheritance

4. Assign permissions using iSPl.RoleAssignments.Add(roleAssig)

5. Enable event firing eFire.eEventFire.

The key to this working is Dim iSPl As SPListItem = spwWeb.Lists(sPi.ListId).GetItemById(sPi.ListItem.ID)

Lookup field, Value does not fall within the expected range

Using a Workflow to update a Lookup field in a Library in SharePoint I ran into this error:

Value does not fall within the expected range

I had no issue obtaining the value of a value from the Lookup field.

Dim sString As New SPFieldLookupValue(DirectCast(wfP.Item(“Field-R”), String))
sString= sString.LookupValue

BUT, what I failed to pay attention to was the hyphen in the field name.

Using the U2U CAML Query Builder I discovered my problem.

The real field name was Field_x002d_L

wfP.Item(“Field_x002d_L”) = New SPFieldLookupValue(1, “Value”)

…. Make sure you are updating the correct field name.

code:

spLibItem.Item(sField) = New SPFieldLookupValue(sValueID, sValue)

workflow to get the value of Lookup field

In Visual Studio 2008.

I was trying to get the value of Lookup field in a Document Library and would see a result like this:

sLookup = workflowProperties.Item(“FieldName”).ToString

but it returns: 9;#FieldValue

This is how I went about fixing the string (if there is a better way, please tell me!)

sLookup = Right(workflowProperties.Item(“FieldName”).ToString, Len(workflowProperties.Item(“FieldName”).ToString) – InStr(workflowProperties.Item(“FieldName”).ToString, “#”))

InfoPath Get Name Field from Data Connection and more

Using a combo of a View and Data Connection we will be able to grab ALL of the fields from a List or Library.

1. Open a Text file so you can paste stuff into it.

2. Open the site you want to gather the data from.

3. Navigate to Site Action > Site Settings

4. Under General Settings click on Audience targeting settings. With this page open look at the URL. Starting with the word List, copy everything to the right.

Example: List={515dc5f2-88b9-4f91-80a3-4e133f25d069}

5. Using your Text file, first paste your new List GUID onto the file, next page this string on a another line _vti_bin/owssvr.dll?Cmd=Display&List={GUID}&XMLDATA=TRUE&noredirect=true

6. Now, going back to your List GUID copy everything between the {} brackets. Then paste it into the {GUID} string got from my site, replacing GUID.

Example: _vti_bin/owssvr.dll?Cmd=Display&List={515dc5f2-88b9-4f91-80a3-4e133f25d069}&XMLDATA=TRUE&noredirect=true

7. Go back to your site and paste the long string you just create into the sites URL (see example below for more detail).

Example: http://SiteName/SubSiteName/_vti_bin/owssvr.dll?Cmd=Display&List={515dc5f2-88b9-4f91-80a3-4e133f25d069}&XMLDATA=TRUE&noredirect=true

8. You should now see a page full of XML pertaining to your List or Library.

To take this to the next level you can create a View to narrow down the columns returned in the XML.

1. Create a new View with the fields you want.

2. Edit your newly created view. With the Edit View page open scroll down to Mobile section. Looking at the URL under “Web address for this mobile view:”, grab all the letters and numbers after View=

3. Open this site (http://meyerweb.com/eric/tools/dencoder/) and paste that string into the URL Decoder/Encoder box and click the Decode button.

4. You should now have a cleaner GUID.

5. Paste that new GUID into your Text file.

6. We will now want to join the new GUID with our existing URL string (see below for example).

Example: http://SiteName/SubSiteName/_vti_bin/owssvr.dll?Cmd=Display&List={515dc5f2-88b9-4f91-80a3-4e133f25d069}&XMLDATA=TRUE&noredirect=true&View={8478D19F-831D-45CB-8F24-A481444C5418}

7. You should now see different results than the first URL string we created.

Now the good stuff! Using the URL you can create XML Data Connections in InfoPath and be able to view columns that were once unavailable.

InfoPath get current username

If you are looking for a way to capture the login user name in InfoPath try this.

Dim sUserName As String = System.Enviroment.UserName

If you want to capture user name from SharePoint try this:

http://blogs.microsoft.co.il/blogs/itaysk/archive/2007/04/05/InfoPath-_2D00_-Get-the-current-user-without-writing-code.aspx

Update the Assigned To field using a Visual Studio 2008 Workflow

After spending way too many hours messing with this, I got it to work. I was trying to update the Assigned To in a Form Library (also works in a Document Library) using a Workflow in Visual Studio 2008. SharePoint being SharePoint, nothing is ever easy.

In the VS I created a Sequential Workflow. Then I added a Code activity (codeActivity1) to the design. After that, double click codeActivity1 in the design window.

Create the Public variable wfP:

Public wfP As SPWorkflowActivationProperties = New Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties

Then add the following code to your codeActivity1 module.

Dim site As SPWeb = New SPSite(wfP.WebUrl).OpenWeb()

Dim list As SPList = site.Lists(wfP.List.Title)

Dim listItem As SPListItem = wfP.Item

listItem(“Assigned To”) = site.Groups(“gLeads”)

listItem.Update()

It should look like this when you are done:

Private Sub codeMoveToLead_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim site As SPWeb = New SPSite(wfP.WebUrl).OpenWeb()

Dim list As SPList = site.Lists(wfP.List.Title)

Dim listItem As SPListItem = wfP.Item

listItem(“Assigned To”) = site.Groups(“gLeads”)

listItem.Update()

End Sub

Trying to set the .AssignedTo never worked for me.