Monday, June 30, 2008

Hiding "Send To" option from context menu of document library

Hi All,

May people would like to get rid off Send to link in context menu of document library.

There is very simple way to remove that link. All you have to do is change you core.js file.

Look for AddSendSubMenu(m,ctx) and comment it*.

That's it. You are done with your job.

Note : * Take backup of your core.js before doing this.

Accessing my site data programmatically.

My site is perfect place to store personalize data.
But accessing my site programmatically is not an easy task.

There is always a big question that “How to access my site personalize data programmatically?”

Here is the solution.

First you have to import

Microsoft.Office.Server.dll

We are not using it normally. (At least not me)

Then you have to set
ServerContext context = = ServerContext.Current;
UserProfileManager profilmanager = new UserProfileManager(context);
UserProfile profile = profilmanager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);


This is the way you can find profile of current user.
After getting profile you can use personalize data.

My links
QuickLinkManager qlmanager = new QuickLinkManager(profile);
QuickLink[] ql = qlmanager.GetItems();
Or
profile.QuickLinks.get ;

My Colleague
ColleagueManager colmanager = new ColleagueManager(profile);
Colleague[] cl = colmanager.GetItems();
Or profile.Colleagues.GetItems();

My Membership
MembershipManager memmanager = new MembershipManager(profile);
Membership[] memship = memmanager.GetItems();
Or
profile.Memberships.GetItems();

It works for me.
Try it out.

Correct way to complete task from code in workflow

Hi All,

If you are working with windows workflow foundation, then you might be knowing that you can complete the task by assigning Completed status for workflow item or making the percentage 100.

But there is possibility where task is actually not completed and you set the percentage to 100 or even you set the status to Completed and percentage shows you only 95% done.

This is not the correct way to do it. There is one interesting thing in the code.

See SPBuiltInFieldId enumeration which will give you list of all hidden fields in MOSS that is actually internally referred by MOSS. Sometimes there are certain columns that is having title different and you have to work with them with different name.

Back to our point, this is the way to actually complete the task.

Hashtable data = new Hashtable();
data[SPBuiltInFieldId.Completed] = "TRUE";
data[SPBuiltInFieldId.PercentComplete] = 1;
data[SPBuiltInFieldId.TaskStatus] =
SPResource.GetString(
new CultureInfo( (int)taskListItem.Web.Language, false),
"WorkflowTaskStatusComplete",
new object[0]);

That's it. you are done with your job.

This good solution is given at this link

Office SharePoint Server 2007 Training (Standalone Edition)

Overview

Office SharePoint Server 2007 provides a single, integrated location where you can find documents and resources, create workflows, automate business processes, communicate using blogs and wikis, gain visibility for yourself and your team using team sites and My Sites, and discover shared knowledge to make better informed decisions in your business.

The Office SharePoint Server 2007 Training Standalone Edition is easy to install and use. The Training provides a solid introduction for users unfamiliar with Office SharePoint Server.

To Download Training Click Here



Office SharePoint Server 2007 Training (Standalone Edition)

Overview

Office SharePoint Server 2007 provides a single, integrated location where you can find documents and resources, create workflows, automate business processes, communicate using blogs and wikis, gain visibility for yourself and your team using team sites and My Sites, and discover shared knowledge to make better informed decisions in your business.

The Office SharePoint Server 2007 Training Standalone Edition is easy to install and use. The Training provides a solid introduction for users unfamiliar with Office SharePoint Server.

To Download Training Click Here



Friday, June 27, 2008

Disabling formatting options in RichHTML Field in MOSS

Hi All,

If you want to disable several formatting options in RichHTML filed, lets say you do not want user to use any of the table options, you do not want user to use images options, no font options then you can do this in following way :

<div class="contentpagecontent">
<PublishingWebControls:RichHtmlField
FieldName="PublishingPageContent"
AllowTables="false"
AllowImages="false"
AllowFonts="false"
runat="server"></PublishingWebControls:RichHtmlField>
</div>


Look at this snap after applying these options :




If you want to go for more customization, then here is a link.

That's it. you are done with your job.

Disabling formatting options from RichHTML field in MOSS

Hi All,

If you want to disable several formating options like if you do not want to allow user to use table options, you do not want to allow user to use images option, then you can do it in following way :

<div class="contentpagecontent">
<PublishingWebControls:RichHtmlField
FieldName="PublishingPageContent"
AllowTables="false"
AllowImages="false"
AllowFonts="false"
runat="server"></PublishingWebControls:RichHtmlField>
</div>

This now disables the specified icons on the toolbar

Have a look at this image

Thursday, June 26, 2008

Increase size limitation for saving site as template

Hi All,

One more thing in this.

The hard limit for site template is 524288000 Bytes. that is 500 Mb. you cannot have more than that.

This limitation applies both for site template and list template both.

Above is Updated Content on 26-Jun-08.


Hi All,

sometimes you may find that you are not able to save your site as a template because of size limitation.

Here is a way from which you can increase the size of template to save.

stsadm -o setproperty -pn max-template-document-size -pv 40000000

numbers should be given in Bytes

That's it. there you go. Now go and save your site!!!!

Tuesday, June 24, 2008

Project start date in project center PWA.

Entire project plan is depend on Project start date.

And there are a lot of issues related to project start date in project server 2007.

Here we go to step by step.
1) Create a project.
2) Set start date of the project.
3) In MS Project we can set start date from Project -> project information -> start date. By default it will take today’s date.
4) For developers this date will save in PROJ_INFO_START_DATE in Project dataset.
5) Now you create tasks with some specific start date or successors and all that.
6) After that, publish that project to PWA.

In project center screen or PWA start and finish date will show different dates.

Logically it should show date from project info start date.
But it shows the minimum date from all tasks’ start date and maximum date from tasks end date.

There is no any other way to have project info start date (PROJ_INFO_START_DATE) from DB in Project center.

The only solution to overcome this situation we can create a custom field of the project.

Save project info start date in that newly created field and change the view project center web part.

Hiding quick launch bar in MOSS

Hi All,

There is a way you can hide a quick launch bar in MOSS 2007.

Here are the steps to follow:

(1)Add content editor webpart on page
(2) Click on Modify shared webpart
(3) Click on source editor button
(4) Copy and paste the following HTML

<style>
.ms-quicklaunch
{
display:none;
}
.ms-navframe
{
display: none;
}
</style>

(5)Go to layouts section of that webpart and select Hidden.

That's it. Now no more quick launch bar !!!!!

If you want to get quick launch back, just again edit the page and go to modify shared webpart of content editor webpart. Go to source editor button and remove all HTML content and save it.

That's it. Now you will have your quick launch back in place !!!

Automate the backup process by using a batch file (Microsoft Office SharePoint Server 2007)

Hi All,

I came across a very good article on Backup Process for a MS office SharePoint Server 2007. Below is a gist of the same.

It is not possible to schedule backups from the SharePoint Central Administration Web site. There is no operation that enables you to automate backups by using the Stsadm command-line tool. You can, however, automate the process by creating a batch file and then using Task Scheduler in Microsoft Windows Server 2003 to run the batch file at a specific time. Because performance can be affected when doing backups with the Microsoft Office SharePoint Server 2007 built-in tools, you might want to schedule your backups for off-peak times such as at night or on weekends.

Create a batch file to perform a backup of Office SharePoint Server 2007
Use this procedure to create a batch file that will run a full backup of your Office SharePoint Server 2007 server farm. This procedure assumes that you have already created a shared folder for your backups. For more information about how to create a shared folder, see the following article Prepare to back up Office SharePoint Server 2007.

To create a batch file

1. Click Start, and then click Run.
2. Type notepad, and then click OK.
3. In Notepad, type the following text:

@echo off
echo ===============================================================
echo Back up sites for the farm to D:\backupSharePoint
echo ===============================================================
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
cd c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
@echo off
md "%DATE:/=_%"
%STSADM% -o backup -directory "D:\backupSharePoint\%DATE:/=_%" -backupmethod full -overwrite
echo completed



Note : Change "C:\backup" and "\backup" to the name of your backup shared folder.


4. In Notepad, on the File menu, click Save As.
5. In the Save As box, select the folder where you want to keep your batch file.
6. Using the ".bat" file name extension, type the name of the file in the File name box, for example, backup_batch.bat.
7. In the Save as type box, click All files.
8. Click Save.


Use Task Scheduler to run a batch file that backs up Office SharePoint Server 2007

Use this procedure to schedule backups of your Office SharePoint Server 2007 server farm in Task Scheduler.

Because system performance can be affected when you do complex operations such as backups with the Office SharePoint Server 2007 built-in tools, you might want to schedule your backups for off-peak times, such as at night or on weekends.

To schedule a backup

1. Click Start, and then click Run.

2. Type control, and then click OK.

3. Double-click Scheduled Tasks.

4. Double-click Add Scheduled Task.

5. When the Scheduled Task Wizard appears, click Next.

6. Click Browse, and then browse to and select the batch file that you just created. (See IMAGE-1)



7. Click Open.

8. Type a name for your task, for example, backup_batch. (See IMAGE-2)



9. Select how often you want this task performed (for example, weekly), and then click Next.

10. Select a day and time that you want this task to begin, and then click Next.

11. Enter a name and password for a user, and then click Next. This task will run as if it were started by that user.

12. Click Finish. (See IMAGE-3)






Notes
• To perform this procedure, you must be a member of the Administrators, Backup Operators, or Server Operators group, or have been delegated the appropriate authority, on the local computer. As a security best practice, consider using the Run as command to perform this procedure.

• When creating a scheduled task, you must enter a user name and password, either in the Add Scheduled Task Wizard or in the Run as box on the Task tab of the properties dialog box for the scheduled task. When the scheduled task runs, the program runs as if it were started by the user you specified, with that user's security context.

• To open Task Scheduler, click Start, click Control Panel, and then double-click Scheduled Tasks.

• Confirm that the system date and time on your computer are accurate, as Task Scheduler relies on this information to run scheduled tasks. To verify or change this information, double-click the time indicator on the taskbar.

• To configure advanced settings for the task, select the Open advanced properties for this task when I click Finish check box in the final page of the wizard. This opens the properties dialog box for the task when you click Finish. You can then change the program being run on the Task tab, fine-tune the schedule on the Schedule tab, customize settings on the Settings tab, or set user and group permissions on the Security tab.

Reference:
http://technet.microsoft.com/en-us/library/cc262562(TechNet.10).aspx

Monday, June 23, 2008

Adding Multiple Lookup field by code in Sharepoint

Hi all,
here is simple code to add Multiple lookup fields by code in SharePoint
SPFieldLookupValueCollection spConnectionMethod = new SPFieldLookupValueCollection();
foreach (ListItem li in rdbconnection.Items)
{
if (li.Selected)
{
spConnectionMethod.Add(new SPFieldLookupValue(Convert.ToInt32(li.Value.ToString().Split('@')[0].ToString()), li.Text));
}
}
litem["Connection"] = spConnectionMethod

Thursday, June 19, 2008

How to change file ordering in document library?

Hi All,

Lets take an example where you may need this kind of tricks to do.

When you add documents in document library it serves document as First entry is last in your document library. means the document that you have added first will also go last. Next document will be before that last document. so the bottom line is oldest document uploaded or created will be the last document in document library.

If you want to order them, means Lets say you want specific document to come first, then specific document to come second.. like this then here is the trick...

(1) Make one column in that document library.
(2) Name it "Sort By"
(3) Give preference number of your document
(4) Modify the default view with sort by column in your specific order

That's it. Now you will always have your documents at your wanted positions.

Tuesday, June 17, 2008

Change default redirection in an ECB Menu

MOSS 2007 and Core.js File
Change default redirection in an ECB (Edit Control Block) Menu.

I am sure lots of people would be wondering how to Change default redirection in a ECB Menu items of a list eg On clicking the "Title Column hyperlink" or the ”View Item” in ECB(Edit Control Block) Menu, the redirection must be to a different location.

For this the modifications needs to be done in CORE.JS file located at "C:\Program Files\CommonFiles\MicrosoftShared\webserver extensions\12\TEMPLATE\LAYOUTS\1033\CORE.JS"


NOTE: Make sure you take back up of Core.js file before making any change in order to prevent any server functionality malfunction.


1) Clicking on Title Column hyperlink of a List Item
Default Sharepoint Navigation:
On clicking on the Title Column, SharePoint takes you to the DispForm.aspx page.

See below Image:


The default navigation is done by the function "GoToLink(elm)" present in core.js

Place alerts in the core.js and understand each of the parameters.
Eg. To navigate to a different page, assign the destination url to the targetUrl
String.


See below Image:




ECB(Edit Control Block) Menu Navigation.
2) Clicking on “View Item” of a List Item in the ECB menu
Default Navigation:
On clicking on the View Item in the ECB menu, SharePoint takes you to the DispForm.aspx page.

The default navigation is done using function “AddSharedNamespaceMenuItems(m, ctx)” in present in customcore.js

Place alerts in the core.js and understand each of the parameters.
Eg. To navigate to a different page, assign the destination url to the strAction
String.


Same as you did for the "Title Column hyperlink".

If you are confused....we kings are here...

Limitation of Send Mail activity in workflow and its solution

Hi All,

There is one limitation of Send Mail activity if you are working with workflow.( Currently i don't know any other limitations :) .once i come to know i would like to post them..so just wait...)

Limitation is that you cannnot send attachment with sendmail activity.

so if your requirement is to send attachment in workflow, take your hand off from sendmail activity. Instead use code activity and use System.Net.Mail by using MailMessage class to send a mail.

Simple solution , isn't it!!!

Monday, June 16, 2008

Breaking long column names in moss

The scenario:
Recently I came across the requirement in which one of our lists has a very big name of the column.
So our look and feel is messed.

The Requirement:
Now what my requirement is I need to break this column name in two lines in “NEW” and “Edit” Mode.
Example- Name of the column is “this is very long name of the column and i want to splilt it“

The Challenge.
Now I have to find the way to break it!!!

First I tried to change the name from “this is very long name of the column and i want to splilt it”
To “this is very long name of<br>the column and i want to spilt it”

But failed. Because while rendering it replaces < to “& lt;” and > to “& gt;”

Now
What I had observer is that while checking in view source the name of the column is rendered in between <nobr> </nobr> tag.
So I there is no chance to break it with my first idea.

The Solution.
I found a strange way to resolve this.
What you have to is that do it with java script.

In java script while loading the page you have to find that label and change it with a BR tag manually.

I will tell you how to do it.
First you have to call java script in this page.
You can do that by
Creating a custom control using .aspx here is the way.
Or create a web part and put it on the list page.(Check This)
Note: for Creating a webpart with user control .ascx (go to this site)

In that .ascx of web part or custom control, you need to find all elements for <nobr>
And find the original text.
And replace this text means inner html of of<nobr> with new text which include <br>
So while rendering it breaks up even if it was on <nobr>.
Using simple JavaScript in SharePoint check this article

Here the sample java script.

// this is default SharePoint function
//it will call after page is loaded.
_spBodyOnLoadFunctionNames.push("split");


//this function finds all <nobr> tag
//then check our original text and
//replace new text which contains <br>
function split()
{
var oP = document.getElementsByTagName('nobr');//the collection of <p> tags
for(var i=0;i<oP.length;i++)
{
//alert(oP[i].innerHTML);
if(oP[i].innerHTML == "this is very long name of the column and i want to splilt it")
{
oP[i].innerHTML = "this is very long name of<br>the column and i want to splilt it"
}
}
}

How to get a thumbnail view of an Image?

Hi All,

In MOSS we have picture library where we can upload images. But there is no way where you can display thumbnail view of an image.

All you have to do is just append “_t” to directory and convert period in filename with underscore character and append images extension.

Here are the samples:

If the Image URL is:

"http://server/site/mysite/PictureLibrary/testPic.gif"

Change it to

"http://server/site/mysite/PictureLibrary/_t/testPic_gif.gif"

You can also use _w instead of _t. This will give you larger image.

This idea is given by Robert Bogue (MVP)

Friday, June 13, 2008

Dragging Left navigation Bar in MOSS 2007

Hi All,

Let me give you a scenario where you may need this kind of feature available. Lets say you are having a long named List Or document library, at that time you will find that name will break to the next line. (See below image)




Let me give you better example. In your document library you are having many folders. Inside each folders you have many other folders as well.

Now you would definitely not like the default structure of left navigation menu. So we can change it to TreeView so that we can explore the things around. But here also you will face one problem. Problem in terms of scrolling horizontally left to right and right to left. How nice will it be if you get something like Arrow from which you can just drag the left navigation bar to any amount to right side so that you get rid of scrolling.

For this you need to place one javascript in master page (default.master). If you have customized master page, then change in that master page.

Note : Make sure that you place this javascript after </BODY> tag. That means between </BODY> and </HTML> tag in master page.

Here is a link from where you can download this javascript.

Click Here to Download

Have a look at this snapshot taken from my PC.



This script will automatically saves the previous location of scrolled position so that it doesn't get lost between server trips.

When you move your mouse pointer to that area between content page and left navigation bar, you will notice that cursor gets changed and now you can drag according to your convenience.

EURO CUP 2008 Web Part for MOSS 2007

Hi All,

Are you a Fan of EURO CUP? Well there you go. It’s very good news for EURO CUP lovers. Officially EURO has given a special service to be used in web part so that it gets available in your MOSS site.

All you need to do is this.

Go to this link

Register yourself. Please at least give e-mail Id correct otherwise you will not get the Key to activate this web part.

Soon you will get one e-Mail. In Email you will find your username, Password and one Key that you will need when you will use this web part on page. Username and Password will be same as you have given at the time of registration. Now go back to your mail and check there will be one more link

Click Here

Go to this link and enter your credentials that you got from mail and download that web part. That page will give you two options one is for SharePoint 2003 and right hand side there is one with MOSS 2007, download appropriate web part. When you download you will also find ReadMe.txt with it. Just read it, it’s very simple. It’s a WSP file so deploy it as solution using -o addsolution command of STSADM and then deploy solution with solution Management in Operations tab in your central administration. There you will find an option saying Choose a web application to deploy this solution. So select the web application for which you are enabling this web part.

And there you go, now go to any site in that web application, edit the page, and add that web part, and modify that web part and give key as property that you got in Mail. You can also give Proxy Settings in

You will get 3 web parts in miscellaneous category. (1) EURO 2008 Admin (2) EURO 2008 Game (3) EURO 2008 Ranking.

This is the screen shot taken from my system. Have a Look at them.



You have to place EURO 2008 Admin webpart in your own "MySite", it will not allow you to use it as public site.

Backup and Restore Problem

Hi,

here is a case when you want to restore WSS 3.0 site with Content database in SQL Server 2000 to wss 3.0 with Default Embadded Edition Microsoft##SSEE.


I have server "A" (Old server) where WSS 3.0 are installed. I have 2 sites created in WSS 3.0 and I have SQL Server 2000 on server "A".
Now I want to restore these four site on new server called "B" where WSS 3.0 installed with Default Microsoft##SSEE Sql instance.
so what should I do which is better and effective way to do this?
as there are two over load of backup from stsadm command in wss 3.0 which should I use.
1.Stsadm.exe -o backup -url http://a/ -filename "c:\backup\a_80.bak"
2.stsadm.exe -o backuo -backupmethod "full" -directoryname "c:\backup"
which one should I use?.
using second method of backup while restore on new server "B" I am getting error [SPManager] [ERROR] [6/9/2008 8:40:11 AM]: The signature of the public key is invalid.
Signing object:[dbo].[AllDocs]
[SPManager] [ERROR] [6/9/2008 8:40:11 AM]: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

while restoring WebApplication is successfully created but in second phase when it trying to attach contentdb with this webapplication it fires an error that remote connection is not enabled because its Microsoft##SSEE instance.

Solution is take backup from first method.. i.e.

1.Stsadm.exe -o backup -url http://a/ -filename "c:\backup\a_80.bak"

and restore it..

Using simple JavaScript in SharePoint

JavaScript is the headache for most of the .Net users.
And when it comes to SharePoint than it become worst.

Here I am posting how to use JavaScript to find element in SharePoint webpart or custom control.

Note: here we are using (usercontrol). ascx page for creating webpart or custom control.
For information check this link.

In generic ASP.Net we can use
document.getElementsById” or
document.getElementsByName
to finding any controls or object.

But in SharePoint we cannot do the same.
In SharePoint we have to do something extra.

Here the details with example.
First what we have to do is that declare a variable for document.forms[0].
var objForm = document.forms[0];

Now we have loop through all the element of that document.
So for loop execute until all elements parsed.
We can find all elements by objForm.elements.length
Now in each control if you check source of that page which contain webpart then you can find
Each and every control has type
Like text box has type “Text”
Dropdown has type “Choice”
And etc…
Find particular object in that for loop like this way (this example for text box)
if (objForm.elements[j].type == "text" && objForm.elements[j].id.indexOf("_dtpDateTimeDate") != -1)

means an object with type is “text” and its id contains “_<<the id given by you>>”
that will be your object which you are looking for.
You can get its value by (alert is just to prompt)
alert(objForm.elements[j].value);

You can set and get value of that control or object.

You can call this script by onload of the window or by adding attribute of control and all that.

Here only thing to check is that
You have to add this script tag for your script to work in different browser.
<script language="javascript" type="text/javascript"> var isNS = (navigator.appName == "Netscape") ? 1 : 0; if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP); function mischandler(){ return false; } function mousehandler(e){ var myevent = (isNS) ? e : event; var eventbutton = (isNS) ? myevent.which : myevent.button; if((eventbutton==2)||(eventbutton==3)) return false; } document.oncontextmenu = mischandler; document.onmousedown = mousehandler; document.onmouseup = mousehandler; </script>

Here is the whole script

<!—first tag for cross browser functionality - ->
<script language="javascript" type="text/javascript"> var isNS = (navigator.appName == "Netscape") ? 1 : 0; if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP); function mischandler(){ return false; } function mousehandler(e){ var myevent = (isNS) ? e : event; var eventbutton = (isNS) ? myevent.which : myevent.button; if((eventbutton==2)||(eventbutton==3)) return false; } document.oncontextmenu = mischandler; document.onmousedown = mousehandler; document.onmouseup = mousehandler; </script>

<!—to start our script - ->
<script language="javascript" type="text/javascript">

//getting document form
var objForm = document.forms[0];

//calling this function on onload

window.onload = getobjectvalue;

//here I’m checking the date because date will be the most complex
//if you check the source then SharePoint date picker is itself textbox and an image with JavaScript
//so we can populate sharepoint date value by this and make any validation with date.
// we can also call this function on date changed or any button click. (Basic fundamentals)

function getobjectvalue();
{
for (j = 0; j < objForm.elements.length; j++)
{
if (objForm.elements[j].type == "text" && objForm.elements[j].id.indexOf("_dtpDateTimeDate") != -1)
{
Var TaskStartDate = objForm.elements[j].value;
alert('task start date : '+ TaskStartDate );
}
}

}
</script>

You can also use this script in custom control prepared with (usercontrol) .ascx.

Have fun.....

Thursday, June 12, 2008

Integrating GoogleMap in your Site

Hi All,

There is a interesting webpart of GoogleMap. Just integrate in your page and there you go, you have all facilities to Zoom in , zoom out and exploring entire world at one GO!!!!.

To Set the default country and place, set its Latitude and Longitude to that place if you know.

To download webpart Click Here

Here is how it looks like in my PC. have a look at it.

InfoPath using Web Service Data connection

Hi,

Read the following scenario you probably come across while development InfoPath using Web Service Data Connection. (Here I assume you know how to create Web Service Data connection using InfoPath 2007)

I have created one InfoPath form in my local machine, where I am filling dropdown from web service of my local machine,

For that I am creating data connection library, but it takes design time web service URL reference in data connection.

Now I want to publish this form to server, but on server it is not working because it considers local web service URL.

On server I have created same data connection library and change the web service reference in all .udcx file but still form template take web reference which I have added design time.

Because In my local machine web service URL is different and on server web service URL is different.

When I try to see preview of my InfoPath template on server it shows following message

"One or more data connection in your form are specified with server-relative link, but no published location has been defined for the form. Data connection will retrieve data from the server specified in design time. To enable server-relative link publish your form to Microsoft Office server"

I have divided this solution in two parts.

1. Create Web service Project (i.e. here I have created web service as Library it will generate .dll file assembly for web service not web service as web application) .Here we will use Web Service Template if you don’t have install this template please download it to create Web Service Project. You can see template in picture.


Now create project like this


Give Strong name to this Assembly.

Deploy it into a GAC .Now open MyService.asmx file in Notepad and replace <%@WebsService /> Tag with following according to your project here is one sample.

<%@ WebService Language="C#" Class="SharePointKings.MyService, SharePoiintKings, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=bce3f92a230905aa" %>

Now create one Directory in 12/Template/Layouts Directory Name in Our case we will create

Directory “SharePointKings” under this directory put .dll from your project in our case it will be SharePointKings.dll.

Now from RUN write “inetmgr” now suppose your site Directory name is “2020” expand this site go to Layouts under Layouts now you will find directory called “SharePointKings” as we created it under 12/Template/Layouts so it will listed here. Now create virtual directory SharePointKings from here.

In first part we have created our web service as Assembly and configure it to use in InfoPath Web service data connection.

2. Now here I assume you know how to create Web service data connection and you want to populate dropdown list from web service.

When you open InfoPath Code Project and from this code project right click on project add Web Reference.

As we have assume that our site port is “2020” so our site URL is like this “http://servername:2020” and add reference http://servername:2020/_layouts/SharePointKings/Myservice.asmx now all web methods will be listed there. Name this web reference “MyService”

Ok now as you add this web reference you will find few additional files created in your InfoPath Code Project in which one is “Reference.cs” open this file you will find default constructor now add second additional constructor which take parameters for Web Reference URL.

public MYService(string WebseriveUrl)

{

this.Url = WebseriveUrl;

if ((this.IsLocalFileSystemWebService(this.Url) == true))

{

this.UseDefaultCredentials = true;

this.useDefaultCredentialsSetExplicitly = false;

}

else

{

this.useDefaultCredentialsSetExplicitly = true;

}

}

Now in your InfoPath Form Load Event Write Following code.

First we Create Dynamic URL For WebService like this so it works for our testing server as well in production server we don’t need to change any thing in code so, here we are creating dynamic URL though we have given hard coded refrecnce while adding web referce.

public void FormEvents_Loading(object sender, LoadingEventArgs e)

{

try

{

string webserviceurl = string.Empty;

webserviceurl = SPContext.Current.Site.Url + "/_layouts/SharePointKings/MYService.asmx"; ExecuteConnection("YourConnectionName",webserviceurl);

}catch(Exception ex){throw ex;}

}

private void ExecuteConnection(string ConnectionName,string WebServiceUrl)

{

WebServiceConnection cn = (WebServiceConnection)this.DataConnections[ConnectionName];

string url = WebServiceUrl;

UriBuilder uri = new UriBuilder(url);

cn.ServiceUrl = uri.Uri;

cn.Timeout = 60;

cn.Execute();

}

This way you can execute Web service connection yousing dynamic web service URL.you don’t need to change any code while deploying your code to production server .

download in word format

Calling SharePoint webservices like lists.asmx using javascript

function QueryListEx(listGuid, fields, where, orderBy, rowLimit, extractRows)

  1. {
  2. var a = new ActiveXObject("Microsoft.XMLHTTP");
  3. if(a == null) return null;
  4. a.Open("POST", GetRootUrl() + "_vti_bin/DspSts.asmx", false);
  5. a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  6. a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/dsp/queryRequest");
  7. var d = ''
  8. + "
  9. + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
  10. + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\/\">"
  11. +" "
  12. +" "
  13. +" 1.0"
  14. +" "
  15. +"
  16. +" service=\"DspSts\" document=\"content\" method=\"query\">"
  17. +" "
  18. +" "
  19. + ""
  20. + "
  21. +" xmlns=\"http://schemas.microsoft.com/sharepoint/dsp\">"
  22. +" + listGuid + "']\""
  23. +" resultContent=\"dataOnly\""
  24. +" columnMapping=\"attribute\" resultRoot=\"Rows\" resultRow=\"Row\">"
  25. +" + rowLimit + "\">"
  26. +" " + fields + ""
  27. +" " + where + ""
  28. +" " + orderBy + ""
  29. +" "
  30. +" "
  31. +" "
  32. + ""
  33. + "";
  34. a.Send(d);
  35. if (a.status != 200)
  36. return null;
  37. else
  38. {
  39. if (extractRows)
  40. return a.responseXML.selectNodes('//Row');
  41. else
  42. return a.responseXML;
  43. }
  44. }


function GetRootUrl()
{
var pathparts = document.location.pathname.split('/');
var url = 'https://' + document.location.hostname + '/' + pathparts[1] + '/';

return url;
}

special thanks to (click here for more help)

Error while click on Search Setting from SSP from central admin

Hi to over come this error do following things.
Make sure that Search service is running from central admin
  1. Go To Run.
  2. write Services.msc
  3. Find Office SharePoint Search
  4. right click it and open LogOn Tab
  5. give admin user name and password or user who have rights on content database server.
for more see
Click here for more
Click here
Let me know your comments...


Monday, June 9, 2008

Enable Incoming Email within SharePoint 2007

SharePoint 2007 allows for emails to be accepted into discussions, document libraries and lists. To enable this functionality, a few steps will need to be followed. One thing to note: integrating SharePoint with Exchange is NOT needed for this functionality, but if you do choose Exchange, you will get some added benefits.



-SMTP Service

You will need to install the SMTP Server Service on the SharePoint server. This is done via add/remove programs, and within the IIS component listing.



-Enable Incoming Email

Now, enable Incoming Email from the Central Administration website. It is found by following: Central Administration > Operations > Incoming Email Settings



-SMTP Connector

You will finally need to configure an SMTP connector within your email server so it knows where to send emails you designate for SharePoint.

Create a project in project server programmatically

Here is the way how programmatically create a project in project server 2007 (PWA) step by step using PSI.

For creating a project you have to use “_vti_bin/psi/Project.asmx” web service.
To use any PSI web service first you have to login to the server. Check my previous post

Project server has predefined database structure.
So for creating a new project we need t o create a new row in project table.
This row has many columns but only few are required for input and others are non mandatory or filled atomically.

Here are that fields
PROJ_UID : new GUID for project.
PROJ_NAME : name of the project which should be unique.
PROJ_INFO_START_DATE : it is not mendatory but every project must have start date other wuse it will take system date.
PROJ_TYPE : this is important. There are two type of porject in project server one is project and other is Template. For project its value is 0 and for template its value is 1. So we are using 0 as we are creating a project.

then this field value in row we have to add this row in project table.

After that project.asmx have a method called QueueCreateProject.
This method will create a project in draft database and push the argument in Project server Queue.

After generating project in draft database we need to publish that project.
For publishing project we have to call QueuePublish method from Project.asmx
Note: Only published project is available to user in PWA.

And last operation after publishing project we need to do is “check in the project”
Checked out project is visible to user but cannot be editable by any one. For check in the project there is also another method in project.asmx QueueCheckInProject
And as per experienced developer we have to logofffrom PSI server.
Here is the snippet for creating project in project server (PWA).
private WebSvcProject.ProjectDataSet dsProjectDataSet = null;
private Project objProject = null;
private bool CreateProject()
{

try
{
//for creating a new we need to create a new row in project table of project dataset
WebSvcProject.ProjectDataSet.ProjectRow projectRow = dsProjectDataSet.Project.NewProjectRow();
Guid _projectGUID = Guid.NewGuid(); // new GUID for each project
projectRow.PROJ_UID = _projectGUID;
projectRow.PROJ_NAME = "My new Project";
projectRow.PROJ_INFO_START_DATE = System.DateTime.Now;
projectRow.PROJ_TYPE = 0; //0 is for project and 1 is for template
dsProjectDataSet.Project.AddProjectRow(projectRow);

//create a project using project.asmx
objProject.QueueCreateProject(Guid.NewGuid(), dsProjectDataSet,
false);

//after creating project by default it is in draft
//we must have to publish the project
objProject.QueuePublish(Guid.NewGuid(), _projectGUID, true, string.Empty);

//when project is created bu default it is checked out
// we must checkin the project.
objProject.QueueCheckInProject(Guid.NewGuid(), _projectGUID, true, Guid.Empty, "Checking by system");

return true;
}
catch (Exception ex)
{
//log error
return false;
}
}

SQL Queries for SharePoint Content Database

Hi All,

The Sharepoint Content Database build up on SQL Server and has a good set of Tables.
These can be accessed and the data can be retrived just as any other SQL database.
Here are some useful queries that will help you.

NOTE: Never update any SharePoint database directly. Always use the SharePoint API (Object Model) for any updates.


When you will open the Sharepoint Database you will see a set of tables.Eg the ImmedSubscriptions table Ref the screen shot below.



We will begin with some of the basic tables.

Features Table that holds information about all the activated features for each site collection or site.

Sites Table that holds information about all the site collections for this content database.

Webs Table that holds information about all the specific sites (webs) in each site collection.

UserInfo Table that holds information about all the users for each site collection.

Groups Table that holds information about all the SharePoint groups in each site collection.

Roles Table that holds information about all the SharePoint roles (permission levels) for each site.

AllLists Table that holds information about lists for each site.

GroupMembership Table that holds information about all the SharePoint group members.

AllUserData Table that holds information about all the list items for each list.

AllDocs Table that holds information about all the documents (and all list items) for each document library and list.

RoleAssignment Table that holds information about all the users or SharePoint groups that are assigned to roles.

SchedSubscriptions Table that holds information about all the scheduled subscriptions (alerts) for each user.

ImmedSubscriptions Table that holds information about all the immediate subscriptions (alerts) for each user.



Some of the common queries that can be used against the content database:

-- Query to get all the top level site collections
SELECT SiteId AS SiteGuid, Id AS WebGuid, FullUrl AS Url, Title, Author, TimeCreated
FROM dbo.Webs
WHERE (ParentWebId IS NULL)

-- Query to get all the child sites in a site collection
SELECT SiteId AS SiteGuid, Id AS WebGuid, FullUrl AS Url, Title, Author, TimeCreated
FROM dbo.Webs
WHERE (NOT (ParentWebId IS NULL))

-- Query to get all the SharePoint groups in a site collection
SELECT dbo.Webs.SiteId, dbo.Webs.Id, dbo.Webs.FullUrl, dbo.Webs.Title, dbo.Groups.ID AS Expr1,
dbo.Groups.Title AS Expr2, dbo.Groups.Description
FROM dbo.Groups INNER JOIN
dbo.Webs ON dbo.Groups.SiteId = dbo.Webs.SiteId

-- Query to get all the users in a site collection
SELECT dbo.Webs.SiteId, dbo.Webs.Id, dbo.Webs.FullUrl, dbo.Webs.Title, dbo.UserInfo.tp_ID,
dbo.UserInfo.tp_DomainGroup, dbo.UserInfo.tp_SiteAdmin, dbo.UserInfo.tp_Title, dbo.UserInfo.tp_Email
FROM dbo.UserInfo INNER JOIN
dbo.Webs ON dbo.UserInfo.tp_SiteID = dbo.Webs.SiteId

-- Query to get all the members of the SharePoint Groups
SELECT dbo.Groups.ID, dbo.Groups.Title, dbo.UserInfo.tp_Title, dbo.UserInfo.tp_Login
FROM dbo.GroupMembership INNER JOIN
dbo.Groups ON dbo.GroupMembership.SiteId = dbo.Groups.SiteId INNER JOIN
dbo.UserInfo ON dbo.GroupMembership.MemberId = dbo.UserInfo.tp_ID

-- Query to get all the sites where a specific feature is activated
SELECT dbo.Webs.Id AS WebGuid, dbo.Webs.Title AS WebTitle, dbo.Webs.FullUrl AS WebUrl, dbo.Features.FeatureId,
dbo.Features.TimeActivated
FROM dbo.Features INNER JOIN
dbo.Webs ON dbo.Features.SiteId = dbo.Webs.SiteId AND dbo.Features.WebId = dbo.Webs.Id
WHERE (dbo.Features.FeatureId = '00BFEA71-D1CE-42de-9C63-A44004CE0104')

-- Query to get all the users assigned to roles
SELECT dbo.Webs.Id, dbo.Webs.Title, dbo.Webs.FullUrl, dbo.Roles.RoleId, dbo.Roles.Title AS RoleTitle,
dbo.UserInfo.tp_Title, dbo.UserInfo.tp_Login
FROM dbo.RoleAssignment INNER JOIN
dbo.Roles ON dbo.RoleAssignment.SiteId = dbo.Roles.SiteId AND
dbo.RoleAssignment.RoleId = dbo.Roles.RoleId INNER JOIN
dbo.Webs ON dbo.Roles.SiteId = dbo.Webs.SiteId AND dbo.Roles.WebId = dbo.Webs.Id INNER JOIN
dbo.UserInfo ON dbo.RoleAssignment.PrincipalId = dbo.UserInfo.tp_ID

-- Query to get all the SharePoint groups assigned to roles
SELECT dbo.Webs.Id, dbo.Webs.Title, dbo.Webs.FullUrl, dbo.Roles.RoleId, dbo.Roles.Title AS RoleTitle,
dbo.Groups.Title AS GroupName
FROM dbo.RoleAssignment INNER JOIN
dbo.Roles ON dbo.RoleAssignment.SiteId = dbo.Roles.SiteId AND
dbo.RoleAssignment.RoleId = dbo.Roles.RoleId INNER JOIN
dbo.Webs ON dbo.Roles.SiteId = dbo.Webs.SiteId AND dbo.Roles.WebId = dbo.Webs.Id INNER JOIN
dbo.Groups ON dbo.RoleAssignment.SiteId = dbo.Groups.SiteId AND
dbo.RoleAssignment.PrincipalId = dbo.Groups.ID


If you come accross any useful queries do let me know.

In FBA When I open document from Document Library Login Page Display in document itself.

Hi,
some time you may come accross the situation when you are using Form Base Authentication(FBA) and after Login when you open document from document library document itself open login page inside.
Problem is because of IE (internet explorer) when you login using form base authentication cookie is saved inside browser not on your machine.so that cookie is not available to your document which open outside browser.
To overcome this problem save cookie on your machine. or persist
In FireFox it will not happen.

Friday, June 6, 2008

How to use PSI web service?

For any development regarding project server 2007 or project web access (PWA), we need to use PSI (project service interface) provided by project server.

There are many web service provided for different- different operation. Here is the MSDN link for Finding the PSI Web Services.

But first question is How to use PSI web service?
For that you need to login first for using any of the web service.

So here is the post how to login to use PSI web service?

For login we have to use “_vti_bin/PSI/LoginWindows.asmx” web service.

Here is the code snippet to login using loginwindows.asmx
private LoginWindows objLoginWindows = null;
private void button8_Click(object sender, EventArgs e)
{
if (Login())
{
//go ahead
}
else
{
//throw login failed error
}
}

private bool Login()
{
try
{
SetCredentials();
return objLoginWindows.Login();
}
catch (Exception ex)
{
return false;
}
}

private void SetCredentials()
{
try
{
objLoginWindows.Url = "http://pwaserver:7777/pwa/_vti_bin/PSI/LoginWindows.asmx";
//use dynamic referance and use url from web/app.config
objLoginWindows.Credentials = CredentialCache.DefaultCredentials;
//DefaultCredentials will use curently login user
}
catch
{
//log your error;
}
}

This way you can log in using loginwindows.asmx

After login successfully you can use any other web service according your permission.

Note: you have to need login every time whenever you want to access PSI.
Note: its good practice to log off using Logoff() method of the same loginwindows.asmx after completion of your work.
objLoginWindows.Logoff();

Alternative to SharePoint Products and Technologies Configuration Wizard

Hi All,

There is one more alternative way to work around for SharePoint Products and Technologies Configuration Wizard. Its One and Only STSADM Command. I wonder , what a superb power this command is having!!!!!!

In SharePoint Products and Technologies, you can use the psconfig.exe command-line tool as an alternate interface to perform several operations that control how the SharePoint Products and Technologies are configured. You must be a member of the Administrators group on the local computer to perform these operations.

How to use psconfig.exe commands

When you run psconfig.exe from the command line, you can specify commands to control how the tool runs. To run psconfig.exe from the command line, navigate to the %COMMONPROGRAMFILES%\Microsoft Shared\web server extensions\12\bin folder, and then type the commands by using the following syntax:

Psconfig.exe -cmd <command> [optional parameters]

You can specify all of the commands to run in a single command-line string. If you do this, then psconfig.exe runs all of the commands in the correct order. For example, on the command line, you can run a command similar to the following:

psconfig.exe –cmd configdb <parameters>
–cmd helpcollections <parameters>
–cmd secureresources <parameters>
–cmd services <parameters>
–cmd installfeatures <parameters>
–cmd adminvs <parameters>
–cmd evalprovision <parameters>
–cmd applicationcontent <parameters>

This reference is taken from Here

SharePoint Column Names: Internal name mappings for non alphabet.

Whenever creating any column for list, SharePoint creates two names for it.

External name to display in views, forms
Internal name
Best example to understand internal name is “Created By” field which is having internal name “Author”.

You can change the display name as many times as you want, but can never change the internal name once column is created.


If you are creating field from code behind then you can assign internal name as per your choice, but when doing it thru web SharePoint gives you option to give display name, and creates internal name by itself. When internal name is defined, if you have any of the non alphabet, numeric character as name SharePoint converts them to special hex codes.


For e.g. trying to create field “Emp Name” gives internal name as “Emp_x0020_Name”


Below is a conversion table for future reference.

SharePoint Internals: InternalName versus DisplayName

When creating columns (more commonly called fields) in SharePoint through the interface, you have to enter a name for it.

This name is used throughout the lists and sites, included internally. Except when you try to change the name, it’ll only reflect on the outside. Internally the old name will be kept.

This is because a field has two names: an internal name and a display name. When creating a field, you set both. When renaming it, you only change the display name. (There is actually no way to change the internal name afterwards)But why is this a concern? Well, in the object model it can become quite vague when to use the internal name and when to use the display name. Here is a short list with some common methods and the name they need.

SPFieldCollection[name] : SPFieldname: DisplayName
unexistent: exception

SPFieldCollection.GetField(name) : SPFieldname: internalName, displayName or internalName and displayName from the current context
unexistent: exception

SPFieldCollection.GetFieldByInternalName(name) : SPFieldname: internalName
unexistent: exception

SPFieldCollection.ContainsField(name) : boolname: displayName or internalName
unexistent: boolean

SPListItem[name] : objectname: internalName, displayName or internalName and displayName from the current context
unexistent: null

SPListItem.GetFormattedValue(name) : stringname: internalName, displayName or internalName and displayName from the current context
unexistent: exception


To Relate with this there also exists a static name. This is a name used by the field type. This is different from the internal name, as the internal name must be unique in its list and could have changed.

Solve Error The remote procedure call failed. (Exception from HRESULT: 0x800706BE) in Microsoft.Office.Interop service

This solution is with respect to WSS 3.0 and MOSS 2007 This error usually come when your machine or server where MOSS 2007 or WSS 3.0 is installed has not application pool identity rights in "IIS WAMREG admin Service" in dcomconfig.add application pool identity to launch and activation permission. Note:when you are using Microsoft.office.interop service in Workflow ,there is chances of this error.Because your application pool identity is NETWORK Service user by default and workflow run under system account ,so this time you need to change application pool identity Network service user to system account.

Adding Active Directory User to Site

Hi All,

Here is a way to add active directory user at site level.

There is one method that ensures that specific loginname exist in site or not? and if not, then adds that user in the site.

Here is a qucik way to do it.

SPWeb.EnsureUser Method (Microsoft.SharePoint)

SPWeb instance ;
String loginName;
SPUser = returnValue;

returnValue = instance.EnsureUser[loginName];

This checks the loginname and if not exists then adds in site.


SPSite siteCollection = SPContext.Current.Site;

SPWeb topLevelSite = siteCollection.RootWeb();

'-------- "Ensure" user and store in a SPUser object: ---------------


SPUser spUserObj = topLevelSite.EnsureUser("domain\someUserName");

'-------- Get the SiteUserInfoList and loop through it to find the
previously "ensured" user: ---------------


SPList userInfoList = topLevelSite.SiteUserInfoList;
SPListItem =InfoItem ;


foreach(userInfoItem In userInfoList.Items)
if(userInfoItem.Item("Account") == spUserObj.LoginName)
{
userInfoItem.Item["Department"] = "some department value";
userInfoItem.Update()
}

Then add user to specifc group.

for more information: Click Here

Thursday, June 5, 2008

Branding SharePoint

Branding a SharePoint site has always been a hot topic.
In the WSS v2.0 and SPS 2003 days, branding was difficult and in many cases required a developer. WSS v3.0 and MOSS 2007 have changed the landscape dramatically; now built entirely on the ASP.NET 2.0 framework master page/page layout infrastructure.

MOSS 2007 Design Component Relationships and Diagrams

Branding SharePoint - Part 1: Designing your SharePoint Site


Branding SharePoint - Part 2: Creating the Design in SharePoint

CSS Reference Chart for SharePoint 2007 (Microsoft Office SharePoint Server 2007 and Windows SharePoint Services v3)

Minimal or Base Master Pages

100% Guarntee to Solve DCOM Error in MOSS 2007 or in WSS 3.0

Here is the post that will help you to solve DCOM error in MOSS 2007 or in WSS 3.0 while development.

Some time you are dealing with Microsoft.Office.Interop service which is one type of DCOM. check in event viewer error will be like this User: NT AUTHORITY\NETWORK SERVICE Computer: computer name Description: The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID {61738644-F196-11D0-9953-00C04FD919C1} to the user NT AUTHORITY\NETWORK SERVICE SID.

This security permission can be modified using the Component Services administrative tool. The highlighted CLSID is for "IIS WAMREG admin Service" in dcomcnfg.

OK to solve this error follows the steps.

in RUN write dcomcnfg open DCOM Config.

in component service right click on My computer and select properties.

in it Default properties section tab make sure that "enable DCOM on this computer is selected.

now select DCOM security tab "Launch and activation section" click on EDIT default add user which gives you error in above error case user is NT AUTHORITY \NETWORK Service so add that user here. assign it Local launch and local activation permission.click ok

now explore DCOM config below my computer and find IIS WAMREG admin Service and right click select properties in security section in Add user for Local launch and activation section.

same thing find NETMAN in it and repeat same thing for it now restart iis .

it should work now generally in we need to give rights for Application pool identity user, by default it is NETWORK SERVICE user.

check WSS_WPG group NETWORK SERVICE User is added or not now it should work.

Special Thanks to : Mike Hanley's Blog

Using Content Query Web Part in MOSS 2007

Content Query Web Part is a way from which you can query different lists at a time and display in web part. Even if you think that you want to display different documents links at a time in web part then also Content Query Web Part is the way you can turn the things around. Even that’s not only with single site but entire site collection.

In short, you can display links to the items from following:
(1) Throughout your site collection.
(2) In one specific site and all of its sub sites.
(3) In one specific list.

Note: The Content Query Web Part is available only in sites that are located on a server running Office SharePoint Server 2007. The server administrator must make this Web Part available in the Web Parts Gallery of the top-level site in the site collection. Also, you must have authoring permissions for the top-level site in order to open and edit page layouts.

Once you have placed a Content Query Web Part, it’s now time to customize the query that best suits your requirement among site or site collection. You can even query by list type, content type. You can also supply filters so that result will get filtered and displayed based on your filter criteria specified.

Display all of the announcements lists in the site collection

(1) With the page layout open in Design view, double-click the Content Query Web Part.
(2) In the Content Query Web Part dialog box, click the plus sign (+) next to Query to expand it.
(3) In the List Type section, in the Show items from this list type list, click Announcements.
(4) Click OK.
(5) To preview the page layout with the Content Query Web Part in it, click
Preview in browser on the Common toolbar.

The page appears in the browser, displaying a list of links to every announcements list from every site in the site collection.

Display a list of links to all graphics in the site, grouped by width

1. With the page layout open in Design view, double-click the Content Query Web Part.
2. In the Content Query Web Part dialog box, click the plus sign (+) next to Query to expand it.
3. In the Source section, click Show items from all sites in this site collection.
4. In the List Type section, in the Show items from this list type list, click Picture Library.
5. In the Content Type section, in the Show items from this list type group list, click <All Content Types>.
6. Click the plus sign (+) next to Presentation to expand it.
7. In the Grouping and Sorting section, in the Group items by list, click Picture Width.
8. Click OK.
9. To preview the page layout with the Content Query Web Part in it, click Preview on the Common toolbar.

for more information :Click Here

Ask Questions

You can ask your questions and queries as a comment to this post. We will try to reply in its comment and so on.


Update: we stop receiving question as we have a lot question pending with answer.
we will reopen ask question soon.

Thanks,
SharepointKings Team

Difference between Synchronous and Asynchronous Events

The primary differences between Sync & Async event handlers are :

1) Synch Eve Handlers will work before the event is completed while AEH will fire after the event is completed.
2) SEH are mostly used to stop the event from completion in order to validate few things. It means you can cancel the event using SEH while it is not possible to cancel the event from AEH.
3) SEH methods has their method names ending with -ing while AEH method names will end with -ed. e.g. ItemAdding, ItemUpdating are SEH while ItemAdded, ItemUpdated are AEH methods.
4) SEH can be used to Add/Modify the values of list fields while using AEH its not possible as it fires after the completion of event.

Wednesday, June 4, 2008

Free Web Parts for MOSS 2007

Hi All,

There is a good link where you can find a free webparts for MOSS2007 to work with.

Here are few links :

Link1

Link2

As i will find more links i will surely put here.

Finding CSS in MOSS

While developing custom webpart, we always wonder for which style sheet class to use.
And try to find out by checking view source of the default page.

Here is the link for
CSS Reference Chart for SharePoint 2007 (Microsoft Office SharePoint Server 2007 and Windows SharePoint Services v3) by Heather Solomon.

This is the wonderful post by Heather Solomon which helped me to solve my many GUI and CSS related problems.

Tuesday, June 3, 2008

Custom Action Button on List's Tool Bar, WSS 3.0

Display a Custom Button say “Load Data” on the Toolbar of the Sales List

Solution:
In a Feature say “CustomContextMenu” we declare a Custom Action.

In the elements.xml file at “\CustomContextMenu\elements.xml” you will need to add this snippet.

<CustomAction Id="CustomContextMenu"
RegistrationType="List"
RegistrationId="10031"
Location="ViewToolbar"
Sequence="239"
Title="Load Data" >
<UrlAction Url="~site/PageFilter.aspx?ListId={ListId}&ItemId={ItemId}&SiteURL={SiteUrl}&Action=7"/>
</CustomAction>

Parameters values:

RegistrationType="List"

RegistrationId is the “Type” id found in the elementManifest.xml of the List on which you want to show the button. Here in our case if you open the elementManifest.xml of Sales List.
You will find that “Type” for this list is “10031”

Location="ViewToolbar". We want the Button to appear on the Tool Bar of the List.

In UrlAction mention the url where you want the control to navigate when you press the button.

Redirection from event handler

Scenario:
recently we have a requirement, for that we need to change default behavior of SharePoint.

Here is the requirement.
• While adding Item in the list, create sub site regarding that item.
• Redirect to the newly created site.
• Same case while updating item also.

Default behavior.
• After adding or updating item your SharePoint will redirect you to the page from where you come.
• Like in list if you adding item by clicking “New Item” from “alltems.aspx” SharePoint will redirect you back to the same page “allitems.aspx”.

How to do it?• Create an event receiver like ItemAdding and ItemUpdating for that List or library.
• In that event receiver, provision site programmatically.
• After provisioning new site, redirect user to newly created sub site using SPUtility.Redirect method. (need to include Microsoft.SharePoint.Utilities)

Roadblocks
• My first road block is that HttpContext is not available in event handler.
• To resolve this problem Check this
• Now after finding a way to get HttpContext we can use SPUtility.Redirect method but if we use it item is not added and your thread will redirect.
• And you’re other events (Asynchronous) like ItemAdded and ItemUpdated will not fire.

Solution
• To resolve this problem please check Code snippet below
public override void ItemAdding(SPItemEventProperties properties)
{

//perform validation if required.

// get the list which item to be added
SPSite objsite = new SPSite (properties.SiteId);
SPWeb objweb = objsite.OpenWeb (properties.RelativeWebUrl);
SPList objlist = objweb.Lists[properties.ListId];

//use this method to disable reoccurence of events.

DisableEventFiring();
SPListItem itemToAdd = objlist.Items.Add();

//add item to list

itemToAdd.Update();
EnableEventFiring();

// provision sub site and perform required action

//redirect it to your new destination like newly provisioned sub site or any other page you want.

SPUtility.Redirect(strNewresiractionUrl, SPRedirectFlags.Trusted,current);

}

I hope you got my problem and solution. With the help of this you can find your solution according to your requirement.

And thank you very much to Eric Bartels for his superb post which was helpful to resolve this problem.



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