Month: November 2009

How to hide a column of SharePoint list in different mode (Add / Edit / Display Mode)?

Posted on Updated on

Most of the time we have requirement like that this field should be shown only in new mode or it should not be shown only in Edit mode not in new mode.

We can hide it in view by not to show in grid view but what to do if you do not want to see that field in Dispforms.aspx?

Here is the way how to do that.
Option: 1
OBJECT MODEL

SPSite site = new SPSite(”http://Server:3000/”);
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists[”Sample”];
SPField objField = list.Fields[”Sample1″];
objField.ShowInNewForm = true;
objField.ShowInDisplayForm = false;
objField.ShowInEditForm = true;
objField.Update();
list.Update();

Option: 2
List Definition
You can hide column appearing in New/Edit/View/ form by creating custom list defination for the list.

For creating custom list defination you can refer following MSDN link:
http://msdn.microsoft.com/en-us/library/ms466023.aspx

Now to hide a column from New/Edit/View/ form, you need to update content types of your list schema. Following is steps to do this (Assuming you have created custom list defination, following the steps mentioned in above URL):
1. Open schema.xml from your custom feature folder
2. Locate Content Types XML node, under that locates the Field which you want to hide from Edit form, set the ShowInEditForm value to FALSE.

Following example hides the Title column of custom list appearing in Edit form:

<FieldRef ID=”{fa564e0f-0c70-4ab9-b863-0177e6ddd247}” Name=”Title” Required=”TRUE” ShowInNewForm=”TRUE” ShowInEditForm=”FALSE” />

Advertisements

SharePoint Site Template Size

Posted on Updated on

When you turn an existing site into a template and include the content, there is a size limit of 10 Mb by default. If you site content is greater than this, a site template will not be created.
You can change this maximum size using an stsadm command on the SharePoint server.

stsadm -o setproperty -propertyname max-template-document-size -propertyvalue  size_in_bytes
 
Where size can be up to 500Mb (524288000 bytes)

Windows PowerShell Out-Performing Stsadm Scenario

Posted on Updated on

The Developer needs to activate a feature across 5,500 site collections. By using Windows PowerShell to run the Stsadm command, he came up with the following script to automate the work:

foreach ($site in (get-spsite -limit 5000000 -Webapplication $WebApp))
{            
 Write-Host “Activating feature ” $solutionName “on” $site.url “…”;
 Write-Host stsadm “-o activatefeature -url” $site.url “-filename” $featureFileName;
 stsadm -o activatefeature -url $site.url -filename $featureFileName
   if( $lastexitcode -ne 0 )
   {             
               Write-Host “Something went wrong activating the site feature. Exit code: ” $lastexitcode “`n”  –               ForegroundColor Red;
               $failure = $true;
               $error.Clear();
    }
}

When he ran the script in her test environment, he found it took more than 12 hours to run. The Developer then decided to look for a better way of doing things. After talking to Grant, he found out there was built-in cmdlet to do this exact task. he then tried this script:

Get-SPSite –Limit ALL –WebApplication $WebAppNameorUrl |%{ Enable-SPFeature $FeatureIdOrName –url $_.Url }

The script ran in less than one hour. Lesson learned: If Stsadm.exe can do the operation, Windows PowerShell can do it too, and generally more efficiently.

SharePoint List Form Validation

Posted on Updated on

You Can Use “PreSaveAction()” Function to Execute any JavaScript Code in New or Edit Forms. When Pressing OK button this Function will be Executed First

You Can Use this Function For Validation without PostBack

PreSaveAction()
{
//
Add Your JavaScript Code Here Then Return True Or False

return false; // Cancel the item save process

return true; // OK to proceed with the save item
}