Sharepoint 2007 - Access Denied when you try to edit
Recently I received an “Access Denied” error when I try to edit the list item in SP 2007.
I found the following solution from here (I coped same text below), which resolved the issue.
Here is the situation:
- In a site collection, you make a new list/document library in any sub-site or the main website.
- You then add a new item/document to the folder, and then attempt to edit the item
- You then see something along the lines of "Access Denied" , even if you are on the system account.
- This happens with every new list you create on any site or subsite.
Specifically the "Effective Permissions Mask" is missing an attribute in it's xml scheme -
RenderXMLUsingPattern="TRUE"
The fix comes in 3 steps:
1. Update your server to the most recent cumulative update package (Service pack 2 or greater). You can get more information about this from the Sharepoint team blog post on SP2. Included in SP2 is a hotfix that prevents this from occurring ever again on any other site collections, but it does not fix sites already effected by it.
2. To fix sites that are already having this problem, first we need to fix the field definition. Thanks to Vicki Dillon who pointed me in the right direction (but the wrong field =) )
The easiest way to accomplish this is to use: sharepoint manager 2007
- Run sharepoint manager 2007 and navigate to the site collection you are having problems with.
- Expand the site collection until you see "Fields"
- Scroll down this long list until you come to "Effective Permissions Mask" (also goes by the static name of PermMask )
- Go to the SchemaXML, copy it out into notepad to wordpad, and add the following value:
- RenderXMLUsingPattern="TRUE"
(I just tacked that onto the end, right before version="1")
This will prevent new lists from being created with out the RenderXMLUSingPatter=True value.
3. Now to fix the lists you already have made that need fixing.. You can either do this using SPmanger or you can do my favored option and fire up visual studio and compile the following code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Xml;
namespace CA_TestingHotfix
{
class Program
{
static void Main(string[] args)
{
FixField(args);
}
static void FixField(string[] args)
{
string RenderXMLPattenAttribute = "RenderXMLUsingPattern";
//Console.WriteLine("Please enter the URL of the site: (Press enter after typing):");
string weburl = args[0];
//Console.WriteLine("Please enter the Document Library Name: (Press enter after typing):");
string listName = args[1];
SPSite site = new SPSite(weburl);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[listName];
SPField f = list.Fields.GetFieldByInternalName("PermMask");
string s = f.SchemaXml;
Console.WriteLine("schemaXml before: " + s);
XmlDocument xd = new XmlDocument();
xd.LoadXml(s);
XmlElement xe = xd.DocumentElement;
if (xe.Attributes[RenderXMLPattenAttribute] == null)
{
XmlAttribute attr = xd.CreateAttribute(RenderXMLPattenAttribute);
attr.Value = "TRUE";
xe.Attributes.Append(attr);
}
string strXml = xe.OuterXml;
Console.WriteLine("schemaXml after: " + strXml);
f.SchemaXml = strXml;
}
}
} Since this touches the Sharepoint Model directly, remember to add the assembly reference to your local copy of Microsoft.sharepoint.dll to avoid compiling errors. Thanks to Jeff1024 for posting this code he got from the microsoft support team.
Run the program on the local server from the command line with two variables, the first one is the site that the list you are fixing is located in, the second is the name of the list to fix.
Finding Access Rights for Specific User in SharePoint 2007 using Powershell
Today I got a ticket saying, two users are not able to access the SharePoint site and not sure whether they have permissions or not. If they have what kinds of permissions? Since SharePoint 2007 don’t have an option to check, we depend on either on custom code or Powershell.
I want to do this pretty quick because of the ticket, I googled for powershell script and found the following site which really works well
http://www.sharepointdiary.com/2013/01/audit-user-permissions-in-sharepoint.html
Here is the code I got it from above mentioned site and made very few changes to make it dynamic
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") #DECLARE VARIABLES [string]$siteUrl = $args[0] [string]$userToFind = $args[2] #IF MISSING PARM FOR SITE URL, ASK FOR INPUT TO FILL if($args.length -eq 0) { DisplayMissingParametersMessage } function DisplayMissingParametersMessage { #Write-Output "You are missing a parameter for 'Site URL'" $script:siteURL = Read-Host "Enter Site URL" $script:userToFind = Read-Host "Enter User to Find" } #Get All Web Applications Function global:Get-SPWebApplication($WebAppURL) { if($WebAppURL -eq $null) #Get All Web Applications { $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} $WebApps = @() foreach ($websvc in $websvcs) { foreach ($WebApp in $websvc.WebApplications) { $WebApps = $WebApps + $WebApp } } return $WebApps } else #Get Web Application for given URL { return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL) } } Function global:Get-SPSite($url) { if($url -ne $null) { return New-Object Microsoft.SharePoint.SPSite($url) } } Function global:Get-SPWeb($url) { $site= Get-SPSite($url) if($site -ne $null) { $web=$site.OpenWeb(); } return $web } Function GetUserAccessReport($WebAppURL, $SearchUser) { #Get All Site Collections of the WebApp $SiteCollections = Get-SPWebApplication($WebAppURL) $SiteCollections= $SiteCollections.Sites #Write CSV- TAB Separated File) Header "URL `t Site/List `t Title `t PermissionType `t Permissions" | out-file UserAccessReport.csv #Check Whether the Search Users is a Farm Administrator $ca= [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local.Sites[0].RootWeb #Get Central Admin $AdminSite = Get-SPWeb($ca.URL) $AdminGroupName = $AdminSite.AssociatedOwnerGroup.Name $FarmAdminGroup = $AdminSite.SiteGroups[$AdminGroupName] foreach ($user in $FarmAdminGroup.users) { if($user.LoginName -eq $SearchUser) { "$($AdminSite.URL) `t Farm `t $($AdminSite.Title)`t Farm Administrator `t Farm Administrator" | Out-File UserAccessReport.csv -Append } } #Check Web Application Policies $WebApp= Get-SPWebApplication $WebAppURL foreach ($Policy in $WebApp.Policies) { #Check if the search users is member of the group if($Policy.UserName -eq $SearchUser) { #Write-Host $Policy.UserName $PolicyRoles=@() foreach($Role in $Policy.PolicyRoleBindings) { $PolicyRoles+= $Role.Name +";" } #Write-Host "Permissions: " $PolicyRoles "$($WebAppURL) `t Web Application `t $($AdminSite.Title)`t Web Application Policy `t $($PolicyRoles)" | Out-File UserAccessReport.csv -Append } } #Loop through all site collections foreach($Site in $SiteCollections) { #Check Whether the Search User is a Site Collection Administrator foreach($SiteCollAdmin in $Site.RootWeb.SiteAdministrators) { if($SiteCollAdmin.LoginName -eq $SearchUser) { "$($Site.RootWeb.Url) `t Site `t $($Site.RootWeb.Title)`t Site Collection Administrator `t Site Collection Administrator" | Out-File UserAccessReport.csv -Append } } #Loop throuh all Sub Sites foreach($Web in $Site.AllWebs) { if($Web.HasUniqueRoleAssignments -eq $True) { #Get all the users granted permissions to the list foreach($WebRoleAssignment in $Web.RoleAssignments ) { #Is it a User Account? if($WebRoleAssignment.Member.userlogin) { #Is the current user is the user we search for? if($WebRoleAssignment.Member.LoginName -eq $SearchUser) { #Write-Host $SearchUser has direct permissions to site $Web.Url #Get the Permissions assigned to user $WebUserPermissions=@() foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings) { $WebUserPermissions += $RoleDefinition.Name +";" } #write-host "with these permissions: " $WebUserPermissions #Send the Data to Log file "$($Web.Url) `t Site `t $($Web.Title)`t Direct Permission `t $($WebUserPermissions)" | Out-File UserAccessReport.csv -Append } } #Its a SharePoint Group, So search inside the group and check if the user is member of that group else { foreach($user in $WebRoleAssignment.member.users) { #Check if the search users is member of the group if($user.LoginName -eq $SearchUser) { #Write-Host "$SearchUser is Member of " $WebRoleAssignment.Member.Name "Group" #Get the Group's Permissions on site $WebGroupPermissions=@() foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings) { $WebGroupPermissions += $RoleDefinition.Name +";" } #write-host "Group has these permissions: " $WebGroupPermissions #Send the Data to Log file "$($Web.Url) `t Site `t $($Web.Title)`t Member of $($WebRoleAssignment.Member.Name) Group `t $($WebGroupPermissions)" | Out-File UserAccessReport.csv -Append } } } } } #******** Check Lists with Unique Permissions ********/ foreach($List in $Web.lists) { if($List.HasUniqueRoleAssignments -eq $True -and ($List.Hidden -eq $false)) { #Get all the users granted permissions to the list foreach($ListRoleAssignment in $List.RoleAssignments ) { #Is it a User Account? if($ListRoleAssignment.Member.userlogin) { #Is the current user is the user we search for? if($ListRoleAssignment.Member.LoginName -eq $SearchUser) { #Write-Host $SearchUser has direct permissions to List ($List.ParentWeb.Url)/($List.RootFolder.Url) #Get the Permissions assigned to user $ListUserPermissions=@() foreach ($RoleDefinition in $ListRoleAssignment.RoleDefinitionBindings) { $ListUserPermissions += $RoleDefinition.Name +";" } #write-host "with these permissions: " $ListUserPermissions #Send the Data to Log file "$($List.ParentWeb.Url)/$($List.RootFolder.Url) `t List `t $($List.Title)`t Direct Permissions `t $($ListUserPermissions)" | Out-File UserAccessReport.csv -Append } } #Its a SharePoint Group, So search inside the group and check if the user is member of that group else { foreach($user in $ListRoleAssignment.member.users) { if($user.LoginName -eq $SearchUser) { #Write-Host "$SearchUser is Member of " $ListRoleAssignment.Member.Name "Group" #Get the Group's Permissions on site $ListGroupPermissions=@() foreach ($RoleDefinition in $ListRoleAssignment.RoleDefinitionBindings) { $ListGroupPermissions += $RoleDefinition.Name +";" } #write-host "Group has these permissions: " $ListGroupPermissions #Send the Data to Log file "$($Web.Url) `t Site `t $($List.Title)`t Member of $($ListRoleAssignment.Member.Name) Group `t $($ListGroupPermissions)" | Out-File UserAccessReport.csv -Append } } } } } } } } } #Call the function to Check User Access GetUserAccessReport $siteUrl $userToFind
SharePoint 2013 App Model – How to View list With in APP
If you working on SharePoint 2013 APP, at some point you defiantly want to see list items contained within the app. Unfortunately there is no navigation to traverse to list.
To view specific list in “APP Web”, you directly type the url which specified in the following format in browser
http://<APP WEB URL>/<APP NAME>/Lists/<List Name>/AllItems.aspx
Ex: http://app-0eb6021fad963e.apps.com/sites/SP2K13/WhiteCaseEDARAPP/Lists/Calendar/AllItems.aspx
If in case you want to see the List settings,
- Click “Modify View” under List tab
- Click on “Settings” link as shown below
SharePoint 2007 – Custom Alert Template Issue
Recently one of our Business user requested to use “Custom Alerts on old SharePoint” even though we are in the process of upgrading to SharePoint 2013.
Anyway I found a nice article to implement “Custom Alert Templates” here. This is what I did, in simple steps.
- Created a copy of “AlertTemplates.xml” found in 12 hive\Templates\XML
- Created a new “AlertTemplate” section with in the XML and gave the unique name (simply copy the GeneraicList and renamed the Name)
- Made couple of changes to Styles and layout (adding new tables to show Company logo)
- Ran the STSADM command to update the template
- Create a small tool in VS to update the template name to specific list
- Reset the IIS
- Reset the SharePoint Timer Service
Even though I followed same as mentioned in the article, still alert emails are defaulting to the old template no matter what i did (Even I made exact changes to generic list section to see at least its falling into that)
After spending couple of days, I removed existing alerts on the list and created new one. Now i see the emails with update template.
I found out that, if we already have alerts setup on the list before updates, even you change the list to use different template (through code), SharePoint still sends alert emails using the template that was assigned to the list at the time of Alert setup.
Lesson learned !!!
SharePoint 2013 - “We’re having a problem opening this location in File Explorer, Add this web site to your Trusted sites list and try again”
I got the following error, when I try to open the library within file explorer, I received following error message
“We’re having a problem opening this location in File Explorer, Add this web site to your Trusted sites list and try again”
As it says, i tried to add the current site to Trusted List, but still having the issue to open in file explorer. After goggling a bit, I found that I have to enable the “WebClient” service.
Steps
1. Go to Run, type “Services.msc” and press Enter.
2. Select “WebClient” service and start the service, if you already have.
For me it’s not showing, so I have to Install “Desktop Experience” feature. To do that
1. Go to Run, type “Server Manager” and press Enter.
2. Select Features and then select Add Features
3. Select “Desktop Experience” checkbox and select “Add Required Features” on following popup screen
4. Click “Next”
5. Click “Install”
6. Once you restart the computer, start the “WebClient” service.
SharePoint DateTime Control Date Format
If you are working with DateTime Control in SharePoint, you might have a requirement to show date format (For example DD/MM/YYYY) based on the user regional setting instead of US date format (MM/DD/YYYY)
You can specify the regional settings locale id to DateTime local id on Page Load
int localId = Convert.ToInt32(SPContext.Current.RegionalSettings.LocaleId);
dtpcStartDate.LocaleId = localId;
If you want to change the default date format, no matter what the user regional setting is, you can do it my writing the custom control by deriving from the Microsoft.SharePoint.WebControls.DateTimeControl.
public class CustomDatePicker : Microsoft.SharePoint.WebControls.DateTimeControl
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
TextBox tb= (TextBox)this.Controls[0];
DateTime dt = DateTime.Parse(tb.Text);
tb.Text = dt.ToString("dd/MM/yyyy");
}
}
}
Note: For above code, I used the Autopostback = true to trigger OnPreRender event until i figure it out how to trigger onDateChangeed event client side.
How to show dates which has TBD at the end of the SharePoint List?
I am working on the two custom web parts, one of them is filter web part and another one is a results web part which shows data filtered from the SharePoint list based on the user selection. In the filter web part, we have a date range where they can specify certain range or just leave it empty so that we just return records which are greater than or equal to current date. Since dates are not mandatory in my SharePoint list (user don’t have a date and it is TBD – to be decided), it either shows empty dates at the top if i order by dates in ascending order without any filter criteria or it won’t show empty dates if i apply filter criteria.
But my requirement is,
- we should show empty dates (TBD)
- TBD should be at the end of the result set and not in the beginning of the result set.
To implement this, we created a calculated field and use the following formula
=IF(ISBLANK(DateColumn),DATE(2099,1,1),DateColumn)
Where
DateColumn – is a column we used to store the user selected date in the List.
Above formula we used max date (01/01/2099), so that we can easily use “Greater than or equal to” to compare with other dates and also sort dates in ascending order so that max dates will so at the end.
In the results web part, we are using XSLT to show the data and in that we are checking dateColumn empty or not, if empty show TBD or else show actual date.
Hope this helps some one and have a happy programming.
Connected Web Part Approaches
I found a very nice article about Connected web parts.
No Edit Page Option in Site Actions in MOSS 2007
Today I tried to Edit the Form pages to add Web Parts, for somehow, i Couldn’t see the option under Site Actions. I found a short cut to edit the page using ?ToolPaneView=2.
For Eg: http://SHAREPOINTSITE/Lists/Test List/NewForm.aspx?ToolPaneView=2
How to change Page Layout of existing page in SharePoint?
Recently a task was assigned to me to make sure that dev site should look like production one. First thing i noticed when i comparing two sites is both pages using different page layouts. so the question is how do you change the page layout which associated with your current page?
It is really simple once you know where to look.
- Go to the Page which you want to change. In my case i need to change my home page. so i browse http://mysite/home.aspx
- Click Site Actions and then select Edit Page option.
- On the toolbar, Click on Page and then select Page Settings
- Now you can pick your page layout
- Click OK once you done with your changes
Redirect a SharePoint Site/Page to another Site/Page using Content Editor Web Part
Redirecting the user from one site/page to another site/page is most common scenario.
You might have several reasons for this like Site Move from one location to another or Point Staging to Production etc..,
For whatever reason, you can achieve this functionality easily using Content Editor WebPart.
Copy and paste the following code into your Custom Editor WebPart
<script language=”JavaScript”>
alert(“The site has been moved to a new location and will automatically redirect to the location. Please update your bookmarks accordingly."”);
</script>
<meta http-equiv=”refresh” content=”0;url=http://[YOUR NEW LOCATION]”>
Once you save these changes, you are not able to modify any thing on this page since it is redirect to new location.
If in case you want to remove this webpart, the workaround is, you have to go through webpart maintenance page.
Copy the following code in Browser Address and make changes accordingly
http://[SERVERNAME]/_layouts/spcontnt.aspx?pageview=shared&url=[Your WebPart Page URL] (For Example: /FirmCalendar/pages/default.aspx)
Select the checkbox which you want to close, and click close button
To enable the closed WebParts follow these steps
1. Go To Site Actions –> Edit Page
2. Click on any Add WebParts
3. Click on “Advanced WebPart Gallery and Options”
4. Click on Closed Web Parts link
5. Drag and drop the Content Editor WebPart Where ever you want.
Hope this helps some one.
SharePoint DateTimeControl returns today's date if there is no selected date
By Default SharePoint DateTimeControl returns today's date if there is no selected date. Use IsDateEmpty to check whether user selected any date or not. If IsDateEmpty returns true, means no date selected by the user otherwise user selected the date and use that date.
if (!((DateTimeControl)c).IsDateEmpty)
{
columnValue = ((DateTimeControl)c).SelectedDate.ToString();
}
else
{
columnValue = "";
}
Event manager error: Could not load file or assembly
How to Delete SharedServices?
How to uncheck the send welcome email checkbox option globally?
In SharePoint, we have an option (checkbox) to send a welcome email to newly added users and this checkbox is checked by default. In my case this option is vary annoying since in most cases we don’t send an email to newly added users but sometimes i forgot to uncheck the checkbox. So i started looking into ways to ease my life.
First thing i want to find is, was there any global setting to flip the checkbox? but there is none. So my next option is modify/edit the aclInv.aspx page which is in Layouts folder in SharePoint hive.
- Navigate to SharePoint Hive\TEMPLATE\LAYUTS folder.
- Find the aclInv.aspx file.
- This step is optional but I recommend to backup this file before making any changes.
- open the aclInv.aspx in editor.
- Search for “chkSendEmail”.
- Change Checked property from True to False.
- Save the page.
Repeat the same steps in all web front end servers.
Custom Actions in SharePoint 2007
WSS 3.0 and MOSS 2007 now have a supported extensibility mechanism allowing developers to easily add links to existing menus or Site Settings.
Custom Actions can be used to add new custom functionality to many places in WSS and MOSS. Depending on where the custom action is located determines the user interface of the custom action. For example if you create a custom action for the Site Actions menu the result is a menu item anchored in the control. If you create a Custom Action for the Site Settings page you will see a link. Creating a custom action for a list's display form toolbar results in a toolbar button. As you can see just from this small list a Custom Action provides a lot of extensibility in WSS and MOSS.
Each custom action exists in a specific location, and depending on that location, can be a part of a group of actions. You can find the Default Custom Action Locations and IDs in Microsoft site.
With a custom action feature, you can:
- Add a new Custom Action Group which can be used to group custom actions in a specific options screen;
- Add a new Custom Action which can be a new option in a settings screen, a new menu item, or a new toolbar button;
- Hide an existing Custom Action whether that action is the result of custom action feature or it belongs to SharePoint's out-of-the-box features.
How to Create a Custom Action Feature
- Create a new Project in VS 2008.
- Within the project create the following folder structure
- Within the MyCustomActions folder, Add a new item and select XML file. Name it as CustomActions.xml
- Add the following text and make the changes accordingly.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Custom Action Group -->
<CustomActionGroup
Id="MyActionGroup"
Description="This group contains all my custom actions."
Title="My Action Group"
Location="Microsoft.SharePoint.SiteSettings"
Sequence="30" />
<!-- Custom Action in Custom Action Group -->
<CustomAction
Id="MyCustomAction"
Description="This link is a custom action."
Title="My Custom Action"
GroupId="MyActionGroup"
Location="Microsoft.SharePoint.SiteSettings"
Rights="ManageWeb"
RequireSiteAdministrator="FALSE"
Sequence="20">
<UrlAction Url="~sitecollection/_layouts/MyCustomPage1.aspx" />
</CustomAction>
<!-- Custom Action in Site Actions Menu -->
<CustomAction
Id="MyNewCustomAction"
Description="This menu item is a new custom action."
Title="My New Custom Action"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
ImageUrl="/_layouts/MyActionIcon.jpg"
Sequence="10">
<UrlAction Url="~sitecollection/_layouts/MyCustomPage2.aspx" />
</CustomAction>
<!-- Hide Custom Action -->
<HideCustomAction
Id="HideDeleteWeb"
GroupId="SiteAdministration"
Location="Microsoft.SharePoint.SiteSettings"
HideActionId="DeleteWeb" />
</Elements>
- Within the MyCustomActions folder, Add a new item and select XML file. Name it as feature.xml
- Add the following text and make the changes accordingly.
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="Paste your NEW GUID Here"
Title="My Custom Actions"
Description="My Custom Actions"
Version="12.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="CustomActions.xml" />
</ElementManifests>
</Feature>
- Build the project using WSPBuilder and deploy the WSP.
Custom Actions really provide us with a great mechanism to place our needed extensions into the menus of WSS and SPS. This post about Custom Actions is a very simple start to what you can do. If you want to know more about Features, check this nice article SharePoint 2007 Deployment: Overview.
Understanding Web Part Life Cycle
If you are writing web parts either in ASP.NET or SharePoint, you need to understand the events and order of execution.
In this post i am trying to summarize the events and its order
OnInit – Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part.
LoadViewState – The view state of the web part is populated over here.
CreateChildControls – All the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() - It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.
OnLoad
User Generated Event – for e.g. button click on the web part.
OnPreRender – Here we can change any of the web part properties before the control output is
drawn.
RenderContents – Html Output is generated.
SaveViewState - View state of the web part is serialized and saved.
Dispose
UnLoad.