Tuesday, June 29, 2010
Jquery: List Items QuickView
hoverImgDescription = 'Hover mouse over this image to preview the metadata';
// The description text added to the top of the page.
// If left blank, no description is added to the top of the page.
arrOfFieldsToShow = ['Title','Description']; // Leave blank to show all fields. To have only the content and not the label, use this format ['Title|0']
prependHoverImageTo = ''; // The standard placement is "Title-field" for lists and "Name-field" for document library.
// If used with multi line text with append, insert FieldInternalName of "append-field" here.
function getLoadedFields(){
var res = {};
$("#jLoadMe td.ms-formbody").each(function(){
if($(this).html().indexOf('FieldInternalName="')<0) return;
var start = $(this).html().indexOf('FieldInternalName="')+19;
var stopp = $(this).html().indexOf('FieldType="')-7;
var nm = $(this).html().substring(start,stopp);
res[nm] = {'label':nm,'html':$(this).html()};
});
return res;
}
function jLoadMe(t,pX,pY,listBaseType) {//load content
if(listBaseType==0){
var whatToLoad = " #part1";
}else if(listBaseType==1){
var whatToLoad = " #onetIDListForm";
}
$("#jLoadMe").load(t + whatToLoad, function() {
if(arrOfFieldsToShow.length==0){
$("#jLoadMe").css({'width':'590'});
$("#jLoadMe h3").css({'font-size':'8pt'});
$("#jLoadMe .ms-formtoolbar:first").hide();
$("#jLoadMe table.ms-toolbar").hide();
$("#jLoadMe .ms-ButtonHeightWidth").hide();
var contentWidth = '590';
var contentHeight = $("#jLoadMe").height();
}else{
$("#jLoadMe h3").css({'font-size':'8pt'});
var contentWidth = '400';
var selectedRow = '';
$.each(arrOfFieldsToShow,function(idx,item){
var split = item.split('|');
var fieldTitle = split[0];
var showTitle = split[1];
jLoadMeFields = getLoadedFields();
if(showTitle!=0){
selectedRow += "<b>" + jLoadMeFields[fieldTitle].label + "</b>" + " - ";
}
selectedRow += jLoadMeFields[fieldTitle].html + "</br>";
});
selectedRow = "<div style='width:" + contentWidth + "'>" + selectedRow + "</div>";
// if(showTitle!=0){
// selectedRow += "<div style='font-weight:bold;border-bottom:1px silver solid;'>" + jLoadMeFields[fieldTitle].label + "</div>";
// }
// selectedRow += "<div style='padding:0 0 5 3;margin-left:5;border-left:1px silver solid'>" + jLoadMeFields[fieldTitle].html + "</div>";
// });
// selectedRow = "<div style='width:" + contentWidth + "'>" + selectedRow + "</div>";
$("#jLoadMe").html(selectedRow);
var contentHeight = $("#jLoadMe").height();
}
// Get height and width of current window
var winHeight = $(window).height();
var winWidth = $(window).width();
var winScroll = $(window).scrollTop();
// Calculate the best position for the popup Y-axis
if((winHeight - pY) < contentHeight){
if((pY - winScroll) < contentHeight){
pY = winScroll + 10
}else{
pY = (pY - contentHeight) - 30
}
}
// Calculate the best position for the popup X-axis
if((winWidth - pX) < contentWidth){
pX = (pX - contentWidth) - 30;
}
// Show popup
$("#jLoadMe")
.css({'position':'absolute',
'left':pX,
'top':pY,
'background-color':'f8f8ff',
'border':'2px silver ridge',
'padding':3})
.show().mouseenter(function(){
$(this).hide();
});
});
}
function initjLoadMe() { // Loop trough all elements and add hover function
isAppendField = false;
$("div[id^='WebPartWPQ']").each(function(){
var thisListCTX = $(this).find("table[ctxname]:first").attr('ctxname');
if(thisListCTX!=undefined){
thisListCTX = eval(thisListCTX);
var listBaseType = thisListCTX.listBaseType;
if(listBaseType==0){ // List
if(prependHoverImageTo!=''){// Apend style field
whatToFind = "a[href$='SPBookmark_" + prependHoverImageTo + "']";
isAppendField = true;
}else{
var whatToFind = "a[href*='DispForm.aspx'][target='_self']";
}
}else if(listBaseType==1){ // Document library
var whatToFind = "td.ms-vb-title";
}
}else if($(this).find("a[href*='DispForm.aspx']").length>0){ // Catch calendar views
var listBaseType = 0;
var whatToFind = "a[href*='DispForm.aspx'][target='_self']";
}
$(this).find(whatToFind).each(function(){
if($(this).parent().find(".mouseOverImg").length==0){
if(listBaseType==0){
if(isAppendField){
var url = $(this).attr("href");
url = url.substring(0,url.indexOf('#'));
}else{
var url = $(this).attr("href");
if(url.indexOf('#')>-1) return;
}
//$(this).before("<a href='" + url + "'><img class='mouseOverImg' src='" + hoverImg + "' height='8' width='8' border='0'></a> ");
}else if(listBaseType==1){
// Get id of item from table id
var table = $(this).find('table:first');
var tableId = table.attr('id');
var url = eval(table.attr('ctxname')).displayFormUrl+"?ID=" + tableId;
//$(this).find('a').before("<a href='" + url + "'><img class='mouseOverImg' src='/_layouts/images/OPENDB.GIF' height='8' width='8' border='0'></a> ");
}
// Hover function
$(this).parent().hover(function(e){
posX = e.pageX + 10;
posY = e.pageY + 15;
jLoadMe(url,posX,posY,listBaseType)
},
function(){
$("#jLoadMe").html('').hide();
});
}
});
});
}
$(document).ready(function() {
// Add description above ms-bodyareaframe
//if(hoverImgDescription!=''){
// $("#onetidPageTitle").append("<div style='font-size:xx-small;float:right;margin:-12 0 0 0'><img src='" + hoverImg + "' height='8' width='8'> " + hoverImgDescription + " </div>");
//}
$(".ms-bodyareaframe").append("<div id='jLoadMe' style='display:none;'></div>");
window.onerror = handleError; // needed for IE
initjLoadMe();
});
function handleError() { // fn needed for IE
return true;
}
// Attaches a call to the function to the "expand grouped elements function" for it to function in grouped listview's
function ExpGroupRenderData(htmlToRender, groupName, isLoaded){
var tbody=document.getElementById("tbod"+groupName+"_");
var wrapDiv=document.createElement("DIV");
wrapDiv.innerHTML="<TABLE><TBODY id=\"tbod"+groupName+"_\" isLoaded=\""+isLoaded+"\">"+htmlToRender+"</TBODY></TABLE>";
tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody);
initjLoadMe();
}
Friday, June 25, 2010
Redirecting a site in Sharepoint to another site
Redirect a SharePoint site by using the Content Editor Web Part
In the Content Editor Webpart and in the Source Editor in any sharepoint page from where the redirect should happend, add the following script:(1)automatic redirect:
<script language="JavaScript">
alert("This site has been moved to another location, please update existing bookmarks. You will be redirected momentarily.");
window.location.href="http://serverTobeRedirectTo"
</script>
(2)with specific timeframe set:
<script language="JavaScript">
function getgoing()
{
top.location="http://serverTobeRedirectTo";
}
if (top.frames.length==0)
{
alert("This site has been moved to another location, please update existing bookmarks. You will be redirected in 10 Seconds.!");
setTimeout('getgoing()',10000);
}
</script>
Links Referred:
http://www.endusersharepoint.com/2010/01/20/redirect-a-sharepoint-site-by-using-the-content-editor-web-part/
http://www.dnzone.com/go?565
Wednesday, June 9, 2010
Jquery - Reading Data from XML or JSON data types
(2) JSON.JSON:
{
topics:{
topic:[
'Select Topic',
'1 - Testing Json!',
'2 - Analysis Statement',
'3 - Another element',
]
}
}
(3) TOPICS.XML:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<Topics>
<Topic>Select Topic</Topic>
<Topic>1 - Testing Json!</Topic>
<Topic>2 - Analysis Statement</Topic>
<Topic>3 - Another element</Topic>
</Topics>
(4) Jquery would be:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
//Binding Json Data using Jquery
$.getJSON('http://YourServer/DocumentLibrary/json.json', function(data)
{
var numItems = data.topics.topic.length // To Count the number of elements in particular node
//Iterate through all the elements in that particular node
for(i=1;i<numItems;i++)
{
$("<option value='SELECT'>" + data.topics.topic[i] + "</option>").appendTo("#ddlTopic");
//Binding it to another dropdown with id ddlTopic
}
});
//Binding XML data using Jquery
$.ajax(
{
type:"GET",
url:"http://YourServer/DocumentLibrary/Topics.xml",
dataType:"xml",
success:function(xml){
$(xml).find('Topic').each(function(){
var topic = $(this).text();
//Binding it to another dropdown with id ddTopic
$("<option value='SELECT'>" + topic + "</option>").appendTo("#ddTopic");
}); // end each() loop
} // end success
}); // end ajax()
});//end ready()
</script>
Friday, May 28, 2010
Applying a SharePoint Designer Workflow to multiple Lists
Thursday, April 15, 2010
Delete ContentType from a Library
Monday, March 22, 2010
Code Snippets
Wednesday, March 17, 2010
STSADM Commands
Monday, March 15, 2010
TimerJob, Feature Receiver, Feature and Batch Files to Install Timer Job
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace PubFormLibraryTimer {
public class FormLibraryTimerJob : SPJobDefinition
{
private const string Event_Source = "FormLibraryTimerJob";
public FormLibraryTimerJob () : base() { }
public FormLibraryTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base (jobName, service, server, targetType) { }
public FormLibraryTimerJob(string jobName, SPWebApplication webApplication) : base (jobName, webApplication, null, SPJobLockType.ContentDatabase)
{ this.Title = jobName; }
public override void Execute(Guid targetInstanceId)
{
DateTime fromTime = DateTime.Now.AddMinutes(-5);
DateTime toTime = DateTime.Now;
SPWebApplication webApplication = this.Parent as SPWebApplication;
SPContentDatabase contentDb = webApplication.ContentDatabases[targetInstanceId];
SPList formsLibraryList = contentDb.Sites[0].RootWeb.Lists["YourFormLibrary"];
SPQuery oQuery = new SPQuery();
oQuery.Query = "
SPListItemCollection collListItems = formsLibraryList.GetItems(oQuery);
this.LogEventMessage(collListItems.Count);
}
private void LogEventMessage(int count)
{
if (!EventLog.SourceExists(Event_Source))
{ EventLog.CreateEventSource(Event_Source, "Application"); }
EventLog.WriteEntry(Event_Source, "Your Form Library Modified Forms Count In Last 5 mins - " + count.ToString(), EventLogEntryType.Information);
}
}
}
Feature Receiver:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace YourFormLibraryTimer
{
public class FormsLibraryTimerJobFeatureReceiver : SPFeatureReceiver
{
private const string LOGGER_JOB_NAME = "FormLibraryTimerJob"; public override void FeatureInstalled (SPFeatureReceiverProperties properties) { } public override void FeatureUninstalling (SPFeatureReceiverProperties properties) { } public override void FeatureActivated (SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name == LOGGER_JOB_NAME) job.Delete(); } FormLibraryTimerJob loggerJob = new FormLibraryTimerJob(LOGGER_JOB_NAME, site.WebApplication); SPMinuteSchedule schedule = new SPMinuteSchedule(); schedule.BeginSecond = 0; schedule.EndSecond = 59; schedule.Interval = 5; loggerJob.Schedule = schedule; loggerJob.Update(); } public override void FeatureDeactivating (SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name == LOGGER_JOB_NAME) job.Delete(); } } } } Feature: ?xml version="1.0" encoding="utf-8" ? Feature Id="{DD1D417C-746B-4793-BA4E-A95F156E1E30}" Title="Form Library Timer Job" Description="Installs Form Library Timer Job" Version="1.0.0.0" Scope="Site" ReceiverAssembly="YourFormLibraryTimer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=68d32dec24dfb1a9"ReceiverClass="YourFormLibraryTimer.FormsLibraryTimerJobFeatureReceiver" xmlns="http://schemas.microsoft.com/sharepoint/" / Installing Timer Job in Batch Files: @SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template" @SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm" @SET GACUTIL="C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe" Echo Installing PubFormLibraryTimer.dll in GAC %GACUTIL% -if bin\debug\YourFormLibraryTimer.dll Echo Copying files to TEMPLATE directory xcopy /e /y TEMPLATE\* %TEMPLATEDIR% %STSADM% -o installfeature -filename FormLibraryTimerJob\feature.xml -force %STSADM% -o activatefeature -filename FormLibraryTimerJob\feature.xml -force -url http://localhost:91IISRESET
Thursday, March 4, 2010
Adding Columns to a List Programatically
Wednesday, March 3, 2010
Return Items from a List
Wednesday, February 24, 2010
What's New in Infopath 2010
Stay tuned for more details on our new and improved form design features!
Layout your Forms Using Pre-built Page and Section Layouts
Laying out your form and making it look more attractive is now easier than ever. Insert one of our pre-built page layouts to give your form structure. Then, insert some section layouts into the page layout to start building your form.
Page and Section Layouts in InfoPath Designer:
New and Improved Controls
We’ve added some new controls and narrowed the feature gap between client and browser forms, ensuring a more consistent form filling experience for all our users.
Tuesday, February 23, 2010
Batch Files to Retract, Deploy WSPs
Monday, February 22, 2010
Count Forms in each List in a Document Library
Create New Sharepoint Web Service
(2)To create an ASP.NET Web service
a)In Visual Studio, click File, point to New, and then select Web Site. b)In the Templates box of the New Web Site dialog box, select ASP.NET Web Service, select File System in the Location box, select a programming language and location for the project, and then click OK.
C) Within the new Web service solution, create a separate class library project to contain the Web service logic.
[ To create the project, click File, point to New, and then select Project.] In the New Project dialog box, select a language in the Project types box, select Class Library in the Templates box, provide a name and location for the project, select Add to Solution in the Solution box, and then click OK.
D)Add a reference to the System.Web.Services namespace in the class library project. And also Microsoft.SharePoint
E)Replace the default class file in the class library project with the default service class file that Visual Studio provides in the App_Code folder of the Web service. [To replace the class file with the service class file ] In Solution Explorer, drag Service.cs or Service.vb to the top node in the class library project. Delete the Class1.cs or Class1.vb file, and also delete the Service.cs or Service.vb file that remains in the App_Code folder.
F)Create a strong name for the class library:
In Solution Explorer, right-click the class library project, and then click Properties.
In the Properties dialog box, click Signing, select Sign the assembly, and then select
G) To build only the class library project, right-click the project in Solution Explorer, and then click Build.
H) To add your assembly to the global assembly cache (GAC), you can either drag the assembly into the % windows%\assembly directory using 2 instances of Windows Explorer, or use the command line utility gacutil.exe that is installed with the Microsoft .NET Framework SDK 2.0.
To use gacutil.exe to copy the class library DLL into the GAC
To open the Visual Studio command prompt, click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and click Visual Studio 2005 Command Prompt.
At the command prompt type a command in the following form, and press ENTER:
gacutil.exe -if "
I) Now you are ready to modify the assembly information in the default Service.asmx file of the Web service with information for the DLL from the GAC. To get information from the GAC, open the %windows% \assembly directory in Windows Explorer, right-click your assembly, and click Properties.
J) To open Service.asmx in Solution Explorer, right-click the file and click Open. Remove the CodeBehind attribute from the page directive in Service.asmx, and modify the contents of the Class attribute so that the directive matches the following format, where the assembly name "NewAssembly" and the public key token are values specified in the Properties dialog box that you opened in step 10: <%@ WebService Language="C#" Class="Service,NewAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8f2dca3c0f2d0131" %>
K)Rename your .asmx file appropriately, and then save your changes.
3)Generate Static discovery and WSDL files.
In Windows Explorer, copy the .asmx file of your Web service to \\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS.
4)Reset IIS for the DLLs in assembly to take effect.
5)Type in http://Server/_layouts/Service.asmx for the Service and its methods in it.
