Vanou’s Blog

After a SharePoint migration this error can occur if you forget the final step

stsadm -o copyappbincontent

Some of your custom solutions may depend on it because of some user controls or pages

No need to change the web.config for that

And last but not least to ensure you have access to your site check the site collection administrators in the Central Admin

Lets say you want to select a picture from you SP site using AssetUrlSelector object, and assign this new image to an existing asp image object

This is when you use the ClientCallback property

 private string GetReturnScript()
        {
            string script = string.Empty;

            script = "function(newAssetUrl, newAssetText, configObject, returnValue)";
            script += "{";
            script += string.Format("document.getElementById('{0}').src=newAssetUrl;", ImageContactPictureEdit.ClientID);
            script += "}";
            return script;
        }

Assign this function to your AssetUrl control like this:

AssetUrlSelectorContactPictureEdit.ClientCallback = GetReturnScript();

When the dialog closes, the image will be displayed on your page

If Central Adminsitration is unavailable after a deployment (all webapps deployment for exemple) just restore the previous version of the web.config and it should work.

It may be caused by some missing assemblies or component needed by the wsp

When you work on a developpement machine, you may need to create several web application or extend existing ones, using  host header (http://company.domain.local, http://extranet.domain.local). Even if you modify the hosts file, you cannot access the sites, either you get 401 or 404 page or you are prompt with the login dialog 2, 3 times before seeing a blank page.

Apparently this is a known issue, you can find the solution in the Microsoft KB896861. To get everything work I just created  a new .reg file and put this:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"DisableLoopbackCheck"=dword:00000001

If you get this error, you might likely have WebApplication and/or ApplicationPool issues. When I got this problem, I thought I would have to start all over again my SharePoint install.

So I launched SPManager2010 and it shown me “Object not set of an instance of an object” error! I opened the source and then debug the application, and I found what was the cause of my trouble.

The property ApplicationPool of one of my webapplication was null !!!

I’ve been scratching my head for a couple of hours when I realised what happened:

I have 5 webapps

  • SharePoint – 8888 (TFS)
  • SharePoint – 6666 (PWA)
  • SharePoint – 7777 (ReportServer)
  • SharePoint – 8090
  • SharePoint – 80

they where on 2 different application pool, so I changed all the webapps to use the same application pool, using powershell simply like:

$webapp8090 = SP-GetWebApplication http://moss-server:8090

$webapp8888 =  SP-GetWebApplication http://moss-server:8888

$webapp8888.ApplicationPool = $webapp8090.ApplicationPool

I have been messing up with the 8090 webapp because of my training and I wanted to delete it. that’s when the problem started, central admin won’t let me create or extend a webapp anymore.

I guess that the reason why is because when I deleted the SharePoint 8090 webapp  I deleted the reference I made to its application pool that I used for the Sharepoint 8888 webapp.

I restored the application pool property of my webapp using the same method with powershell and I got the central admin working.

for those who are coding in C#, in your strings manipulations use 

Environment.NewLine instead of “\n”, it works better and it’s easier to maintain.

Tags: ,

Few days ago I add to copy Alerts and QuickLinks from a UserProfile to another in SPS 2003. I managed to create the functions, it seems easy at first, but the one thing I forgot is that I was on .Net Framework 1.1 withVisual Studio 2003!! argh! intellisense sucks compare to VS2008 or 2005

Copy QuickLinks:

/// </summary>

/// copy QuickLinks to another userprofile

/// copy if not exist, update otherwise

/// </summary>

/// <param name=”userProfile”>UserProfile that will contain the links</param>

/// <param name=”links”>Links to copy</param>

public static void CopyQuickLinks(UserProfile userProfile,QuickLinkManager links)

{

foreach(QuickLink link in links)

{

QuickLink newLink = null;

newLink= userProfile.QuickLinks.Add(link.Title,link.URL,link.Group,link.Public);

newLink.ContentClass= link.ContentClass;

newLink.Commit();

}

}

Copy Alerts:

///<summary>

/// copy a list of a alert to another userprofile

/// copy if not exist, update otherwise

/// </summary>

/// <param name=”userProfile”>UserProfile that will contain the alerts</param>

/// <param name=”alerts”>alerts to create for user</param>

public static void CopyAlerts(UserProfile
userProfile,ArrayList alerts)

{

foreach(Microsoft.SharePoint.Portal.Alerts.Alert alert in
alerts)

{

Microsoft.SharePoint.Portal.Alerts.Alert newAlert = null;

if(userProfile.Alerts[alert.Name] == null)

{

newAlert=
userProfile.Alerts.CreateAlert();

newAlert.Type = alert.Type;

foreach(Microsoft.SharePoint.Portal.Alerts.DeliveryChannelSettings channelSettings in alert.DeliveryChannels)

{

newAlert.DeliveryChannels.Add(channelSettings);

}

}

else

{

newAlert =
userProfile.Alerts[alert.Name];

}

newAlert.Name = alert.Name;

newAlert.ObjectDisplayName =
alert.ObjectDisplayName;

newAlert.ObjectID = alert.ObjectID;

newAlert.ObjectUrl = alert.ObjectUrl;

newAlert.Query = alert.Query;

newAlert.ConditionText =
alert.ConditionText;

newAlert.QueryLocale =
alert.QueryLocale;

newAlert.Commit();

if(alert.Active)

newAlert.Activate();

else

newAlert.Deactivate();

}

}

Since System.Collections is pretty limited in .net 1.1 I used an ArrayList of Alerts, which contains the alerts of the user to copy from

   
/// <summary>

/// Returns a StringCollection object from a SPField object of type SPFieldChoice from the web.Fields   

/// </summary> 

/// <param name=”fieldName”>Field name needed to retrieve the list of choice of the SPFieldChoice object</param>   

/// <returns></returns>

   
public static StringCollection GetAllFieldChoices(string fieldName) 

{

 StringCollection fieldChoices = null;                                                      

SPSecurity.RunWithElevatedPrivileges(delegate()    

{             

SPWeb origWeb = SPContext.Current.Web;     

while (!origWeb.IsRootWeb)        

origWeb = origWeb.ParentWeb;      

try       

{      

using (SPSite site = new SPSite(origWeb.Url))         

{           

using (SPWeb web = site.OpenWeb())           

{             

SPField field = web.Fields[fieldName] as SPField;             

if (field != null)             

{             

if (field.Type == SPFieldType.Choice)                

fieldChoices = ((SPFieldChoice)field).Choices;             

}           

}         

}       

}       

catch (Exception ex)      

{        

throw;     

}

});

    return fieldChoices;

}

 

/// <summary>

    /// Update an SPFieldChoice Field of the SPWeb

    /// </summary>

    /// <param
name=”fieldName”>
Name of the
field
</param>

    /// <param
name=”choices”>
StringCollection
that represents the choices for the field
</param>

    public static void
UpdateSPFieldChoice(string fieldName,
System.Collections.Specialized.StringCollection
choices)

    {

      SPSecurity.RunWithElevatedPrivileges(delegate()

      {

        SPWeb
origWeb = SPContext.Current.Web;

        while
(!origWeb.IsRootWeb)

          origWeb = origWeb.ParentWeb;

        try

       

          using
(SPSite site = new
SPSite(origWeb.Url))

          {

            using
(SPWeb web = site.OpenWeb())

            {

              SPField
field = web.Fields[fieldName] as SPField;

              if
(field != null)

              {

                if
(field.Type == SPFieldType.Choice)

                {

                  int
numberOfChoices = choices.Count;

                  string[]
values = new String[numberOfChoices];

                  choices.CopyTo(values, 0);

                  web.AllowUnsafeUpdates = true;

                  SPFieldChoice
spFied = field as SPFieldChoice;

                  if
(spFied != null)

                  {

                      spFied.Choices.Clear();

                     
spFied.Choices.AddRange(values);

                      spFied.Update();

                  }

                }

              }

            }

          }

        }

        catch (Exception ex)

        {

          throw;

        }

      });

    }

///<summary>
///Extention Method For IEnumerable Objects that returns random items from the source
///</summary>
///<typeparam name=”T”>Type of objects in array</typeparam>
///<param name=”source”>IEnumerable source(items in source must be of type T)</param>
///<param name=”howMany”>Number of items toreturn</param>
///<returns>Randomly returns a List T of specified number of items inthe IEnumerable source</returns>
public static List<T>TakeRandom<T>(this IEnumerable<T> source,int howMany)
{
    //if the source object is null the function return a new List<T>
    if(source ==null)
        return new List<T>();

    var array = source.ToArray();
    Random random =new Random();
    for(vari = 0; i <Math.Min(howMany,array.Length); i++)
    {
        var currentItem = random.Next(i, array.Length);
        var temp = array[i];
        array[i] = array[currentItem];
        array[currentItem] = temp;
    }
    return array.Take<T>(howMany).ToList();
}
///<summary>
///Extension method for IEnumerable objects that return an item randomly chosen from the source
///</summary>
///<typeparam name=”T”>Type of object contained in the source</typeparam>
///<param name=”source”>IEnumerable source that contains many T objects</param>
///<returns>Returns an item of type T</returns>
public staticT TakeRandom<T>(this IEnumerable<T> source)
{
    //if the IEnumerable source object is null the function returns the default(T)
    if (source ==null)
        return default(T);
    List<T> list = TakeRandom(source, 1);
    T objectToReturn =default(T);
    if (list !=null)
        if (list.Count > 0)
            objectToReturn = list[0];
    return objectToReturn;
}
///<summary>
///Extension Method for IEnumerable object that returns if the collection is Empty
///</summary>
///<typeparam name=”T”></typeparam>
///<param name=”source”>IEnumerable object</param>
///<returns>Returns true if there is no items in the collection</returns>
public static bool IsEmpty<T>(this IEnumerable<T> source)
{
    if (source ==null)
        return true;
    else
        return source.Count() == 0 ?true:false;
}
///<summary>
///Extension method for objects that implement the IList interface
///This method update an item from the list with a new one
/////TODO: maybe add the predicate in the function itself to find if oldItem has a match in the list
///</summary>
///<typeparam name=”T”>T of objects in the List</typeparam>
///<param name=”source”>Source List (must implement IList)</param>
///<param name=”oldItem”>Old Item T to find and update</param>
///<param name=”newIitem”>New Item T</param>
public static void Update<T>(this IList<T> source,T oldItem, T newIitem)
{
    if (source !=null)
    {
        for (inti = 0; i <= source.Count() – 1; i++)
        {
            if (source[i].ToString() == oldItem.ToString())
            {
                source[i] = newIitem;
                //once the item is found, exit the function
                break;
            }
        }
    }
}
Tags:

Welcome on my blog !

It’s been a long time since I thought “why not me?”, so voilà! Though this blog has been existing for 2 years…

Bienvenue sur mon blog!

Ca faisait longtemps que je me disais “pourquoi pas moi?”, et voilà! Et pourtant ce blog existe depuis 2 ans déjà…