Jan 6

To check if a user is in a SharePoint Group (which also checks if the user is in an AD Group within that SharePoint group), use the following code:

 using System.DirectoryServices.AccountManagement;

        public bool IsUserInSharePointGroup(string webUrl, string groupName, string username)
        {
            bool userIsInGroup = false;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                try
                {
                    SPWeb web = SPContext.Current.Web;

                    // Find the group
                    SPGroup group = web.SiteGroups[groupName];
                    string upperCaseUserName = username.ToUpper();

                    foreach (SPUser user in group.Users)
                    {
                        // Check if this is an AD Group
                        if (!user.IsDomainGroup)
                        {
                            // Verify if the user name matches the user name in group
                            if (user.LoginName.ToUpper().Equals(upperCaseUserName))
                            {
                                userIsInGroup = true;
                                return;
                            }
                        }
                        else
                        {
                            // this is an AD group
                            var pc = new PrincipalContext(ContextType.Domain);
                            var myuser = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, username);
                            var mygroup = GroupPrincipal.FindByIdentity(pc, user.LoginName);
                            if (myuser.IsMemberOf(mygroup))
                            {
                                userIsInGroup = true;
                                return;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Trace error
                }
            });
            return userIsInGroup;
        }

Nov 24

If you try to upload an aspx file with inline code in it, SharePoint will give you an error. To execute that inline code, the web.config file needs to be modified to allow execution of that particular aspx file as follows:

      <PageParserPaths>
        <PageParserPath VirtualPath="/path/to/script.aspx" CompilationMode="Always" AllowServerSideScript="true" />
      </PageParserPaths>

This should be placed between the <SafeMode> </SafeMode> tags which is within the <SharePoint> </SharePoint> tags.

Note that you can use the * character if you would like the entire library to be able to execute inline code.

Sep 2

When browsing a SharePoint site on the iPad, you might not be able to scroll up and down the site. To be able to do that, you need to use 2 fingers instead of 1 finger. It is not intuitive and most people will therefore not be able to navigate your SharePoint 2010 site on their iPads.

To allow navigation on iPads with single finger scrolling, the style sheet needs to be slightly modified with the following styles added.

<style>
@media (max-device-width: 768px){
    body.v4master {
        height: auto;
        width: auto;
        overflow: auto!important;
    }
    body #aspnetForm {
        height: auto;
    }
    body #s4-workspace {
        overflow: auto!important;
        height: auto!important;
        width: auto!important;
    }
    body #s4-bodyContainer:after {
        content: ".";
        display: block;
        clear: both;
        height: 0;
        line-height: 0;
        font-size: 0;    }
    #s4-titlerow {
        width: auto!important;
    }
}
</style>

It can be added straight into your master pages custom style sheets so single finger scrolling is available throughout the entire site, or alternatively, if you want it enabled for just one page, then add the CSS to a Content Editor web part on the page.

Aug 24

Here's a useful post on how to map a SharePoint URL with PictureURL in user profile properties.

http://spmat.blogspot.com/2010/10/how-to-map-sharepoint-2010-pictureurl.html

Here's one to map an extension attribute in AD to the PictureURL in user profile properties.

http://goodbadtechnology.blogspot.com/2010/05/setting-up-pictureurl-user-profile.html

Unfortunately, as you can see from these examples, it's not exactly a straightforward task.

Jul 28
Editing InfoPath 2010 xml with C#
Posted by Wei in C#, InfoPath, SharePoint on 07 28th, 2011| | No Comments »

Here's a code snippet to edit nodes in an existing InfoPath 2010 Xml document from a selected Form Library in SharePoint 2010:

 SPWeb mySite = SPContext.Current.Web;
 SPList oList = mySite.Lists["FormLibraryName"];
 SPQuery oQuery = new SPQuery();
 oQuery.Query = "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>TargetFile.xml</Value></Eq></Where>";
 SPListItemCollection listItems = oList.GetItems(oQuery);

 if (listItems.Count > 0)
 {
  SPListItem item = listItems[0];

  MemoryStream oMemoryStream = new MemoryStream(item.File.OpenBinary());
  XmlTextReader oReader = new XmlTextReader(oMemoryStream);

  XmlDocument oDoc = new XmlDocument();
  oDoc.Load(oReader);

  oReader.Close();
  oMemoryStream.Close();

  XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(oDoc.NameTable);
  nameSpaceManager.AddNamespace("my", oDoc.DocumentElement.NamespaceURI);

  oDoc.DocumentElement.SelectSingleNode("my:NodeToUpdate", nameSpaceManager).InnerText = "Update text";
  oDoc.DocumentElement.SelectSingleNode("my:Node/my:SubNode", nameSpaceManager).InnerText = "Update text";

  mySite.AllowUnsafeUpdates = true;

  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
  SPFile oSPFile = mySite.Folders[mwp.FormLibraryName].Files.Add(item.File.Name, (encoding.GetBytes(oDoc.OuterXml)), true);
 }

« Previous Entries