Vanou’s Blog

Archive for the ‘MOSS 2007 – SharePoint 2007’ Category

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

   
/// <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;

        }

      });

    }