Posted by ken zheng on November 4, 2009
If you received this error when use session in your custom aspx page deployed to SharePoint:
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.
If you add “EnableSessionState=”true” “ to your it should enable it but also you need to modify you web.config
The problem is that by default, Sharepoint does not allow server side code in .aspx pages by default. You need to enable this using PageParserPath. Add the PageParserPath inside of the PageParserPaths node of the web.config file, changing the virtual path to the path you want to enable. Or you can use /Pages/* as the value if they are in the same folder
Posted in Sharepoint | Tagged: Custom Page, Sharepoint | Leave a Comment »
Posted by ken zheng on November 3, 2009
The server-packages of October 2009 Cumulative Update for Microsoft Office SharePoint Server 2007 and Windows SharePoint Services 3.0 are ready for download. October 2009 Cumulative Updates introduce more rules on Pre-Upgrade Checker, which can help customers to prepare the upgrade of their SharePoint farm to SharePoint 2010.
Download Information
Windows SharePoint Services 3.0 October 2009 cumulative update package
http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=974989
Office SharePoint Server 2007 October 2009 cumulative update package
http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=974988
Detail Description
Description of the Windows SharePoint Services 3.0 October 2009 cumulative update package
http://support.microsoft.com/kb/974989
Description of the Office SharePoint Server 2007 October 2009 cumulative update package
http://support.microsoft.com/kb/974988
Installation Recommendation for a fresh SharePoint Server
To keep all files in a SharePoint installation up-to-date, the following sequence is recommended.
1. Service Pack 2 for Windows SharePoint Services 3.0 and language packs
2. Service Pack 2 for Office SharePoint Server 2007 and language packs
3. October 2009 Cumulative Update package for Windows SharePoint Services 3.0
4. October 2009 Cumulative Update package for Office SharePoint Server 2007
Please note: Start from April 2009 Cumulative Update, the packages will no longer install on a farm without a service pack installed. You must have installed either Service Pack 1 (SP1) or SP2 prior to the installation of the cumulative updates.
After applying the preceding updates, run the SharePoint Products and Technologies Configuration Wizard or “psconfig -cmd upgrade -inplace b2b -wait” in command line. This needs to be done on every server in the farm with SharePoint installed.
The version of content databases should be 12.0.6520.5000 after successfully applying these updates.
You can also refer to April Cumulative Update post for deployment guides, slipstream how-to links and FAQs.
Posted in Sharepoint | Tagged: Sharepoint | Leave a Comment »
Posted by ken zheng on October 29, 2009
Sometime you get this error when you deployed a web part which use references. To fix the problem, you need to open your aspx page and add references like , even you are not useing it in your UI
Posted in Sharepoint | Tagged: Sharepoint, SharePoint2007, Smart Part | Leave a Comment »
Posted by ken zheng on October 22, 2009
The followong script is to recursively remove documents from a library only. A few examples for Announcement from here.
To remove the items just uncomment the $items | % { $_.Delete() }
#Start-Transcript ‘c:\powershell\logs\transcript.txt’
[System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$weburl = "http://winsvr2008/kenny"
$contenttype = "Document"
$site = new-object Microsoft.SharePoint.SPSite($weburl)
$web = $site.OpenWeb()
$list = $web.Lists["Test Doc"]
# $list | foreach { $_.Items | select Name, ContentType }
$caml='<Where><Eq><FieldRef Name="ContentType" /><Value Type="Text">'+ $contenttype + '</Value></Eq></Where>'
$query=new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$query.Query=$caml
$items=$list.GetItems($query)
# Pipe results to a loop and delete each element
#$items | % { $_.Delete() }
$items.Count
$items | select Name
$web.Dispose()
$site.Dispose()
#Stop-Transcript
Posted in PowerShell, Sharepoint | Tagged: PowerShell, Sharepoint | Leave a Comment »
Posted by ken zheng on October 22, 2009
PowerGUI is a great tool to write scripts. I just play around the PowerShell script and add here for furture reference:
The first step in connecting to SharePoint is to load the necessary .Net library. This can be done with the following command:
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$site = New-Object Microsoft.SharePoint.SPSite("http://adbmoss")
# Connect to the site collection http://adbmoss and store the object in the $site variable
$site | get-member
# Display all the properties and methods for the object in $site
$site.set_readonly($True)
# Set the site collection to read only. No updates are allowed
$site.set_readonly($False)
# Set the site collection back to read-write
$root = $site.rootweb
# Connect to the root site in the site collection and store the object in $root
$root | get-member
# Display all the properties and methods for the object in $root
$root.lists | format-table -property title, author
# Display title and authors for all the lists in the root site
$root.lists | ?{$_.iscatalog -eq $null} | format-table -property title, author
# Filter the lists to show only the user lists. The $_ symbol refers to the object in the piple line. The ? symbol is an alias for the where-object commandlet.
$root.listtemplates | format-table -property name
# Show all the available list templates for the root web
$TempCal=$root.listtemplates["Calendar"]
# Store the Calendar template in a variable $TempCal
$root.lists.add("Events","Company Events", $tempCal)
# Create a list called “Events” with Description “Company Events” on the calendar template
import-csv dept.csv | %{$root.lists.add($_.Dept, $_.Descr,$root.listtemplates[$_.Temp])}
# Create a new list for ever line in a CSV file where the name for the list is saved in the Dept column of the file, the description is in the Descr column, and the type of list to create is in the Temp column. First check that the lists are correctly created before you continue. The % symbol is an alias for the foreach-object commandlet and places each instance of the collection in the pipeline one after the other.
import-csv dept.csv | %{$root.lists[$_.Dept].delete()}
# Use the CSV file again to delete all the create lists again.
You can user PowerShell to provision additional columns in a custom list as well. The following commands show how to accomplish that.
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
# Load SharePoint library
$site = New-Object Microsoft.SharePoint.SPSite("http://adbmoss")
# Connect to the site collection http://adbmoss and store the object in the $site variable
$root = $site.rootweb
# Connect to the root site in the site collection and store the object in $root
$root.lists.add("CTest","Custom Test",$root.listtemplates["Custom List"])
# Create a new list called “CTest” from the template “Custom List”
$list = $root.lists["CTest"]
# Set a variable $list to the custom list that was just created.
$list.fields.add("T1","Text",0)
# Create a new field of type Single Line Text with the name of “T1”. The field is not required (last parameter)
The scenario below was that the documents were already in the library and they had a spreadsheet with the id number of the document and some additional meta-information. This can also be done in PowerShell. The first step is to save the spreadsheet in CSV format or any other format that PowerShell can easily import. The following code shows how to go about importing the metadata.
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
# Load SharePoint library
$site = New-Object Microsoft.SharePoint.SPSite("http://adbmoss")
# Connect to the site collection http://adbmoss and store the object in the $site variable
$root = $site.rootweb
# Connect to the root site in the site collection and store the object in $root
$docs = $root.lists["Shared Documents"]
# Store the Shared Documents document library in a variable $Docs
import-csv DocProps.CSV | %{$item = $Docs.items[$_.id]; $item["Title"] = $_.Title; $Item["Group"] = $_.group; $Item.Update()}
# Loop through the csv file and update the properties
The last line of the code is quite complex, so what it means are:
import-csv DocProps.CSV # Import the data from the DocProps CSV file
| # Pipe the results to the group
%{ # For each (%) line in the csv file do begin ({)
$item = $Docs.items[$_.id]; # set the variable $item to the entry in the list where the id corresponds to the id column in the file. The semicolon (;) indicates the separate command is to follow
$item["Title"] = $_.Title; # set the title of $item to Title in the file
$Item["Group"] = $_.group; # set the Group metadata property to the group Column in the file
$Item.Update() # update the entry $item in the list
} # End (}) the loop
Posted in PowerShell, Sharepoint | Tagged: PowerShell, Sharepoint | Leave a Comment »
Posted by ken zheng on October 21, 2009
Every time I executed the code, some error came up. Most of the time, it was either “Access Denied” or “The security validation for this page is invalid”.
I ran the code using RunWithElevatedPrivileges, but that didn’t help much. Neither did the SPWeb.AllowUnsafeUpdates property.
Now the below code to rescue me:
SPSite.WebApplication.FormDigestSettings.Enabled = false
But you will have to use it in RunWithElevatedPrivileges scope:
public void EditSecurity()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
SPWebApplication webApp = web.Site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
web.AllowUnsafeUpdates = true;
SPGroup group = web.SiteGroups["groupname"];
SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)group);
SPRoleDefinition roleDefinition;
roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor); // Gets a predefined role definition
roleDefinition = web.RoleDefinitions["customRole"]; // Gets a custom defined role definition
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
web.RoleAssignments.Add(roleAssignment);
web.Update();
web.AllowUnsafeUpdates = false;
webApp.FormDigestSettings.Enabled = true;
}
}
});
}
Posted in Sharepoint | Tagged: Security, Sharepoint | Leave a Comment »
Posted by ken zheng on October 21, 2009
To add new user to the web is very common process but fails most time. See http://sharepointsearch.com/cs/blogs/sharepointblogs/archive/2007/12/20/using-spweb-ensureuser-loginname-to-add-a-new-spuser-to-a-web.aspx for more details.
The way to solve this problem is to user SPWeb.EnsureUser(loginName).The description in the SDK for EnsureUser is:
“Checks whether the specified login name belongs to a valid user of the Web site, and if the login name does not already exist, adds it to the Web site.” Which happens to be exactly what we want!
Now we can finish our code:
SPUser newUser = newWeb.EnsureUser(@"domain\username");
newWeb.AllowUnsafeUpdates = true;
// Create the new roleassignment that we want to add to the collection of roleassignments of the new web
SPRoleAssignment roleAssignment = new SPRoleAssignment(newUser);
SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;
// Add the binding to the correct roledefinition to the roleassignment
// This can also be Contribute for contributor rights.
// Keep in mind that in sites in other languages this needs to be translated
roleDefBindings.Add(roleDefinitions["Read"]);
roleAssignments.Add(roleAssignment);
newWeb.AllowUnsafeUpdates = false;
newWeb.Dispose();
portalSite.Dispose();
Posted in Sharepoint | Tagged: Sharepoint, SPUser | Leave a Comment »
Posted by ken zheng on June 30, 2009
The code below is to use the global navigation bar and Inherit site master page from parent of this site
projectDetailWeb.Navigation.UseShared = true;
//set masterpage to Inherit site master page from parent of this site
projectDetailWeb.MasterUrl = projectDetailWeb.ParentWeb.MasterUrl;
projectDetailWeb.AllProperties["__InheritsMasterUrl"] = "True";
projectDetailWeb.CustomMasterUrl = projectDetailWeb.ParentWeb.CustomMasterUrl;
projectDetailWeb.AllProperties["__InheritsCustomMasterUrl"] = "True";
projectDetailWeb.AlternateCssUrl = projectDetailWeb.ParentWeb.AlternateCssUrl;
projectDetailWeb.AllProperties["__InheritsAlternateCssUrl"] = "True";
projectDetailWeb.Update();
Posted in Sharepoint | Tagged: Sharepoint, Site Master Page | 1 Comment »
Posted by ken zheng on June 16, 2009
Sometime the list web part doesn’t show the change view dropdown list, I found this soltuion by just removing the web part and re-add it from the closed web part in Advanced Web Part gallery and options. It works.
See the blog for more details
Posted in Sharepoint | Tagged: Sharepoint | Leave a Comment »
Posted by ken zheng on May 13, 2009
I got the below errors on the SharePoint Server in every minute. This looked like the incoming email drop folder was not setup properly in the Central Admin Console. We checked and sure enough the drop folder was empty. Setting that value fixed this error. To set the drop folder
Central Admin-> Incoming email settings
Click Advanced and type in the email drop folder.
Event Type: Error
Event Source: Windows SharePoint Services 3
Event Category: E-Mail
Event ID: 6872
Date: 5/25/2008
Time: 9:16:22 AM
User: N/A
Computer:
Description:A critical error occurred while processing the incoming e-mail drop folder.
The error was: Value cannot be null.
Parameter name: path.
For more information, see Help and Support Center at
Event Type: Error
Event Source: Windows SharePoint Services 3
Event Category: Timer
Event ID: 6398
Date: 5/25/2008
Time: 9:16:22 AM
User: N/A
Computer:
Description:The Execute method of job definition Microsoft.SharePoint.Administration.SPIncomingEmailJobDefinition (ID 15cb7ef8-cfa0-4d8e-9892-4deb1c69d0f7) threw an exception. More information is included below.
Value cannot be null.
Parameter name: path
Posted in Sharepoint | Tagged: Sharepoint | Leave a Comment »