Microsoft Technology, .Net, BizTalk, Sharepoint & etc.

Liedong(Ken) Zheng, Senior SharePoint Developer at SIMPLOT

Passed ITIL V3 Foundation exam

Posted by ken zheng on July 8, 2009

After 2 and half days course and I passed the ITIL V3 foundation exam today, no more study.

Posted in Uncategorized | Leave a Comment »

Publishing Sub-site to Site Collection

Posted by ken zheng on July 2, 2009

For those in need of this, Gary LaPointe has updated his gl-convertsubsitetositecollection command to be fully supported.

http://stsadm.blogspot.com/2007/09/convert-sub-site-to-site-collection.html

The only hitch is it assumes SP2. One good reason to upgrade.

Posted in Sharepoint | Tagged: | Leave a Comment »

Programmatically Inherit Master Page and CSS in MOSS 2007

Posted by ken zheng on June 30, 2009

The code below is to use the global navigation bar and Inherit site master page from parent of this site


                projectDetailWeb.Navigation.UseShared = true;

                //set masterpage to Inherit site master page from parent of this site
                projectDetailWeb.MasterUrl = projectDetailWeb.ParentWeb.MasterUrl;
                projectDetailWeb.AllProperties["__InheritsMasterUrl"] = "True";

                projectDetailWeb.CustomMasterUrl = projectDetailWeb.ParentWeb.CustomMasterUrl;
                projectDetailWeb.AllProperties["__InheritsCustomMasterUrl"] = "True";

                projectDetailWeb.AlternateCssUrl = projectDetailWeb.ParentWeb.AlternateCssUrl;

                projectDetailWeb.AllProperties["__InheritsAlternateCssUrl"] = "True";

                projectDetailWeb.Update();

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

Silverlight 3 – Consumption of a WCF Service

Posted by ken zheng on June 21, 2009

I started to play with the SL3 with wcf, but keep getting the error when using default clientconfig file

Could not find default endpoint element that references contract ‘ProjectName.ServiceReference1.IService1′ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

If you look at the config file you’ll see contract=”ServiceReference1.IService1″. This needs to be a fully qualified namespace, and should be changed to contract=”ProjectName.ServiceReference1.IService1″ (or whatever namespace is specified in your Reference.cs file)

Posted in Silverlight | Tagged: | Leave a Comment »

Making the Quick Launch appear again on Web Part pages stored in a document library

Posted by ken zheng on June 16, 2009

There are a few option to make it happen, I followed David’s step to modify the master page of the site:

or you can modify every page.

Posted in Sharepoint | Tagged: | Leave a Comment »

Dropdown to change the View disappeared

Posted by ken zheng on June 16, 2009

Sometime the list web part doesn’t show the change view dropdown list, I found this soltuion by just removing the web part and re-add it from the closed web part in Advanced Web Part gallery and options. It works.

See the blog for more details

Posted in Sharepoint | Tagged: | Leave a Comment »

The service did not respond to the start or control request in a timely fashion for sql report service

Posted by ken zheng on June 11, 2009

We managed to circumvent the problem with this instrucions:

1.Click Start, click Run, type regedit, and then click OK.

2.Locate and then click the following registry subkey:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control

3.In the right pane, locate the ServicesPipeTimeout entry.

Note If the ServicesPipeTimeout entry does not exist, you must create it. To do this, follow these steps:

a.On the Edit menu, point to New, and then click DWORD Value.

b.Type ServicesPipeTimeout, and then press ENTER.

4.Right-click ServicesPipeTimeout, and then click Modify.

5.Click Decimal, type 60000, and then click OK.

This value represents the time in milliseconds before a service times out.

6.Restart the computer.

Posted in Handy Tips, SQL | Tagged: | Leave a Comment »

Cannot Set Windows Background Image

Posted by ken zheng on June 3, 2009

It happens to me a few times, I can’t set my desktop image. What you need to do is go to your registry. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System, delete Wallpaper key and now you can set the background image

Posted in Handy Tips | Leave a Comment »

Generate insert script from existing data table

Posted by ken zheng on June 3, 2009

You can generate a create table script from SQL 2005 but there is no oob to generate an insert script.

Here is the link to create a sp which will generate script for you.
http://vyaskn.tripod.com/code/generate_inserts_2005.txt.

Check out the My code library to see any script can be used in your project.

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

BreakRoleInheritance(false) and AllowUnsafeUpdates

Posted by ken zheng on June 2, 2009

. I’ve used the method for this previously in the solution,BreakRoleInheritance(false), so that no inherited roles are copied, but then this was done on a POST request and now it should do almost the same during a GET request, that is when the user navigates to the page.

All this is done under elevated privileges and looks something like this


SPSecurity.RunWithElevatedPrivileges(delegate() {
  using (SPSite site = new SPSite(url)) {
    using (SPWeb web = site.OpenWeb(url.Replace(site.Url, string.Empty))) {
      web.AllowUnsafeUpdates = true;
      Guid guid = web.Lists.Add(name, string.Empty, SPListTemplateType.DocumentLibrary);
      SPList list = web.Lists[guid];
      ...
      list.BreakRoleInheritance(false);
      ...
      list.Update();
    }
  }
});

This gives me the following error when running during a GET request.

“Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb.”

If I rewrite the code and change the BreakRoleInheritance(false) to BreakRoleInheritance(true) and set the AllowUnsafeUpdates to true once again it works fine and I have to manually get rid of all the roles.

Why is it so?

If you step through the code in the working sample you will see that after the BreakRoleInheritance(true) line the AllowUnsafeUpdates property of the SPWeb object has changed to false. The AllowUnsafeUpdates property will reset to false whenever any ISecurable object changes their role definitions, and in the BreakRoleInheritance method you have a call to an internal function that invalidates the SPWeb object which resets the AllowUnsafeUpdate property.

The exception is then thrown after breaking the role inheritance and when the method tries to remove the roles from the list. I initially thought that it was the other way around and therefore was a bit confused.

So the correct way is this:


SPSecurity.RunWithElevatedPrivileges(delegate() {
  using (SPSite site = new SPSite(url)) {
    using (SPWeb web = site.OpenWeb(url.Replace(site.Url, string.Empty))) {
      web.AllowUnsafeUpdates = true;
      Guid guid = web.Lists.Add(name, string.Empty, SPListTemplateType.DocumentLibrary);
      SPList list = web.Lists[guid];
      ...
      docLib.BreakRoleInheritance(true); //Exception throw here when the parameters is "false"
      web.AllowUnsafeUpdates = true;
      SPRoleAssignmentCollection roleAssigns = docLib.RoleAssignments;
      for (int i = roleAssigns.Count-1; i >= 0; i--)
     {
        roleAssigns.Remove(i);
      }
      list.Update();
    }
  }
}};

Reference:
http://www.wictorwilen.se/Post/BreakRoleInheritance-and-AllowUnsafeUpdates.aspx
http://www.delphi-ts.com/blogs/lozzi/2008/10/31/TheSecurityValidationForThisPageIsInvalid.aspx

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