Thursday, December 22, 2011

Before
starting what sandbox solution is, first let us understand what solution mean? If
you have worked with MOSS 2007 version then you must be aware of solutions.
Solutions can be deployed over a farm. With 2010 version solution can also be
deployed in sandbox. Solution may contain web parts, images, pages, event
handlers, lists etc.

Sandbox
solution is a new concept introduced in SharePoint 2010. Advantage of sandbox
solution is this solution actually executes in a restricted zone. It cannot
access everything in object model. It cannot access certain resources from
SharePoint object model.

This is the
advantage because it cannot affect the farm environment. If something goes
wrong in the sandbox solution then entire farm does not get affected.

Sandbox
solution is always given certain number of resource allocation space and that
is monitored by farm administrator. If farm administrator wants, then it can be
disabled or even it can also be promoted to be a farm solution as an upgrade.

Other
advantage of sandbox solution is it can free farm administrator for deployment
stand point. Site collection administrator can deploy and activate the sandbox
solution. If the sandbox solution does not contain any assembly, then even a
user with full control over a top level site of site collection can also deploy
the solution.

Sandbox
solution runs in a separate process and that is the reason if something goes
wrong in sandbox solution then it does not impact farm. It does not run in w3wc
process but runs under SPUCWorkerProcess.

For the
hosted SharePoint environment, this can be one of the best ways to deploy and
maintain the solutions and sites.

There are
many limitations in terms of accessing resources while you program against
sandbox solutions in SharePoint. I am listing down some of them. You cannot:

1)System.IO,
ADO.Net

2)Write
to disk files

3)Oher
site collection content

4)SPSecurity.RunWithElevatedPrivileges

5)Change
threading model

6)Create
visual web part

7)Access
programmatic workflow

8)Timer
Job

9)Web
Application scoped features

Here are
certain items that you can do in sandbox solution environment

1)Web
Parts (not visual)

2)Event
receivers

3)Feature
receivers

4)Custom
SharePoint Designer Workflow Activity

There are
certain steps that farm administrator has to perform before setting up sandbox
solution environment if entire set up is farm architecture. Farm administrator
starts the sandbox service in each server in farm, configures the best load
balancing service for sandbox solutions on each server and then set the
resource quotas.

When the page loads, we push the function AlertParametersPassedFromParent
to execute and called a function called getQueryString which is actually logic
to retrieve query string which is passed from the parent page. There is no
ready method in JavaScript like server side methods. So we have to use our own
method to get that.

And we have then just prompted the parameter value with
alert to see if it has passed properly.

Here is what we get as an end result.

I hope you have enjoyed the entire series of model
dialog framework. We will try and add some new content if we find anything
interesting about model dialog more. Of course we encourage and appreciate our
readers to share their experiences so that we all SharePoint working community
get benefited from it.

Tuesday, December 13, 2011

If you have not gone through Part-1 to Part-3 of this
series, I would recommend you reading them first and then continue reading from
here on.

In this post, we are going to see how we can pass
parameters to a parent page from where we have opened up the model dialog.

We take the same example that we have in our previous
post. I am not going to rewrite the entire code and pages. You can have a look
at previous posts to gain the insight of it.

Open your aspx page and change the button click
functionto following. As you can see we have declared an array of result and we
have passed name and value pair of parameter values in it and then passed the
entire results array as an object to our window.frameElement.commitpopup
method.

<script language="javascript" type="text/javascript">

function OkButtonClicked() {

var results = {

message: "Custom message from a custom dialog page",

passedvalue : "yes"

};

window.frameElement.commitPopup(results);

}

</script>

So when the page is closed, we can now retrieve these
parameters in the parent page. We can do so in following way.

Thursday, December 8, 2011

If you have not gone through Part-1 and Part-2 of this
series, I would recommend you reading them first and then continue reading from
here on.

In this post, we are going to create our own page and
then open the page with dialog framework and then handle Ok and Cancel event to
that just like how we saw in previous post with library upload page.

Open your own project in Visual studio 2010. If you
have not created a project, create an empty SharePoint project and add new item
an application page. Give it a name like CustomPage.aspx. Visual studio will
automatically map the page to layout folder.

All the dialog pages that open in SharePoint 2010
inherits from dialog.master file which is in TEMPLATE/LAYOUTS folder. So we
also need to modify our markup to inherit the page from dialog.master.

We can remove the dynamicmasterpage file attribute from
the page tag. We will see about this attribute in some future post. As of now,
we simply remove it.

Now because we have changed the master page URL and we
are referring to a different master page, all the content place holders which
are on the page may not be there in the master page that we are now referring.

So we need to make the change in the content place
holders as well.

Remove all these content tags.

When you are not sure, you always should check the
master page content place holder IDs and the content place holder IDs present
in content page. If there is any misplaced place holder, then you will not be
able to work on the page. The page will not be rendered.

You can create the entire HTML here to work on a page. Table layouts, controls etc.

</asp:Content>

Use the same OpenModelDialog method in your web part or
any button on your custom page to open this layouts page.

function OpenModalBing()

{

var options = {

url: '/sites/SP2010/_layouts/SharePointActivities/CustomDialog.aspx',

tite: 'Open a custom dialog',

allowMaximize: false,

showClose: true,

width: 750,

height: 550,

dialogReturnValueCallback: FunctionToCall

};

SP.UI.ModalDialog.showModalDialog(options);

}

function FunctionToCall(dialogResult, returnValue) {

if (dialogResult == SP.UI.DialogResult.OK) {

SP.UI.Notify.addNotification('OK was clicked');

}

if (dialogResult == SP.UI.DialogResult.cancel)

SP.UI.Notify.addNotification('Cancel was clicked!');

}

And this is what you get. You can see the default
buttons OK and Cancel been added to the page. We thought have not hooked up any
event to that.

Now because we have inherited our custom page from
dialog master page hence we got the ok and cancel button on a page. We need to
write a custom code to the ok and cancel button. So we need to hook up our code
to ok button.

So let’s add some code to it. Open the cs file of our
custom page and write down the following code to it.

Now we need to add this script to a aspx page. So open
up aspx page and add the function script.

<script language="javascript" type="text/javascript">

function OkButtonClicked() {

window.frameElement.commitPopup();

}

</script>

Now build and deploy the solution and see this in
action.

Click cancel, the message appears and click ok, the
message appears after clicking on cancel or ok. Window.frameelement.commitpopup
closed the model dialog and passes the dialog option value based on ok or
cancel button clicked.

Monday, December 5, 2011

If you have not gone through Part-1 of this series, I
would recommend you reading part-1 and then continue reading from here on.

In this post, we are going to see how to open built in
SharePoint list page and react to Ok or Cancel button clicked on a page.

Let us enhance the example that we saw in previous
post. We will add some more lines to code and this time we will bind a function
that will execute after we close the window from clicking ok or cancel button.

What we are doing here is we are opening a upload
window page in model dialog and then based on a user action we display a
message. If user uploads a document and click on Save or ok then dialog returns
the OK status and if user clicks on cancel then it returns the cancel status
that we check in the JavaScript function.

dialogReturnValueCallback is the function that executes
after the model dialog closes. When declaring that function we need to define
two parameters. One is the result and the other is return value.

Here in this example, we are not using the return value
but checking the default button clicks.

Here is what you can see in action. When cancel clicked
and when OK clicked.

In next post, we will create our own page, will deploy
the page and then opens that page via dialog framework and handle Ok and Cancel
button click event on our own.

Tuesday, November 29, 2011

We are going to cover a new topic and a new series
called dialog framework that has been introduced in SharePoint 2010
environment.

We all are aware about the dialogs if we have worked in
web technologies. A model window that pops up and you can perform some
operation without navigating to other page and then come back to the previous
page.

If you would like to have a quick look at this series and would like to understand it as an overview, you can have a look at Opening any page as model dialog post.

Model dialog allows you to perform an operation and
then close the window after performing an operation and you are back on the
same page.

Most of the functionality is handled by two basic
classes. SP.UI.Dialog and SP.UI.ModelDialog.

Classic example of model dialog is when you create,
edit entries from list items, you get a dialog window to perform that. These
pages open as a part of dialog.

We will deep dive into this dialog framework. In this
post, I am going to cover a simple scenario of opening a window as a model
dialog. You can have this enabled in your custom action click event, it can be
a part of button click, and it can be a part of ribbon button.

Here is a very simple code written to open Bing search
in model window from button click. We have defined a JavaScript that executes
when we click on the button.

I’ve defined in a web part, one input type button and
invoking a JavaScript function to open a model dialog.

<input type="button" value="Open Bing" onclick="OpenModalBing()" />

<script type="text/javascript">

function OpenModalBing()

{

var options = SP.UI.$create_DialogOptions();

options.url = "http://www.bing.com";

options.width = 750;

options.height = 550;

SP.UI.ModalDialog.showModalDialog(options);

}

</script>

And this is what you get out of this code.

You can pass on different parameters in an option. So
that when a window opens, it has some properties defined in it. just like how
we do with window.open javascript function.

Here I have made some change to an existing code and look
at the change in the behavior of how window open when button is clicked.

Now the maximize button does not appear as we have set
it in JavaScript.

If you observe, the window opens in a center. If you
would like to open a window at some other position, then you can use x and y
properties and set it to options.

There is also another way you can create dialog.
Observe the difference between two methods. Earlier we have created a window
and then we set the properties on the window object with = sign. This is the
other way around. Feel free to use the best suited way for you.

<script type="text/javascript">

function OpenModalBing()

{

var options = {

url: 'http://www.bing.com',

tite: 'Bing Search',

allowMaximize: false,

showClose: true,

width: 750,

height: 550,

};

SP.UI.ModalDialog.showModalDialog(options);

}

</script>

Both give you the same result. Keep reading Part-2 of the series to know more about model dialog.

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com

SiteMeter

Bookmark US

Disclaimer

The opinions expressed on this blog are the personal views of SharePointKings, and do not represent or reflect the viewpoints or policies of any past, present, or future employer, colleague, or customer, or any other entity. The posts on this blog are provided ‘as is’ with no warranties, express or implied, and confer no rights. Use of information contained within this blog, including specific technical steps mentioned herein, is at your own risk. References to specific software products, processes, resources, or companies do not imply any endorsement.