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

Liedong(Ken) Zheng, Senior SharePoint Developer at SIMPLOT

Archive for December 10th, 2008

Victoria.NET Back to Basics – Sessions on WCF, WPF and WF – Monday Dec 15th

Posted by ken zheng on December 10, 2008

case you missed this announcement from Mahesh… Cheers Dave

Monday 15th December 2008
5:30pm (Pizza and drinks served); 6pm (presentations start)
Microsoft Theatre, Level 5, 4 Freshwater Place, Southbank

Back to Basics – WCF, WPF and WF

Over two years ago Microsoft introduced .NET 3.0 and with it, it’s four pillars – Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), Windows Framework (WF) and Windows Cardspace. In “Back to Basics”, we present 3 detailed sessions on 3 of these topics – WCF, WPF and WF.

If you’ve never used these Technologies before or would like to re-acquaint yourself with them, this is the session to attend.

If you are planning on coming, please RSVP to help us organise drinks and catering.

To register, simply send an email to info@victoriadotnet.com.au. It is a FREE event and there is no charge for attendance but space is limited so you’ll need to let us know you’re coming so we can make sure there’s space. If you do not wish to receive event notification mails in the future, simply send a mail to info@victoriadotnet.com.au with the word Unsubscribe in the subject.

The user group has a Twitter account. You can follow the happenings in the group at http://twitter.com/vdnug/a>

The Victoria .NET Dev SIG usually meets on the second Tuesday of every month to discuss developer related .NET topics. Victoria .NET also runs an Office and SharePoint group called MOSSIG (that meets on the 4th Wednesday of every month) and a SQL SIG (that meets 12:30-2:00pm on the 2nd Monday of each month) to discuss topics related to SQL Server development and a new Silverlight Developer and Designer Network user group

Posted in Uncategorized | Leave a Comment »

Best Practise to Use SharePoint Site Object

Posted by ken zheng on December 10, 2008

                using (SPWeb userWeb = SPContext.Current.Web)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite currentSite = new SPSite(userWeb.Site.ID))
                        {
                            using (SPWeb currentWeb = currentSite.AllWebs[userWeb.ID])
                            {
                                //allow unsafe updates
                                bool currentUnsafeSetting = currentWeb.AllowUnsafeUpdates;
                                currentWeb.AllowUnsafeUpdates = true;
                                returnValue = currentWeb.EnsureUser(loginName);
                                currentWeb.Update();
                                currentWeb.AllowUnsafeUpdates = currentUnsafeSetting;
                            }
                        }
                    });
                }

Posted in Sharepoint | Leave a Comment »

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack when use new spsite

Posted by ken zheng on December 10, 2008

You need to use

SPSite site = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
site = new SPSite(Configuration.MyPmpUrl);
});
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
return web;

To open your site
Below is the code to change pagelayout of default page

            string url = SPContext.Current.Web.Url + "/" + TextBox1.Text;
            string pageName = "default.aspx";
            string layoutName = "DefaultLayout.aspx";

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                using (SPSite site = new SPSite(url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        PublishingPage pubPage = null;
                        PageLayout pubLayout = null;
                        web.AllowUnsafeUpdates = true;

                        PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

                        PublishingPageCollection pages = pubWeb.GetPublishingPages();

                        foreach (PublishingPage page in pages)
                        {
                            if (Equals(page.Name, pageName))
                            {
                                pubPage =  page;
                            }
                        }

                        PageLayout[] layouts = pubWeb.GetAvailablePageLayouts();

                        foreach (PageLayout layout in layouts)
                        {
                            if (Equals(layout.Name, layoutName))
                            {
                                pubLayout =  layout;
                            }
                        }

                        pubPage.CheckOut();

                        pubPage.Layout = pubLayout;
                        pubPage.Update();
                        pubPage.CheckIn("Page Modified For Layout Assimilation");
                        pubPage.ListItem.File.Publish(string.Empty);

                        if (pubPage.ListItem.ParentList.EnableModeration)
                        {
                            pubPage.ListItem.File.Approve(string.Empty);
                        }
                    }
                }

            });

Posted in Sharepoint | 1 Comment »