Sharepoint 2007 - Some tips and tricks

Links

Create SharePoint page

  • Go to server where share point is installed
  • Start
  • Programs
  • Administrative tools
  • SharePoint Central Administration
  • Application management
  • Create site collection
  • resultant site

Create custom list
  • Home
  • Site actions
  • Create
  • Custom list
  • Name of the list

Delete list

  • Home
  • Go to list
  • Settings
  • List settings
  • Delete this list

Delete view of a list

  • Home
  • Go to list
  • View:
  • Select the view
  • Modify this view
  • Delete

Add Column
  • Home
  • Go to list
  • Settings
  • Create column
  • Type - Lookup (if information already exists on the site)

Add Column - Assigned to
  • Home
  • Go to list
  • Settings
  • List settings
  • Create column
  • Type - Person or Group

Add Column - multiple choice
  • Home
  • Go to list
  • Settings
  • List settings
  • Create column
  • Type - Choice(menu to choose from)

Get StaticName of a column
  • Home
  • Go to list
  • Settings
  • List settings
  • Click the column for which you want to see static name
  • The StaticName is the value for the Field parameter in the QueryString

Add Column - cascade lookup
  • Paid and easy
  • Download jquery.SPServices-0.4.7.min.js from http://spservices.codeplex.com/
  • Download jquery-1.3.2.min.js from http://jquery.com/
  • Note: relationshipListParentColumn & relationshipListChildColumn are static.
  • Add following Code
    <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <script language="javascript" type="text/javascript" src="../../jquery/jquery-1.3.2.min.js"></script>
    <script language="javascript" type="text/javascript" src="../../jquery/jquery.SPServices-0.4.7.min.js"></script>
    <script language="javascript" type="text/javascript">
    $(document).ready(function() {
    $().SPServices.SPCascadeDropdowns({
    relationshipList: "Clientes",//simple name
    relationshipListParentColumn: "Title",//static name
    relationshipListChildColumn: "Morada",//static name
    parentColumn: "Cliente",//simple name
    childColumn: "Local Final1",// simple name
    debug: true
    });
    });
    </script>
  • If it works on intranet and doesnt work in internet, then you may consider configuring Alternate Access Mappings

Delete Column
  • Home
  • Go to list
  • Settings
  • List settings
  • Click in the column
  • Delete

Document Library
  • Home
  • Site actions
  • Create
  • Document Library

Add Web Part(s) to one list/page
  • Home
  • Go to list
  • Site actions
  • Edit page
  • Add a Web Part

Create relation between web parts
  • Add Web Part(s) to one list/page
  • Home
  • Go to list
  • Site actions
  • Edit page
  • Select webpart
  • edit
  • connection

Webparts edit-connection options missed
  • First of all, always use IE instead of firefox.
  • Go to server where share point is installed
  • Start
  • Programs
  • Administrative tools
  • Sharepoint Central Administration
  • Application management
  • Security for Web Part pages
  • Allow connection

Import data from excel
  • Home
  • Site actions
  • Create
  • Import Spreadsheet

Publish from excel to sharepoint

  • Open your excel sheet
  • Select your data
  • Click Crtl+l
  • Click ok
  • Right click list
  • List
  • Publish list
  • type address of sharepoint site (eg: http://thor:28345/sites/fleetcrm)
  • Static name of sharepoint list (eg: TiposdeResumo)
  • click Finish

Create view ( and add filter based on a CURRENT USER)
  • Home
  • Go to list
  • View:
  • Create View
  • Filter
  • Show items only when the following is true
  • [Your field to filter]
  • is equal to
  • write: [Me]

Create links on left
  • Copy the link eg. link of view that you have created recently
  • Home
  • Site Actions
  • Site Settings
  • Quick lunch
  • New link

Set color backgrounds for rows in calender
  • Workflow(Sharepoint designer - File-New-Workflow)(Actualize a column, where column value has html)
  • Javascript on edit page
  • Color Calendar

Programmatically Setting Permissions for List Items
        private void ActualizePermission(SPListItem listItem, SPUser user, string permissionName, SPWeb web)
{
try
{
SPRoleAssignment roleAssignment = new SPRoleAssignment(user);
roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions[permissionName]);
if (!listItem.HasUniqueRoleAssignments)
listItem.BreakRoleInheritance(true);
listItem.RoleAssignments.Add(roleAssignment);
listItem.Update();
}
catch(Exception)
{
Log("Error while giving '" + permissionName + "' permission to '" + user.Name + "'");
foreach (SPRoleDefinition definition in web.RoleDefinitions)
Log(definition.Name + " - " + definition.Description);
throw;
}
}

Actualize site administrator

  • Home
  • Site definition
  • Advanced permission
  • Definition
  • Administrate site collection

Remove users from a group
  • On the home page, click the Site Actions menu, point to Site Settings, and then click People and Groups.
  • On the People and Groups page, on the Quick Launch, click Groups.
  • On the People and Groups: All Groups page, click the name of the group from which you want to remove users.
  • Select the check boxes for the users who you want to remove.
  • On the Actions menu, click Remove Users from Group, and then click OK.

Delete a group
  • On the home page, click the Site Actions menu, point to Site Settings, and then click People and Groups.
  • On the People and Groups page, in the Quick Launch, click Groups.
  • On the People and Groups: All Groups page, in the Edit column, click the Edit button next to the group that you want to delete.
  • On the Change Group Settings page, scroll to the bottom of the page, click Delete, and then click OK.

Delete a user from a site collection
  • On the site collection home page, click the Site Actions menu, point to Site Settings, and then click People and Groups.
  • On the People and Groups page, in the Quick Launch, click All People.
  • On the People and Groups: All People page, select the check box next to the user who you want to delete.
  • On the Actions menu, click Delete Users from Site Collection, and then click OK.

Activate/Deactivate/Remove feature
  • Go to server where share point is installed
  • Start
  • Programs
  • Administrative tools
  • Sharepoint Central Administration
  • Operations
  • Click in the solution that you want to activate/Deactivate/remove
  • Select option as per your need

External workflow
  • C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow\WSS.ACTIONS

Create job by creating site feature

  • SPJobDefinition
  • SPFeatureReceiver
  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES
  • feature.xml
  • elements.xml
  • http://geekswithblogs.net/evgenyblog/archive/2008/01/27/118966.aspx

Get users list (C#)
             using (SPSite site = new SPSite(_siteUrl))
{
using (SPWeb web = site.OpenWeb(_webUrl))
{
SPUserCollection userList = web.Users;
...

Programmatically adding list entries to a SharePoint 2007 list which contains a lookup field gave following error:

Invalid data has been used to update the list item. The field you are trying to update may be read only.

Solution is to use id instead of value. Here is an example:

...
     if (columnsName[i] == "Cliente")
{
int id = Helper.GetLookupFieldID(values[i], clienteList);
occurenceItem[columnsName[i]] = id;
}
...
     public static int GetLookupFieldID(string lookupValue, SPList lookupSourceList)
{
int lookupFieldID = -1;
SPQuery query = new SPQuery();
query.Query = String.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", lookupValue);
SPListItemCollection listItems = lookupSourceList.GetItems(query);
foreach (SPListItem item in listItems)
lookupFieldID = item.ID;
return lookupFieldID;
}

Publish items to sharepoint
         StreamReader streamReader = new StreamReader("../Data/data.txt");
using (SPSite site = new SPSite("http://thor:28345/sites/crm"))
{
using (SPWeb web = site.OpenWeb("/sites/crm"))
{
SPList list = web.Lists["test1"]; //Value does not fall within the expected range. - if "test1" doesnt exists in sharepoint site
while (true)
{
string line = streamReader.ReadLine();
if (line == null) break;
string[] columns = line.Split('\t');
SPListItem listItem = list.Folders.Add();
listItem["name"] = columns[0];
listItem["location"] = columns[1];
listItem.Update();
}
}
}

Delete all items of the list
private void deleteAllItemsButton_Click(object sender, EventArgs e)
      {
using (SPSite site = new SPSite(_siteUrl))
{
using (SPWeb web = site.OpenWeb(_webUrl))
{
SPList list = web.Lists[_listName];
while (list.Items.Count > 0)
list.Items.Delete(0);
}
}
}

Set color backgrounds for rows in task lists to show the status of the task
  • Home
  • Go to list
  • Site actions
  • Edit page
  • Add a web part
  • Content Editor web part
  • Edit
  • Modify Shared web part
  • Appearence
  • Chrome type
  • Set to none
  • Click in source editor
  • Put this code
  • <script type="text/javascript" language="javascript">
    var x = document.getElementsByTagName("TD") // find all of the TDs
    var i=0;
    for (i=0;i<x.length;i++)
    {

    if (x[i].className=="ms-vb2") //find the TDs styled for lists
    {

    if (x[i].innerHTML=="No") //find the data to use to determine the color
    {
    x[i].parentNode.style.backgroundColor='red'; // set the color
    }

    //repeat the above for each data value

    if (x[i].innerHTML=="Yes")
    {
    x[i].parentNode.style.backgroundColor='lightgreen'; // set the color
    }

    }

    }
    </script>

Search - working correctly in intranet, but not in internet

Alternate Access Mapping
  • Go to server where share point is installed
  • Start
  • Programs
  • Administrative tools
  • Sharepoint Central Administration
  • Application Management
  • Create or extend Web application
  • Extend an existing Web application
  • Select web application:
  • Description: Any name you want
  • Port: Any port you want
  • Host Header: Name you use in server to access sharepoint (Eg: demo if internet url is http://demo/sites/crmdemo/default.aspx)
  • Zone: Internet

Hide columns in Edit Mode(Edit xx.aspx page)
  • Open the site in SharePoint designer
  • Open the aspx that you want to change (e.g.: EditForm.aspx)
  • Search and select WebPartPages:ListFormWebPart that is inside webpart zone
  • Double click
  • Layout
  • Set hidden to true
  • Click once in the same area
  • Insert
  • SharePoint Controls
  • Costum List Form
  • Select the list, items and type of form
  • Select the line that you want to delete and hit delete. Save the page.

Get logged-in user id from Javascript
  • _spUserId

Hide column in Edit.aspx or NewForm.aspx or DispForm.aspx (Javascript)
<script language="javascript" type="text/javascript" src="../../jquery/jquery-1.3.2.min.js"></script>
  <script language="javascript" type="text/javascript" src="../../jquery/jquery.SPServices-0.4.7.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function()
{
Hide("input", "", "CalendarText");
Hide("input", "", "Fonte de registo");
});

function Hide(tagName, identifier, title)
{
var control = getTagFromIdentifierAndTitle(tagName, identifier, title);
control.parentNode.parentNode.parentNode.style.display="none";
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}
</script>

Hide column using C# in Edit.aspx or NewForm.aspx or DispForm.aspx (C#)

<script runat="server" type="text/c#">
  void Page_Load(object sender, EventArgs e)
{
SPContext.Current.Fields["CalendarText"].ReadOnlyField = true;
SPContext.Current.Fields["CalendarText"].Update();
}
</script>

Set readonly to columns in Edit.aspx or NewForm.aspx (Javascript)
function SetReadonly(tagName, identifier, title)
{
var control = getTagFromIdentifierAndTitle(tagName, identifier, title);
control.readOnly="true"; //cannot use control.disabled because it will prevent the data to be sent to the server
control.style.backgroundColor = "eeeeee";
}

Hide columns in Edit.aspx or NewForm.aspx (Javascript)
function Hide(tagName, identifier, title)
{
SetReadonly(tagName, identifier, title)
var control = getTagFromIdentifierAndTitle(tagName, identifier, title);
control.parentNode.parentNode.parentNode.style.display ="none";
}

Get notified just before save in Edit.aspx or NewForm.aspx (Javascript)
function PreSaveItem()
{
}
Get notified just before save in Edit.aspx or NewForm.aspx (C#)


Enable server side C# script


  • Have to change web.config(
    C:\Inetpub\wwwroot\wss\VirtualDirectories\80)
  • <PageParserPaths> <PageParserPath VirtualPath="/sites/crmdemo/Lists/Ocorrncias/EditForm.aspx" CompilationMode="Always" AllowServerSideScript="true" /> </PageParserPaths>



Performance tip

The executable "OWSTIMER.exe" belongs to "Windows Sharepoint Services Timer V4" service. Its main function is to send notification and perform schedule tasks for sharepoint. It has some memory leak problem. If it is possible, it is recommended to disable this service to improve performace of the sharepoitn site.

How often you have to go to central administration page after you have configured you site properly? Not much. Then it might be a good idea to stop the central administration site from running. For that go to the "IIS Manager", "Sites", "Sharepoint Central Administration v4" and stop the site. I have not calculated yet whats really is the performance gain by stopping this site.

3 comments:

  1. Hello Ajit,
    I was having a small problem in sharepoint 2010.
    How to send email to group when any new user is added to that group. For eg: if a user x is added to a group y. All the users of group y should get the message " New user x has been added the this group. Please Help

    ReplyDelete
    Replies
    1. Hi Suman, I have not implemented this feature in the past, so i just can try to help. Anyway, how are you trying to resolve this? Have you already configure an SMTP server for SharePoint Portal? In which part are you in the process?

      If you have already configure an SMTP server, then there are three way than i can think of (ps: I have not tested it because I dont have sharepoint installed in my machine),

      1) Create a workflow that send email when any change is detected, described in http://office.microsoft.com/en-us/sharepoint-designer-help/workflow-example-send-a-notification-message-HA010182908.aspx

      2) Get notified just before save in c# and send email

      3) Get notified just before save in javascript (presaveitem), then send http post to server to notify other users.

      Take care ;)

      Delete
  2. thanks Ajit I solved that .
    Now I am in another issue. I have to use webservices in sharepoint so that i can extract data from different program in sharepoint. Do you have any idea how to do this. Please Help.

    ReplyDelete