Monday, April 12, 2010

How to show the Filter Toolbar always on for DataView

Sometimes we need to customize DataView Webparts (DVWP) in the Sharepoint Designer. there are to many cases, one of these cases is always showing the Filter Toolbar. to do this:
1. Go to the <xsl:template name="dvt_1.toolbar"> template
2. at the end of this template you find a if statment
<xsl:if test="$dvt_adhocmode = 'filter'" ddwrt:cf_ignore="1"> </xsl:if>
delete this statement and that is all

Mohammed AlShafe'i

Tuesday, February 23, 2010

Ajax second postback not working in Sharepoint in UpdatePanel

We have one problem in work, we spend with that a day without any solution, all we found cause some another problem. This is what help us when the page is not making second postback in update panel when the first postback is fired by element in UpdatePanel and refresh only update panels on the page.

Taken from Mike Ammerlaan's Blog

Windows SharePoint Services JavaScript has a “form onSubmit wrapper” which is used to override the default form action. This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios. However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.

To do this, you may need to register a client startup script which disables this workaround, in addition to resetting the default form action:

<script type='text/javascript'>
_spOriginalFormAction = document.forms[0].action;

This script may be directly embedded in the page, or could be emitted by a control that uses the UpdatePanel. The following is an example of a very simple method which will fix this issue:

 Private Sub EnsureUpdatePanelFixups()
        If Me.Page.Form IsNot Nothing Then
            Dim formOnSubmitAtt As String = Me.Page.Form.Attributes("onsubmit")
            If formOnSubmitAtt = "return _spFormOnSubmitWrapper();" Then
                Me.Page.Form.Attributes("onsubmit") = "_spFormOnSubmitWrapper();"
            End If
        End If
        ScriptManager.RegisterStartupScript(Me, GetType(UpdatePanel), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", True)
    End Sub

Mohammed AlShafe'i

Wednesday, February 10, 2010

adding users to sharepoint group programmatically

When I was working on form authunticated portal site in sharepoint 2007, I need
to add users to sharepoint group programmatically, all what we need is the following:

Dim membershipUser As MembershipUser
Dim membershipStatus As MembershipCreateStatus
membershipUser = Membership.CreateUser( pUsername, pPassword, pEmail, pSecurityQuestion,
pSecurityAnswer, True,membershipStatus)

' after creating user, call  _addUserToGroup() method using SPSecurity.RunWithElevatedPrivileges(AddressOf  )

SPSecurity.RunWithElevatedPrivileges(AddressOf _addUserToGroup)

Private Sub _addUserToGroup()
        Dim site As New SPSite("http://localhost:1200")
        Dim web As SPWeb = site.OpenWeb()
        Dim spUser As SPUser
        web.AllowUnsafeUpdates = True
       ' call EnsureUser method and pass user name with Membership Provider Name  like the following row
        spUser = web.EnsureUser("AspNetSqlMembershipProvider:" + txtUsername.Text)
End Sub
Thats all
Mohammad AlShafe'i

Thursday, January 7, 2010

Error: A file or folder name contains an invalid character

When I was trying to deploy a ListDefinition using CTP release of VSeWSS 1.3 for Visual Studio 2008, I got the following error:

 A file or folder name contains an invalid character

This message means: One or more file contains invalid character, but all my soultion files are not contain any invalid character, so after I search I found the Name of ListDefinition contains an invalid character on ListDefinition.xml file, to solve this error just remove this character

    Special character are not allowed in the value of Name in the ListTemplete inside the XML File because when the user trying to deploy the solution. The system will generate a folder with this value, and you know the speacial characters are not allowed in folder or file name
Mohammad AlShafe'i

ERROR: Unable to load one or more of the requested types

When I was trying to deploy a web part using CTP release of VSeWSS 1.3 for Visual Studio 2008, I got the following error:
VSeWSS Service Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

The solution:
I've found the following steps solving this error, here are the steps:
1. Add the All referenced assemblies to the GAC
2. Restart IIS
3. Clean the project in Visual Studio
4. Redeploy your solution again, Then everything will work.

Mohammad AlShafe'i