Month: November 2009

Create secure sharepoint application page for site administrator

Home | SharePoint Development | Create secure sharepoint application page for site administrator

I’ve seen a question in msdn forum few days back, asking whether the sharepoint application page can be accessed only by the administrator. There is a simple way to achieve this. Whenever we create the secure application page in sharepoint, we need to override the property called RequireSiteAdministrator and return the value true. This would secure the application page in such a way that, it can be accessed only the site-administrator. Here is the code-snippet for the same. 

public class YourSampleApplicationPage : LayoutsPageBase {

  protected override bool RequireSiteAdministrator {
    get { return true; }
  }

  protected override void OnLoad(EventArgs e) {
    // any arbitrary logic goes here
  }
}

 Subscribe to my post

Create a custom web part to render silverlight application

Home | SharePoint Development | Create a custom web part to render silverlight application

In my previous post, I’ve discussed about how to leverage the content editor web part to render the silverlight application. In this post, I’d be discussing the steps to create a custom web part to render the silverlight application. The custom web part that renders the silverlight application has more advantages. Because things like attributes of silverlight application can be externalized as web part properties. Moreover security can be applied while rendering silverlight application, because the custom web part has power of code-behind support, rather than content editor web part. The whole idea is to render the silverlight control programmatically inside the web parts(using createchildcontrols method) . Here are the steps mentioned below :-

a)Import required namespace

Add a reference to System.Web.Silverlight.

using System.Web.UI.SilverlightControls; 

b)Programmatically add the script manager control to the page

To render the silverlight control, the ScriptManager object needs to added to the Page. Override the OnLoad method of web part, add the ScriptManager control using the following code-snippet. There needs to be only one instance of ScriptManager object registered with the Page object.

    protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //get the script manager associated with the current page
            ScriptManager oscriptManager =
                  ScriptManager.GetCurrent(this.Page);

            //check whether the script manager is already registered to the page
            if (oscriptManager == null)
            {
                oscriptManager = new ScriptManager();
                Controls.AddAt(0, scriptManager);
            }

        }

 

c)CreateChildControls method to render silverlight application

Override the CreateChildControls method and render the Silverlight control.

 protected override void CreateChildControls()
        {
            base.CreateChildControls();

            Silverlight oSilverlight = new Silverlight();
            oSilverlight.ID = “SLWPID”;
            oSilverlight.Source = “∼/ClientBin/YourSilverlightApp.xap”;
            oSilverlight.Width = Unit.Percentage(100);
            Controls.Add(oSilverlight);
        }

 Subscribe to my post

Leverage content editor web part to render silverlight application

Home | SharePoint Development | Leverage content editor web part to render silverlight application

Silvelight can be integrated with SharePoint sites to provide richness and improve the user experience of the SharePoint sites. There are many ways to integrate the silverlight application (xap) with SharePoint sites. The first option is to leverage the content editor web part and render the silverlight application (xap) through html and JavaScript. This is the simplest way to integrate silverlight applications with SharePoint sites. The other option is to to create a custom web part that does the rendering of the silverlight application.

In this blog post, I’d be sharing the steps to render silverlight applications by leveraging the  content editor web part.

Step1

Go the virtual directory in IIS, corresponding to the SharePoint web application. In my case it is C:inetpubwwwrootwssVirtualDirectories1111

Create a sub-folder by name silverlight_bin under the C:inetpubwwwrootwssVirtualDirectories1111

Copy the silverlight application (xap) from the bindebug directory of silverlight project  to the sub-folder silverlight_bin

Step2

Add the content editor web part to the page

Step3

Click ‘Modify shared web part’ and enter the following html snippet to the web part to the source editor of the content editor web part

<object
  data=”data:application/xsilverlight,”
  type=”application/xsilverlight2b2width=”400height=”300>

<param
  name=”sourcevalue=”/Silverlight_Bin/yoursilverlightapp.xap/>

</object>
Sometimes specifying the object tag in content editor web part may not work properly. If it does not work properly, we need create the object tags and other attributes using javascript.

 Subscribe to my post