Showing posts with label sharepoint 2010. Show all posts
Showing posts with label sharepoint 2010. Show all posts

Sunday, August 4, 2013

PowerShell to Find ListItems Modified Since a Date

Assuming that the list to be queried is already referenced in the $list object in script, here is a simple snippet to retrieve all list items that have been modified within the last one hundred days:

$previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '<where><Gt><FieldRef Name="Modified" /><Value Type="DateTime">{0}</Value></Gt></Where>' -f $previousRunDate $query = New-Object Microsoft.SharePoint.SPQuery $query.Query = $camlQuery $listItems = $list.GetItems($query) $previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '{0}' -f $previousRunDate $query = New-Object Microsoft.SharePoint.SPQuery $query.Query = $camlQuery $listItems = $list.GetItems($query)

Wednesday, January 4, 2012

Setting BCS Secondary Fields Programmatically in SharePoint 2010

Phew, that was quite a battle. I have been writing some code to import values from a CSV file into some custom lists in SharePoint (I realise that there are, of course, plenty of other ways to import into SharePoint, such as using PowerShell or a third party app., but specific needs call for special handling), and one of the requirements is to import data into External Columns in the SharePoint list.

Original this process used the GetSecondaryFieldNames() method of the SPBusinessDataField instance to get the internal names of each of the secondary fields, and then combined each of those with the internal name of the SPBusinessDataField to create the displayname value for each secondary field. The list item fields could then be set using these displayname values.

This worked fine in the dev environment... but of course the real workd is different! Researching the failure of this process on the target machine showed that the display names for the secondary fields did not contain the values from the GetSecondaryFieldNames() call (PowerShell allowed me to easily view the Schema XML for the fields in the list, saving the need for a tool like SharePoint Manager).

So, my solution was to seek the secondary field by enumerating through all fields in the list, seeking the field whose:
  • "DisplayName" property value starts with the internal name of the related external data field
  • "BdcField" property value matches a string value returned by GetSecondaryFieldNames()
This lets me find the required secondary BCS field, and gived me the GUID for use in later populating that field with a value. I then make sure to cache this GUID, meaning on the next pass through this part of the code I can use the cached value rather than re-enumerating all the fields once again.

Monday, September 12, 2011

SharePoint 2010 Timer Job Journey of Discovery - Updating Web App Properties

So there I was, creating a SharePoint 2010 Timer Job to retrieve and aggregate tag information from the Social Data Service. Using a pattern that worked well in SharePoint 2007, the feature receiver in the solution was tailored to save information for each execution of the job to the property bag of the web application.
But the timer job failed to register when activating this solution through the features admin page on the site. The event log showed an "Access denied" SecurityException error, occuring in the call to SPWebApplication.Update(). The code was simply attempting to set a web application property at that stage.

Time passes... Lots of experimentation and research.... Finally discovered the cause is related to applying least privileges access to accounts on the server install. The account under which the feature gets activated when clicking on "Activate" in the browser UI does not have sufficient rights to make changes in the configuration database. And web application property bag settings seem to be saved to the configuration database rather than to a content database (makes sense, I guess, as a web app can be associated with multiple content databases).

The solution therefore is to activate the feature using PowerShell whilst logged in with an account having update rights on the config database - for instance, using the setup account (which you used during installation, of course, didn't you?!)

Thursday, August 11, 2011

Secure Store Application Error 8306

After much experimenting on the SharePoint 2010 server, following tips on the "Claims to Windows Tokens Service" and the settings of the SecurityTokenServiceApplication web service site, finally found that the 8306 error being frequently logged was due to Forms Authentication being enabled in the SecurityTokenServiceApplication web service site. Disabling Forms Authentication removed the issue on the Secure Store Service Application management page in Central Admin

To check this setting, open IIS Admin, browse in the left-hand pane to Sites > SharePoint Web Services > SecurityTokenService Application, and in the IIS section in the right-hand pane open the "Authentication" settings. Only "Anonymous Authentication" and "Windows Authentication" should be enabled.

The 8306 error in the event log was : "An exception occurred when trying to issue security tokens". Thanks to the threads at http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/49508c3a-e44b-4b3a-ad94-0e9957b9e025/ and http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/580a6e7a-e26e-47aa-a6d8-51563b7d27de/ for the final bit of assistance in tracing this one.

Monday, June 20, 2011

Watch your Ports When Configuring AAMs

Found (the hard way) that SharePoint 2010 is not happy when an Alternate Access Mapping is configured with a port on the public URL that is different than the port on the corresponding Internal URLs.

For an extranet I was creating using SharePoint Foundation 2010, we were using port 80 on the external-facing side of the firewall. The firewall was redirecting those calls to port 81 on an internal IP address. So I had setup the extranet zone in AAM to have [some site]:80 as the public URL, and [some internal ip address]:81 as an Internal URL in that same zone.

[Various reasons for not using host headers in this instance, and for using port 81 for the SharePoint web app!]

Could access the site inside the firewall, but failed to get to the SharePoint pages from outside. Much analysis using Fiddler and the MS Network Monitor 3.4 (great tool, that one - really easy parsing of results) revealed that something was redirecting the client from [some site]:80 to [some site]:81 for the external calls. Still don't know whether IIS or SharePoint was responsible for this - just know that by changing the firewall to pass through on port 81, and calling [some site]:81 from outside, then all was well again.

So what I learnt today - don't mix ports across AAM internal and external URLs

Wednesday, June 1, 2011

Refinement Filtering in the SharePoint Search URL

The refinement filter querystring is the "r" term in a search result page URL. An example of its use is

http://intranet/search/pages/phonelist.aspx?k=christchurch&r=department%3a%22Human%20Resources%22

The value of the “r” term in the querystring decodes to

Department:”Human Resources”

Some documentation (and the links generated by the refiner web part) use a “=” character, but in my experimentation it seemed that only the “:” character would return results. Further research has shown that the “:” (%3A) character denotes a “contains” comparison whereas “=”(%3D) not surprisingly means “equals” (and yet the “equals” operation does not seem to retrieve any results in my trials)

Sunday, April 10, 2011

Finding the SharePoint Site Collection URL on the Client

Little tip - if your client-side code needs to know the URL of the site collection hosting a SharePoint page, have a look at the properties of the _spPageContextInfo object in the HTML source of the page.

This JavaScript object is written into each page, and contains useful information about that page. For my requirement, the _spPageContextInfo.siteServerRelativeUrl property contains the value I needed.

Simple Glossary App (Beta) for SharePoint Released

Have just published details of a new simple glossary/theasaurus application for SharePoint - OneStride Define. The idea behind this, and other layers planned for the framework, is to offer a way to layer interactivity and information on top of existing SharePoint pages.

No need to modify pages that already refer to a word that needs to be clearly defined - just add that word to a dedicated list in SharePoint, and any occurrence of that word in published pages or text fields in lists will be linked to the definition. Nice n' simple.
Highlighted Term On SharePoint Page

An additional benefit is that the framework and this first "layer" are supplied as sandboxed solutions, meaning that they can be deployed through the browser, run isolated from the rest of SharePoint and are suitable for use in hosted SharePoint (Office 365 here we come!).

This beta will be available until the end of May 2011. Have a look and let me know what you think!

Sunday, October 10, 2010

Web Application with Host Header on Port 80 Fails

Adding new SharePoint web applications on port 80 is easy by associating a host header name, but I was unable to view the site collection in the new web application with IE - the login dialog box would show three times, and then just a blank page, even though my account was the primary site collection administrator.

Turns out that in Windows 2008 R2 it is necessary to disable the loopback check. Open the Powershell ISE or console (as administrator to get sufficient registry permissions!) and run the following script:

New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword

Thanks to Ignacio Montenegro of IGA Systems for that tip.

Thursday, September 30, 2010

Where's the "Configure Incoming Email Settings" Link?

If you cannot see the "Configure incoming e-mail settings" link in SharePoint 2010 central administration, and are sure you have all the permissions you require, try right-clicking on an IE icon and selecting "Run as administrator" from the context menu. In that instance of Internet Explorer, you may well see the link you are seeking!

Thursday, September 16, 2010

Access Denied for Configure Service Accounts Link

Clicking on the "Configure Service Accounts" link on a SharePoint 2010 server resulted in an "Access Denied" message.

Resolution of this issue is to run IE with Elevated Permissions by right clicking on an IE shortcut and selecting "Run as administrator"

Friday, September 3, 2010

At Last - Tame the Core CSS FIle!

Thanks to the blog of buta no le, I could solve that nasty issue of corev4.css being placed after my custom CSS file when using the SharePoint.CSSRegistration tag.

The reason I want to use that tag is that it allows the use of tokens to derive the actual site collection URL (as opposed to having to hard code the URL, and then editing the masterpage on the client site). In MOSS, SharePoint.CSSRegistration always places the core CSS file at the end of all the registered CSS files, thereby rendering useless any style overrides in your own files.

But SharePoint 2010 adds the "After" attribute to the tag. Nice! Now I can insert the following in the masterpage, and dictate my own styles over the core ones (note that the name actually needs to be enclosed in angle brackets!)

SharePoint:CSSRegistrationName="% $SPUrl:~sitecollection/style library/state.css
%" After="corev4.css" Runat="server"/>

Tuesday, July 27, 2010

SP2010 - Get the Item ID from the OpenPopUpPage Link

Just wanted to record here a simple little jQuery script useful for retrieving the item ID from the OpenPopUpPage hyperlink that is rendered for lookup column values in a Data View Web Part in SharePoint 2010. The useful thing about this is that you can then manipulate the action of the hyperlink to pass this item id to a different page - without having to look at changing the field type in any way.

The lookup field is rendered in a DVWP with the following onclick action:

OpenPopUpPage( 'http://blah/_layouts/listform.aspx?PageType=4&ListId={FFFC7FEA-62B2-459F-9D1B-80B6CA3608FF}&ID=23&RootFolder=*', RefreshPage);


The XSL (in the DVWP) that is rendering this lookup value is as follows:


Trust Partner:





[An aside: "table-based HTML?" you may ask. Well, sometimes expedience wins over web standards, though I am usually a standards-based advocate!]


The jQuery script to extract and use the item ID is:

$(function() {
$('.linktoentitydetails').each(function() {
var $link = $(this).find('a');
var href = $link.attr('href');
if (href != '') {
var itemIdMatches = href.match(/.*&id=(\d+)&.+/i)
if (itemIdMatches.length == 2) {
var itemId = itemIdMatches[1];
$link.removeAttr('onclick');
$link.attr('href', 'persondetails.aspx?eid=' + itemId);
}
}
});
});

So, in this case, I am replacing the OpenPopUpPage hyperlink action with a simple link to a custom page (persondetails.aspx) on which I can present other information about this linked item.

Saturday, May 29, 2010

SharePoint Connection Error in Visual Studio 2010

When running Visual Studio 2010 on a Windows Server 2008 R2 / SQL Server 2008 / SharePoint 2010 development box, even though the logged-in account has local admin rights on the server, I still experienced a SharePoint Connection Error in Visual Studio 2010 on that same Virtual Machine. The text in the error dialog states that "the local SharePoint Server is not available".

Seems the error is caused be the logged-in account having insufficient rights against the SharePoint databases. Log into the SQL Server using the administrator account, and grant rights to the developer account; db_owner rights on the SharePoint configuration and admin database is reported to be sufficient -but as in this instance I was dealing with a development virtual machine, I opted for the easy route of granting sysadmin role to the dev user account :-)