ObjectSharp Blogs

You are currently viewing

Justin Lee's Technology Blog


Languages, Languages, Languages!


Elevating Privileges in SharePoint

Here’s a good tip for elevating privileges in SharePoint.

http://blogs.devhorizon.com/blogs/reza_on_blogging/archive/2007/07/12/484.aspx

For those who doesn’t want to click on that link (like myself when I searching for this post again), here’s the code.

//Don't dispose the following two objects. Sharepoint will take care of their disposal when page is completely rendered.
SPWeb  webInUserContext = SPContext.Current.Web;
SPSite SiteInUserContext = SPContext.Current.Site;
Guid webGuid = webInUserContext.ID;
Guid siteGuid = SiteInUserContext.ID;

SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    // get the site in impersonated context
                    using (SPSite site = new SPSite(siteGuid))
                    {

                        // get the web in the impersonated context
                        SPWeb web = site.OpenWeb(webGuid);
                       // Do your work here  

                     web.Dispose();
                    }

               });

There we go. I used this piece of code to access the SPFile of a document within SharePoint. SPFile requires elevated privileges, and can’t be access with just your normal privileges.

My code works now, and I’m happy. :)

Where is my Check-In in SharePoint Designer?

sharepointdesigner-checkin

If you notice, the master page file in SharePoint Designer is checked out (from the check symbol at the side). It’s supposed to show me “Check In” and “Undo Check Out” and all that. Where is it?

It is under your “Edit” toolbar, “Check In”.

image

So when it doesn’t display, you know where to go.

Hiding Sign In Link For Anonymous Access Users in SharePoint

To customize SharePoint “Sign In” link, we need to modify or duplicate Welcome.ascx in your Control Templates directory.

Here’s a good post specifying how to hide your sign in link.

Hide the Sign In link for the anonymous access user in anonymous access enabled site - Bend the Welcome.ascx - SharePoint MOSS

You can play around with Welcome.ascx and come up with your custom style sign in.

Free UX Tools and Extensions for Websites

Here’s a great blog post with the compilation of great tools if you’re a web developer.

Top 29 Free UX Tools and Extensions

I ran a few of the test on our website, and boy are there a few optimizations we could have done, especially for the JavaScript within the pages to improve performance. And also some quirks xhtml and css errors which will just make things nice and more standardised.

SharePoint: Bug or Feature? @Created not on Variation Site

As mentioned in the title, the @Created date field (or site column, depending on your terminology), the date of document creation, which is by default available to all pages and documents, is not replicated when you create a site variation. It is however *linked* to the original document from the original site itself. So if you ever decide to turn off site variation, you’ll lose the @Created date field on your site variation, and there’s absolutely no way to get it back, or at least I haven’t found a way to get it back without hacking it through code.

So be careful when you decide to create a site variation. This “feature” caught us all by surprise, especially when variation was turned off and still wanted the persisted site.

One suggestion to get around it is to create another field and set the computed value to today’s date. I’ll blog more on how we solve this problem when we actually do.

Sharepoint Development: Enable Debugging

Note to self – Before developing on SharePoint, always enable debugging on the development machine to see a “little” more verbose error messages. Edit the web.config and change the following:

<SafeMode MaxControls="200" CallStack="false" ...> <!-- Becomes -->

<SafeMode MaxControls="200" CallStack="true" ...>

 

<customErrors mode="On" /> <!-- Becomes -->

<customErrors mode="Off" />

 

<compilation batch="false" debug="false"> <!-- Becomes -->

<compilation batch="true" debug="true">

Sharepoint Development: &quot;Request failed&quot; with custom page or dlls/assemblies

Note to self - If using any external assemblies that try to access Microsoft.Sharepoint assemblies, remember to change the trust level to full in the web.config.

<trust level="Full" originUrl="" />

This is only used during development.

When it comes to production, install assembly into the GAC with gacutil /i to allow external assemblies access to Microsoft.Sharepoint assemblies.

VSLab - F# Visualization

Visual Studio Lab (VSLab) exploits the power of F# and its interactive top level to provide an interactive environment similar to MatLab and Mathematica, in which you can easily create Add-ins and interact dynamically with them inside Visual Studio. Moreover, since F# is a compiled language, the final code can be compiled as a standalone application.
Goal of the project is to provide the basic infrastructure to turn Visual Studio in VSLab, and a number of addins (called viewlets) used to show data and support development of scientific based applications.

Take a look. :) I assure you that you'll be impressed.

Another Reason to use Flash Instead of Silverlight

Flash content is finally searchable by two of the biggest online search engines on the internet, Google and Yahoo.

One of the biggest disadvantage of using Flash content for your dynamic content is simply because it is not searchable, and now with Adobe's new optimized Adobe Flash Player helping both Google and Yahoo to search and index Flash content, this means that there is no excuse left NOT TO USE FLASH on your web sites.

Note that Microsoft Live Search was not included in this partnership.

Now, for those enthusiastic about writing Silverlight content on the web, might I ask, what is Microsoft going to do about this? Both in its Live Search, making it competitive with Google and Yahoo to search Flash content, and also making Silverlight content searchable too. This is the biggest advantage Adobe Flash has over Silverlight now, and if Microsoft doesn't do anything about it, the web will not be convinced about Silverlight, regardless of the amount of bribing promoting they can and will do.

Adobe, we love you and thank you.

To those Silverlight enthusiasts, please get your facts right about Adobe Flash before even bashing Adobe Flash technology. You know who you are.

Blaming the User

Is it better to have a user implicitly learning how an application work easily by discovery, rather than explicitly learning how an application works through training and books?

If something goes wrong with an application, is it really a "problem between the keyboard and the chair"? Or is it because the "User Experience" isn't sufficient or consistent to assist with implicit learning?

Sometimes people in the "Computer Industry" need to think more about the user and how to ease their pain, instead of blaming them and create more pain for them.

I'm always amazed when a user tells me "It just works! Amazing!" instead of "How do you do this?". That's "User Experience" for you.

Think about it.

This is my rant today.

More Posts Next page »