Monday, December 21, 2009

Display version history on DispForm.aspx

Go to the list settings of your list-> versioning settings->select yes in item version histry. Save it. So every time yuo go to display form or edit form you will get the link for verson history. Hope this will be helpfull

Monday, November 16, 2009

Determine whether the site is WSS (3.0) or MOSS Enterprise

There is no way to actually know whether a site is hosted on a server that has Microsoft Office SharePoint Server (MOSS) installed by just looking at it.The differences are mostly behind the scenes and are not visible to users. Customizations may cause a WSS site to look as if it has some extensions that come with MOSS or might cause a MOSS site to look simpler by removing the MOSS specific links that would help you identify a site as MOSS.

There are two things you can look for in any SharePoint site and be fairly sure that your site is MOSS or WSS. The first is to look for the My Site link at the top of the screen.If you have that link,it means you are viewing a site that is running on a server with MOSS.Not having the link does not necessarily mean that the site does have MOSS because the administrator can choose to disable that functionality.

The second way you can tell is by looking for the Advanced Search link. WSS site (unless customized)do not have that link,so having that link means you you probably are viewing a site that is running on a server with MOSS. Another related way to test this is to open the search screen (perform a search) and see whether you have the option from that screen to switch to advanced search.

One of the main differences between WSS and MOSS is the Web Parts available; the list below shows those Web Parts which are not present in WSS 3.0

Contact Details
Business Data Actions
Business Data Item
Business Data Item Builder
Business Data List Business Data Related List
Excel Web Access
IView Web Part
WSRP Consumer Web Part
Site Aggregator
Key Performance Indicators
KPI Details
Content Query Web Parts
I need to…
RSS Viewer
Summary Link Web Part
Table of Contents Web Part
This Week in Pictures
Business Data Catalog
Filter
Choice Filter
Current User Filter
Date Filter
Filter Actions
Page Field Filter
Query String (URL)
Filter
SharePoint List Filter
SQL Server 2005 Analysis Services Filter
Text Filter
My Calendar
My Contacts
My Inbox
My Mail Folder
My Tasks
Advanced Search Box
People Search Box
People Search Core
Results
Search Action Links
Search Best Bets
Search Box
Search Core Results
Search High Confidence Results
Search Paging
Search Statistics
Search Summary
Categories
Sites in Categories
Top Sites

Sunday, November 15, 2009

Export Excel to Sharepoint

Export your excel spreadsheet data in to sharepoint list using these steps:

Import the file into a new list using these steps:
1.Site actions -> Create
2.In the "Custom Lists" section, select "Import Spreadsheet"
3.Enter a name and description for your list
4.Browse to your exported text/Excel file.
5.Click Import

Excel will start up with a Import dialog.

1.In the import dialog, select "Range of cells"
2.Click in the "Select range" text box.
3.Select the Subject to End Time columns and drag down to all rows you want to import.
(So it will result in something like MyExportedCalendar!$A$1:$E$46)
4.Click Import.

The data is now imported in to a list.Hope this helps.

Tuesday, November 10, 2009

Sending Alerts to Group in Sharepoint 2007

In most of the cases user need to send alert to sharepoint group but in GUI one can pass either user name or Email address. But here is the solution to achieve this functionality ofcourse it is not possible without any customization!!

Take a look on how it works!



Item wise:



Alert Group page where you can select the group:



you can get this web part from the following link:
http://www.codeplex.com/AdvancedAlert

Thursday, November 5, 2009

SharePoint Color Coded Calender


SharePoint calender can display the items in color and that too without creating any complicated code.

Steps are:
1.Create or open a calendar

2.Add a new column named "Color" (Settings, List Settings) – most likely type will be "Choice" with choices like "Red, Green, Blue, Black", but this could be a lookup or a single line of text.

3.Add a new column named "CalendarText"

type is Calculated

equation is
="<'font color='" & Color & "''>" & Title & "<'/font'>"

data type returned = single line of text

4.Modify the existing view, or create a new view such as "Color Calendar"

Change the field used for the month view to "Calendar Text"

Save and exit
5.Add a Content Editor web part

Site Actions, Site Settings, Edit Page

Add a Content Editor web part and move it below the calendar web part

Click in the web part click Edit, Modify Shared Web Part

Click Source Editor

6.Paste this JavaScript

<'script type="text/javascript" language="javascript"'>
var x = document.getElementsByTagName("TD")
var i=0;
for (i=0;i<'x.length;i++')
{
if (x[i].className.substring(0,6)=="ms-cal")
{
x[i].innerHTML= x[i].innerHTML.replace(/</g,'<').replace(/>/g,'>')
}
}
<'/script'>


7.Click Save, OK, Exit Edit Mode

8.Add a new calendar item and select a color.

Note: Remove every single quote written after < html tag.

Create a Google Map web part for yout MOSS web site


So you are looking for creating Google Map web part for your MOSS web site, here is the easiest way to achieve this without coding, just a little bit of HTML.a link out to the web from your MOSS server as the google map api will need to communicate to the google map server and a google API key which you can request from http://code.google.com/apis/maps/signup.html

The google API key, is a key that will be mailed to you from google, once you have submitted the google api key form, you will need to agree to Google Standard Terms and Conditions and provide the URL of your MOSS site.

PreReq :
1. MOSS Server
2. Goggle API Key
How To :
1. Open a Moss site where you would like to place your Goggle Map web part.
2. Place a Content Editor Web Part in the Page of the site.
3. Edit the content Editor Web Part and in the proerties of this web part open the source editor. Do not use the Rich Text Editor.
4. Copy and paste the folloing code in the sorce editor:

<'script src="http://maps.google.com/maps?file=api&v=1&key=ADD_YOUR_GOGGLE_API_KEY_HERE" type="text/javascript" mce_src="http://maps.google.com/maps?file=api&v=1&key=ADD_YOUR_GOGGLE_API_KEY_HERE"'>
<'/script'>
<'script src="<'a href=" file="api&v="1&key="ADD_YOUR_GOGGLE_API_KEY_HERE"'>http://maps.google.com/maps?file=api&v=1&key=ADD_YOUR_GOGGLE_API_KEY_HERE<'/a'>" mce_src="<'a href="http://maps.google.com/maps?file=api&v=1&key=ADD_YOUR_GOGGLE_API_KEY_HERE"'>http://maps.google.com/maps?file=api&v=1&key=ADD_YOUR_GOGGLE_API_KEY_HERE<'/a'>" type="text/javascript"'>
<'/script'>
<'div id="map" style="width: 400px;height:300px"'><'/div'>
<'script type="text/javascript"'>
var map = new GMap(document.getElementById("map")); map.centerAndZoom(new GPoint(-0.160265, 51.51443), 3);
<'/script'>

5. Apply and OK.

If you want to add scaling and repositioning to your web part then add the following into your code, after the var map = …… Line:
map.addControl(new GLargeMapControl());

Your Google Map web part is ready to use!!!

Note: Remove every single quote written after < html tag.

Wednesday, November 4, 2009

Integrate Crystal Reports with SharePoint

If you are working on sharepoint based intranet and would like to integrate already developed Crystal reports to your sharepoint site then your search ends here!!
You just need to create one web part which holds the .rpt files from custom document library and shows the data/charts from the report on your site. So create document library named "Reports"(you can change the name but make changes in code accordingly.) on your site.
So create Sharepoint web part and add following code in to it:
Required Namespaces:
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;

public class CustomCrystalReportWP : System.Web.UI.WebControls.WebParts.WebPart
{
String strReportName = "";
ReportSourcePart edPart = new ReportSourcePart();
public CustomCrystalReportWP()
{
}
// serialise the name of the report
[Personalizable(PersonalizationScope.Shared, false)] // Storage.
public string ReportSource
{
get
{
return strReportName;
}
set
{
strReportName = value;
}
}
protected override void CreateChildControls()
{
CrystalDecisions.Web.CrystalReportViewer crystalReportViewer1 = new CrystalDecisions.Web.CrystalReportViewer();
ReportDocument crdoc = new ReportDocument();
this.SetPersonalizationDirty();
base.CreateChildControls();
if (strReportName.Length > 0)
{
SPWeb thisSite;
thisSite = SPControl.GetContextWeb(Context);
SPFolder folder = thisSite.GetFolder("Reports");
if (folder.Exists)
{
// get collection of Crystal Reports rpt files in the document library
SPFileCollection files = folder.Files;
// open the rpt file and get the contents
SPFile srcfile = files[strReportName];
byte[] content = srcfile.OpenBinary();
// make a temporary folder
DirectoryInfo dir2 = new DirectoryInfo("~/temp");
if (!dir2.Exists)
dir2.Create();
if (File.Exists("~/temp/temp.rpt"))
{
File.Delete("~/temp/temp.rpt");
}
// write the report definition to a temporary file
BinaryWriter bw = new BinaryWriter(File.Open("~/temp/temp.rpt", FileMode.Create));
bw.Write(content);
bw.Close();
// set up the crystal report
crdoc.Load("~/temp/temp.rpt");
// and the Crystal report Viewer
crystalReportViewer1.ReportSource = crdoc;
crystalReportViewer1.ReuseParameterValuesOnRefresh = false;
crystalReportViewer1.HasRefreshButton = true;
this.Controls.Add(crystalReportViewer1);
// clean up
File.Delete("~/temp/temp.rpt");
}
}
}
// Display a custom editor in the tool pane, this gets displayed when you edit the web part settings.
public override EditorPartCollection CreateEditorParts()
{
ArrayList arEditorParts = new ArrayList();
edPart.ID = this.ID + "RptSrcEditorPart";
arEditorParts.Add(edPart);
return new EditorPartCollection(arEditorParts);
}
// Create a custom EditorPart to edit the WebPart.
class ReportSourcePart : EditorPart
{
DropDownList rptslist = new DropDownList();
// Get settings from web part.
public override void SyncChanges()
{
CustomCrystalReportWP part = (CustomCrystalReportWP)this.WebPartToEdit;
}
// Apply new settings to web part.
public override bool ApplyChanges()
{
CustomCrystalReportWP part = (CustomCrystalReportWP)this.WebPartToEdit;
part.strReportName = rptslist.SelectedValue;
return true;
}
// Render the control.
protected override void CreateChildControls()
{
// Set the title to display in the properties pane
this.Title = "Crystal Reports List";
// add elements to dropdown
SPWeb thisSite;
thisSite = SPControl.GetContextWeb(Context);
//thisSite.Site.P
SPFolder folder = thisSite.GetFolder("Reports");
SPFileCollection files = folder.Files;
foreach (SPFile file in files)
{
rptslist.Items.Add(file.Name);
}
Controls.Add(rptslist);
this.ChildControlsCreated = true;
base.CreateChildControls();
}
}
}
You have to add CrystalImageHandler.aspx and CrystalImageHandler.aspx.cs to the root folder of your site to display the graphics on your site. You can copy those files from http://www.codeproject.com/KB/sharepoint/CustomCRWP2.aspx then add the reference to httpHandlers in your web.config,
Now your web part is ready to deploy:)

Filter SharePoint Search Results based on Target Audience

Basic requirement is to filter the search results based on target audience on SharePoint document repository. If current user belongs to one perticular group and if that group doesn't have permission on perticular folder from document library then that user will not be able to see documents from that perticular folder.
Here is the code:
using Microsoft.Office.Server.Search.Query;
using System.Collections.Generic;
using System.ComponentModel;

Button cmdSearch;
TextBox txtQueryText;
Label lblQueryResult;
SPWeb web = null;
int SearchCnt = 0;
protected override void CreateChildControls()
{
// Create and add the controls that compose the
// user interface of the Web Part.
Controls.Clear();
txtQueryText = new TextBox();
this.Controls.Add(txtQueryText);
cmdSearch = new Button();
cmdSearch.Text = "Start Search";
cmdSearch.Click += new EventHandler(cmdSearch_Click);
this.Controls.Add(cmdSearch);
}

void cmdSearch_Click(object sender, EventArgs e)
{

try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite site = SPContext.Current.Site;
web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists[_ListName];
SPView view = list.Views["All Documents"];
SPQuery query = new SPQuery(view);
query.ViewAttributes += " Scope=\"Recursive\"";
//Retrieve the items based on Query
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem item in items)
{
SPRoleDefinitionBindingCollection usersRoles = web.AllRolesForCurrentUser;
// Validate if user has rights
if (item.Name.Contains(txtQueryText.Text))
{
foreach (SPRoleDefinition roleDefinition in usersRoles)
{
SPRoleDefinitionBindingCollection col = item.AllRolesForCurrentUser;
foreach (SPRoleDefinition role in col)
{
if (role == roleDefinition)
{
SearchCnt++;
HyperLink name = new HyperLink();
name.Text = "
" + item.Name + "
";
name.Font.Size = 10;
name.NavigateUrl = web.Url + "/" + item.Url;
HyperLink url = new HyperLink();
url.Text = web.Url + "/" + item.Url + "
";
url.NavigateUrl = web.Url + "/" + item.Url;
url.ForeColor = System.Drawing.Color.Green;
this.Controls.Add(name);
this.Controls.Add(url);
}
break;
}
}
}
}
if (SearchCnt == 0)
{
lblQueryResult = new Label();
lblQueryResult.Text = "
" + "No search results found!";
this.Controls.Add(lblQueryResult);
}
});

catch (ArgumentException ex)
{
}
}