SharePointed

All things SharePoint

SharePointed header image 1

Event Handler ItemAdded returns null value

August 3rd, 2010 · No Comments

use the following code to get the item from ItemAdded Event.

 

Public Overrides Sub ItemAdded(ByVal properties As SPItemEventProperties)
Using spsSite As SPSite = New SPSite(properties.WebUrl)
Using spwWeb As SPWeb = spsSite.OpenWeb

Dim iSPl As SPListItem

If spwWeb.GetFile(properties.AfterUrl).Exists Then
iSPl = spwWeb.GetFile(properties.AfterUrl).Item

ElseIf spwWeb.GetFolder(properties.AfterUrl).Exists Then
iSPl = spwWeb.GetFolder(properties.AfterUrl).Item
End If

End Using
End Using
End Sub

→ No CommentsTags: SharePoint

You must restore to an empty web site

August 2nd, 2010 · No Comments

not following the directions caused me to get stuck on this one.

using SharePoint Designer, backup the site you want.

Site –>Administration –>Backup Web Site –> Select a location and save

create an empty site. (this is where i messed up)

to create an empty site do the following:

File –> Web Site –> General –> Empty Web Site –> Enter a site name

Then you will have a empty site to restore to.

Site –>Administration –>Restore Web Site –> Select your backup file –> Click Advanced  (make sure your new empty site name is there) –> Click OK

 

→ No CommentsTags: SharePoint

infopath object reference not set to an instance of an object

July 28th, 2010 · No Comments

using VSTA / codebehind i was getting a object reference not set to an instance of an object error.

turned out i fat-fingered some code.

make sure to check the fields you are referencing.

example:

bad -

Dim sAttchID As XPathNavigator = nav.SelectSingleNode(“/my:theAttachmentLibID“, Me.NamespaceManager)

good -

Dim sAttchID As XPathNavigator = nav.SelectSingleNode(“//my:theAttachmentLibID”, Me.NamespaceManager)

→ No CommentsTags: InfoPath

The Web application at SITE could not be found.

July 19th, 2010 · No Comments

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.

→ No CommentsTags: InfoPath

SharePoint The user does not exist or is not unique.

July 7th, 2010 · No Comments

Error

The user does not exist or is not unique.

To fix this error try changing the Group Owner.

Group –> Settings –> Group Settings –> Owner

 

→ No CommentsTags: SharePoint

InfoPath Hyplerlink opens as Read Only

June 25th, 2010 · No Comments

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

→ No CommentsTags: InfoPath · SharePoint

InfoPath Loop in a Repeating Table

June 14th, 2010 · No Comments

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

→ No CommentsTags: InfoPath

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

June 10th, 2010 · No Comments

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

Access is denied. (Exception from HRESULT: 0×80070005 (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)

→ No CommentsTags: SharePoint

Lookup field, Value does not fall within the expected range

June 2nd, 2010 · No Comments

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)

→ No CommentsTags: SharePoint

workflow to get the value of Lookup field

May 27th, 2010 · No Comments

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, “#”))

→ No CommentsTags: SharePoint