All About SharePoint

Liedong(Ken) Zheng,SharePoint Leader at SIMPLOT

Archive for April, 2009

Importing Custom Active Directory attributes into User Profiles‏

Posted by ken zheng on April 28, 2009

Wonder if anyone across this problem and have any idea. We have created a couple attributes in AD but they are not showed in Data source field to map in Edit User Profile Property after I did full import.

I finally figure it out, first go to Search Setting and to see if it is in the Managed Properties. Also check to see if there are duplicated property in user profile. You may have to delete existing one and recreate in User Profile

Posted in Sharepoint | Tagged: | 3 Comments »

Automatic Login SharePoint for authenticated ADS user

Posted by ken zheng on April 28, 2009

1) Go to Internet Explorer options.
2) Add the SharePoint site to the Trusted Location.
3) Go to Custom Level and scroll to last option and change it Automatic logon with current username and password.
4) You may also do it for Intranet Zone if required.

Posted in Sharepoint | Tagged: | 2 Comments »

DocumentExplorer WebPart Extenstion

Posted by ken zheng on April 24, 2009

Atidan Document Explorer for SharePoint is a tree-view control that displays your Microsoft® SharePoint site’s document library structure and content in the familiar explorer type view.

Document libraries and associated contents are presented in an intuitive, collapsible, hierarchical format.

The is a great control, but the problem is it displays all document libraries under site. Because it is using User Control and no property to set. So I decide to extend the web part which allow user specify the document library.

24-04-2009-4-30-23-pm1

You can download the source from here.

Posted in Sharepoint | Tagged: , | Leave a Comment »

Incompatible Web Part markup detected. Use “.dwp web part XML instead of *.webpart web part xml

Posted by ken zheng on April 23, 2009

Check for [XmlRoot(Namespace = "ClassNameSpace")] in top of ur class definition, remove this statement and deploy again and see what happens. I got the same error mentioned and when I remove the above statement it works fine with me…

Posted in Sharepoint | Tagged: | 2 Comments »

Upgrade: Transition Your MCPD Enterprise Application Developer Skills to MCPD Enterprise Application Developer 3.5

Posted by ken zheng on April 16, 2009

The exams for this path will became available in recent months:

Exam 70-568: Upgrade: Transition Your MCPD Enterprise Application Developer Skills to MCPD Enterprise Application Developer 3.5, Part 1 (English)
Exam 70-569: Upgrade: Transition Your MCPD Enterprise Application Developer Skills to MCPD Enterprise Application Developer 3.5, Part 2 (English)

Posted in .Net | Tagged: , | Leave a Comment »

MOSS: SPListItem.Update() throws error Operation is not valid due to the current state of the object.

Posted by ken zheng on April 3, 2009

Problem:
When running SPListItem.Update commands inside SPSecurity.RunWithElevatedPrivileges block you get error: Operation is not valid due to the current state of the object.

Thoughts:
I will call this a workaround since I don’t know why it works and is this really how it should be done.

Workaround:
You must not call the SPListItem.Update inside the RunWithElevatedPrivileges block. Instead you should only instantiate the SPSite or SPWeb there and call Update afterwards, like this:

    private static string CreateSiteLink(SPWeb newSite, int groupId, string text)
    {
        string retVal = "";
        SPWeb elevatedRootWeb = null;

 try
  {
         SPSecurity.RunWithElevatedPrivileges(delegate()
         {
             using (SPSite elevatedSite = new SPSite(newSite.Site.ID))
             {
                 elevatedRootWeb = elevatedSite.RootWeb;
             }
         });

         SPList userInformation = elevatedRootWeb.Lists["User Information List"];

         if (userInformation != null)
         {
             try
             {
                 elevatedRootWeb.AllowUnsafeUpdates = true;
                 SPListItem item = userInformation.GetItemById(groupId); 

                 if (item["Notes"] != null)
                 {
                     item["Notes"] = string.Format(text, newSite.ServerRelativeUrl, newSite.Name);
                     item.Update();
                 }
                 elevatedRootWeb.AllowUnsafeUpdates = false;
             }
             catch (Exception e)
             {
                 retVal = " Site link for group " + groupId + " couldn't be created. (" + e.Message + ")";

             }
         }
         else
         {
             retVal = " Site link for group " + groupId + " couldn't be created. (User Information List not found)";
         }
 finally
 {
  elevatedRootWeb.Dispose();
 }

        return retVal;

    }


Posted in Sharepoint | Tagged: | 5 Comments »

Get Count from SharePoint List for InfoPath

Posted by ken zheng on April 3, 2009

I always be asked to get a Numberic Id for new infopath form. Instead of writing code in Form, I created a Web Service which will go to the SharePoint List, grab the number and increment by 1, then update the list. By doing that, you can set rule in your Form Submit Button without code required.
Below is the code

[WebMethod]
        public int GetAndIncrementCount(string ListUrl, string CountName)
        {
            int count = 0;

            SPWeb oSPWeb = null;
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite oSPSite = new SPSite(ListUrl))
                    {
                        oSPWeb = oSPSite.OpenWeb(ListUrl.Substring(ListUrl.IndexOf("/") + 1));
                    }
                });
                SPList oSPList = oSPWeb.GetList(ListUrl);

                if (oSPList != null)
                {
                    oSPWeb.AllowUnsafeUpdates = true;
                    SPListItemCollection items = oSPList.Items;
                    if (items.Count > 0)
                    {
                        SPListItem item = items[0];
                        count = int.Parse(item[CountName].ToString()) + 1;
                        item[CountName] = count;
                        item.Update();
                    }
                }
            }
            catch (Exception exception)
            {
                Log.WriteLogEvent(string.Format("An Error Occured In GetAndIncrementCount Method | Exception Message:{0} StackTrace: {1}", exception.Message, exception.StackTrace));
            }
            finally
            {
                oSPWeb.Dispose();
            }
            return count;
        }

Posted in Sharepoint | Tagged: , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 28 other followers