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

Liedong(Ken) Zheng, Senior SharePoint Developer at SIMPLOT

Archive for June, 2009

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: , | 1 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: | 2 Comments »

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 »

Corrupted applicationHost.config file in IIS 7

Posted by ken zheng on June 2, 2009

One day, when my VPC was closed unexpected, the IIS can’t restart and throw error:

The Windows Process Activation Service encountered an error trying to read configuration data from file ‘\\?\C:\Windows\system32\inetsrv\config\applicationHost.config’, line number ‘0′. The error message is: ‘Configuration file is not well-formed XML’

Luckily IIS makes a backup each time you make a change. All those versions are stored in the folder C:\inetpub\history\. All you have to do is to copy a former applicationHost.config file into the C:\Windows\System32\inetsrv\config\ working directory.

Posted in Handy Tips, Sharepoint | Tagged: , | 3 Comments »

Immediate Alerts failed On One Web Front End

Posted by ken zheng on June 1, 2009

We have 2 web front end server for Sharepoint, but one of them is 32-bit and not upgraded which caused some timer job failed. To check the Immediate Alerts I followed this blog:

a. Open the command prompt and go to the 12\Bin folder. Run this command and see whether alerts are enabled for the web application.

Stsadm.exe-o getproperty -url http://problemsite -pn alerts-enabled

The expected output is . If you don’t get this, run the following command to change the value.

stsadm.exe -o setproperty -pn alerts-enabled -pv “true” -url http://problemsite

If the property is Yes and still the alerts are not sent, toggle the property from Yes to NO
and then from No to Yes. This may delete all the existing alerts and warn the customer
about this.

b. Check the property job-immediate-alerts schedule through command prompt. Run this command from the 12\bin folder. If we have issues with Scheduled alerts like daily or weekly, then check the property job-daily-alerts and job-weekly-alerts.

stsadm.exe -o getproperty -url http://ProblemSite -pn job-immediate-alerts

The expected output is
. If you don’t get this, run the following command to change the value.

stsadm.exe -o setproperty -pn job-immediate-alerts -pv “every 5 minutes
between 0 and 59″ -url http://ProblemSite

c. Confirm the above step through the UI. Central adminàOperationsàTimer Job Definitions and ensure that a job named Immediate Alerts is present for the web application.

I run the above commands which display all right. So I turned off the 32-bit server for one night. And on the next morning, all the Immediate Alerts back tot he 64 bit server works fine.

Posted in Sharepoint | Leave a Comment »