Archive for the 'MOSS 2007' category

Setting a custom 404 error page for SharePoint

Aug 09 2010 Published by Hojo Clement under MOSS 2007, PowerShell

In this article we will see how to set a custom error 404 (page not found) error page for SharePoint.

  1. Log on the sharepoint server and access the language folder in layout of IIS (% systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\LangID)
    Note: In this path, LangID represents the actual Locale ID of the language that you use. For example, 1033 is the language ID for U.S. English.
  2. Rename the error.html file to error.old.
  3. Create the custom HTML file (pagenotfound.html) and copy it to above folder.
  4. Create a console
  5. application / PowerShell script for assigning the new custom error page for your web application and run / execute it in SharePoint server

C# code for console application

Microsoft.SharePoint.Administration.SPWebApplication webapp =
Microsoft.SharePoint.Administration.SPWebApplication.Lookup(new Uri("http://"));
webapp.FileNotFoundPage = "
";
webapp.Update();

PowerShell code

$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("http://")
$webapp.FileNotFoundPage = "pagenotfound.html"
$webapp.Update()

Note: By default, in Internet Explorer, the Show friendly HTTP error messages setting is turned on and the custom error page may not appear. In this case turn off this setting and try.

One response so far

Read data from a content editor webpart

Jun 11 2010 Published by Hojo Clement under MOSS 2007, Webpart

In this article we will see how we can to get data from a content editor webpart from one page and display it in another page using a custom webpart.

If you are new to webpart development you can check out my previous post about Hello world SharePoint Web Part for Beginners
Add the following code in the RenderWebPartmethod of the webpart you are creating. The code and comments are self explanatory. Please pose a comment if you have any problem in understanding the code.

SPSite site = new SPSite("http://mysite">http://mysite"); // create object of the site
SPWeb web;
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
web = site.OpenWeb();
mgr = web.GetLimitedWebPartManager("Pages/mypage.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.User);//http://mysite/Pages/mypage.aspx will be the URL of the source page
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (wp.Title ==  "My RichTextEditor") //My RichTextEditor is the webpart title
{
SPWebPartPages.ContentEditorWebPart webPart =    (SPWebPartPages.ContentEditorWebPart)wp;
output.Write(webPart.Content.InnerText);
}
}

No responses yet

Error in Multiple Documents Upload

Jun 08 2010 Published by Radhika under MOSS 2007

This is one of the ‘not so common’ but confusing error. All of a sudden multiple documents upload will not work and give you the following error.

Can not run Windows SharePoint Services on the Page

There are different possible reasons for this error.

1.

  • Open Central Administration -> Application Management -> Authentication Providers. Make sure you select the correct Web Application which is giving you the error.
  • Turn off Enable Client Integration (NO) then go back and Turn on Enable Client Integration (YES).
  • Then do an  IISRESET and try to upload multiple documents.

2.

It is normally not advisable to edit upload.aspx file in the layouts folder but there may be cases when you have to edit this file. One thing which you should keep in mind is updates like Service Pack will overwrite thee files so try the following.

Steps

1.     Backup upload.aspx and then Open upload.aspx and search for

<input TYPE="hidden" NAME="_charset_" VALUE="utf-8

2.      Update the following string as follows

<input TYPE="hidden" NAME="Cmd" VALUE="Save

3.      Save your file.

4.      Reset IIS and try to upload multiple files in document library.

One response so far

Hide Breadcrumb on a single page in MOSS 2007 without using SharePoint Designer

Jun 02 2010 Published by Radhika under MOSS 2007, SharePoint Design Customisation, Tips

In this article we will see how we can hide the BreadCrumb in a single page. We are also going to do it without using the SharePoint Designer. We are going to do it by using a content editor web part.
1. Go to Site Actions –> Edit Page –> Add a Content editor web part

2.  Write following code in to content editor web part


<style rel="stylesheet" type="text/css" />

.ms-pagebreadcrumb{display:none; }

</style>

Save the changes and exit edit mode or publish the page

Step 3 :  Now your page should look like this

One response so far

3 ways to edit SharePoint page properties

May 19 2010 Published by Hojo Clement under MOSS 2007, PowerShell, Tips

Here comes another post in the series of “3 ways to do….”. Here is how you can edit the properties of a page in Sharepoint

using browser

1. Go to the pages library of the site.
2. Click Checkout menu of the page
3. Click property menu of the page
4. Edit property and save
5. Finally checkin that page
using Object model

SPSite site = new SPSite("http://mysite");
SPWeb web = site.OpenWeb();
SPFile file = web.GetFile("./pages/default.aspx");
file.CheckOut();
file.Item["Title"] = "new title";
file.Item.Update();
file.CheckIn("title edited");

using PowerShell

[system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
$site= New-Object Microsoft.SharePoint.SPSite ("http://mysite")
$web=$site.OpenWeb()
$page =  $web.GetFile("./Pages/default.aspx")
$page.CheckOut()
$page.Item["Title"] = "new title"
$page.item.update()
$page.CheckIn("title edited")

No responses yet

Hide a required field in SharePoint list while adding new item

May 13 2010 Published by Hojo Clement under MOSS 2007, PowerShell, Tips

There may be cases when we need to a hide required field while adding a new item to a list but at the same time you may want to show it while editing the item.

The above case looks tricky but it is easily achievable using some extra bit of code or PowerShell

C#

string siteUrl = "http://mysite";
SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
site.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["mylist"];
SPField fldName = list.Fields["Name"];
fldName.ShowInNewForm = false;
fldName.Update();
list.Update();

PowerShell

[system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
$site= New-Object Microsoft.SharePoint.SPSite ("http://d-dev1:1234/gp")
$web=$site.OpenWeb()
$list=$web.Lists["mylist"]
$field = $list.Fields["Name"]
$field.ShowInNewForm = $false
$field.Update()

If you want to hide this field in edit form, you can use below command

fldName.ShowInEditForm = false;

If you want to hide this field in display form, you can use below command

fldName.ShowInDisplayForm = false;

If you want to hide this field in list settings, you can use below command

fldName.ShowInListSettings = false;

If it is not a required filed then you can hide the item using Jquery in client side.

<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$('nobr:contains("Name")').closest('tr').hide();
});
// ]]></script>

No responses yet

3 ways for adding new column in SharePoint list

May 12 2010 Published by Hojo Clement under MOSS 2007, MOSS 2010, PowerShell, Tips

In this post we will see 3 different methods for adding columns in SharePoint list or document library or discussion board.

using browser
Go to the list which you want to add column
On the page that displays the list, click list’s settings and create columns.
Type a name for the column, choose the column type and click OK.

using Object model


SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();

site.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = true;

SPList list = web.Lists["mylist"];
SPFieldText fldName = (SPFieldText)list.Fields.CreateNewField(SPFieldType.Text.ToString(), "mycolumn");
fldName.Required = true;
fldName.MaxLength = 50;
list.Fields.Add(fldName);
list.Update();

site.AllowUnsafeUpdates = false;
web.AllowUnsafeUpdates = false;

using PowerShell


[system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
$site= New-Object Microsoft.SharePoint.SPSite ("http://mysite")
$web=$site.OpenWeb()
$list=$web.Lists["mylist"]
$list.Fields.Add("mycolumn", "Text", 0)

No responses yet

3 ways to find SharePoint list field’s Internal name

May 11 2010 Published by Hojo Clement under MOSS 2007, PowerShell, Tips

While working with caml query there may be cases where we may need to refer internal name of a sharepoint list and in some of the cases the display name and internal name may be different. If you try to access this list we will get object not found error.

We can find out the sharepoint field’s internal name using any of the following ways
1. Using browser (it applies to custom fields only)
Go to list settings -> Edit column. Then you can see field name from the query string

2. Object model (it applies for custom fields as well as system fields)

string siteUrl = "http://mysite";
SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
SPList list = web.Lists["my forum"];
for (int i = 0; i < list.Fields.Count; i++)
Console.WriteLine(list.Fields[i].Title + "..." + list.Fields[i].InternalName + "...");
Console.ReadLine();

3. Powershell (it applies for custom fields as well as system fields)

[system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
$site= New-Object Microsoft.SharePoint.SPSite ("http://mysite")
$web=$site.OpenWeb()
$list=$web.Lists["my forum"]
$list.Fields |select title, internalname| more

One response so far

Display all Lists in a SharePoint site using PowerShell

May 09 2010 Published by Shoban under MOSS 2007, MOSS 2010, PowerShell

In this tutorial we will see how we can list out all the Lists in a SharePoint site using Windows PowerShell.

Open Powershell and Enter the following cmdlets one by one.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$spsite = New-Object Microsoft.SharePoint.SPSite("http://shoban")
$spsite.AllWebs | foreach { $_.Lists | ft $_.URL, Title }

In the first line we load the Microsoft.SharePoint assembly. In the second line we create a new SPSite object for our SharePoint site. In this case the url of the site is http://shoban

In the last line we List out all the Lists in the site. We also use the ft cmdlet to Format the Output.

If you want to write the output to a text file simply replace the last line with the following

$spsite.AllWebs | foreach { $_.Lists | ft $_.URL, Title } > Lists.txt

To open the new Text file created use the Invoke-Item cmdlet.

No responses yet

Creating site collection using custom site template

Apr 23 2010 Published by Hojo Clement under MOSS 2007

In this post we will see how to convert a site to site collection.

  1.  Save the existing site to site template (site actions-> site settings -> save site as template)
  2. Download the created stp file from site template gallery of site collection and copy it to SharePoint server and we can delete it from site template gallery.
  3. For adding this template to central administration site templates we need to execute the addtemplate stsadm command.
    “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.exe” -o addtemplate  -filename “G:\Shared\mysite.stp” -title “mysite” -description “mysite”
  4. Reset IIS

Now we can see the new site template under custom tab while creating site collection

No responses yet

Older posts »