Wednesday, July 14, 2010

Internal mechanism of showing indicator of long operations in Sharepoint using SPLongOperation

This is regarding the progress of process that we we usually see into sharepoint like while creating new site or so.
This is very informative blog
http://sadomovalex.blogspot.com/2010/07/internal-mechanism-of-showing-indicator.html

Open SPSite under RunWithElevatedPrivileges in proper zone

This is very good point when we are developing some custom code which is gona be used for a web application that is hosted on multiple zones like Intranet and Internet and so

http://sadomovalex.blogspot.com/2010/01/open-spsite-under-runwithelevatedprivil.html

Tuesday, July 13, 2010

Fire a button click event when user press enter key from textbox

It is very common requirement that when user clicks enter key. a specific submit button event should fire. Sadomovalex has explained it very well in following blog.

http://sadomovalex.blogspot.com/2009/12/post-login-form-without-submit-button.html

Camlex.NET simplifies creating of CAML queries for Windows SharePoint Services by using expression trees

This is very good technique when we need to work on CAML queries.
Contributors have done a great job.
Check this for more info on Camlex.NET
http://camlex.codeplex.com/
Check following link for good examples by Sadomovalex for camlex
http://sadomovalex.blogspot.com/2010/06/build-dynamic-caml-queries-based-on.html

Cross-site and cross-site collection navigation in Sharepoint

This is very good article about, how we can have common navigation for all sites of a site collection or even accross site collections too.
http://sadomovalex.blogspot.com/2010/05/cross-site-and-cross-site-collection.html

Tuesday, July 6, 2010

Disable WebPart form validators when page is in edit mode

There was a issue that my form validators gets fired when we are in Page edit mode or we are updating a webpart.

So we need to disable validators when page in in edit mode.

Solution

On WebPart user control

using Microsoft.SharePoint.WebPartPages;

protected void Page_Load(object sender, EventArgs e)
{
if (SPWebPartManager.GetCurrentWebPartManager(Page).DisplayMode != WebPartManager.BrowseDisplayMode)
validator.Enabled = false;
}

Showing image preview popup using div and javascript

There was a requirement to have a grid with the image thumbnail column and when we clicks that image, it should show the preview for same image in popup. That popup will have close button on right top.

Also if user selects the image as choice from combo the it should show real images if he selects the document then i need to show the one dummy image and on clicking that image it should open or save document.


Step 1:

<asp:GridView
...

<ItemTemplate>

<center>

<div runat="server" id="previewDocument" >

<a href="<%# DataBinder.Eval(Container.DataItem, "ItemUrl")%>" alt="Click to see preview." target="_blank" >

<img id="Img1" class="imgThumbnail" src="/_layouts/images/EgSpi/Default/document.gif" alt="Click to see preview." />

</a>

</div>

<div runat="server" id="previewImage" >

<img id="Img1" class="imgThumbnail" src="<%# DataBinder.Eval(Container.DataItem, "ItemUrl")%>" alt="Click to see preview." onclick="Large(this)" />

</div>

</center>

</ItemTemplate>

</asp:TemplateField>

....
</asp:GridView>

Step 2:



protected void grvResults_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HtmlGenericControl docPreview = (HtmlGenericControl)e.Row.FindControl("previewDocument");
HtmlGenericControl imgPreview = (HtmlGenericControl)e.Row.FindControl("previewImage");

if (ddlObjectType.SelectedItem.Text == Enums.Object_Types.Document.ToString())
{
docPreview.Visible = true;
imgPreview.Visible = false;
}
else
{
docPreview.Visible = false;
imgPreview.Visible = true;
}
}
}

Step 3:

<script language="javascript">
function Large(obj) {
var imgHeight = 240;
var imgWidth = 240;
var imgBoxHeight = 250;

var imgbox = document.getElementById("imgbox");
imgbox.style.visibility = 'visible';

var divImageContainer = document.createElement("div");
divImageContainer.id = "imgContainer";
divImageContainer.innerHTML = '';

var divClose = document.createElement("div");
divClose.id = "imgclose";
divClose.innerHTML = "X";

if (divClose.addEventListener) {
divClose.addEventListener('onclick', Out, false);
} else {
divClose.attachEvent('onclick', Out);
}
imgbox.innerHTML = '';
imgbox.appendChild(divClose);

var img = document.createElement("img");
img.src = obj.src;

if ((img.height > imgHeight) || (img.width > imgWidth)) {
img.style.height = imgHeight + 'px';
img.style.width = imgWidth + 'px';
}
else {
divImageContainer.style.height = (imgBoxHeight - img.height) / 2 + 'px';
imgbox.appendChild(divImageContainer);
}

imgbox.appendChild(img);
imgbox.style.left = (obj.offsetParent.offsetLeft + 70) + 'px';
imgbox.style.top = (obj.offsetParent.offsetTop) + 'px';

}

function Out() {
document.getElementById("imgbox").style.visibility = 'hidden';
}

</script>

Step 4:

#imgbox
{
position: absolute;
border: 1px solid #999;
background: #FFFFFF;
filter: Alpha(Opacity=100);
visibility: hidden;
height: 250px;
width: 250px;
z-index: 50;
overflow: hidden;
text-align: center;
vertical-align:middle;
padding-top:5px;
padding-left:5px;
}

#imgclose
{
position: absolute;
top: 0px;
right: 0px;
background: #858585;
cursor: pointer;
padding: 6px;
font: bold 12px verdana, sans-serif;
color: white;
}

.imgThumbnail
{
border:none;
cursor:hand;
height:14px;
width:14px;
border: 1px solid #999;
padding:1px 1px 1px 1px;
}


----------------------------------- Enjoy ---------------------------------------