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

Tuesday, May 2, 2017

Opening a form as a Site Member gives: "Sorry, you don't have access to this page"

Symptom: 
You have a SharePoint list and the user reporting the issue is a Site Member. When the user tries to open a list item in view mode they are redirected to a page with the message: "Sorry, you don't have access to this page"

Issue: 
The issue I had was that one of the fields in the list was a person field. This field restricted the choice of people to a SharePoint Group. On checking this SharePoint security group. I found that the setting for this group "Who can view the membership of the group" was set to "Group Members".

Resolution:
Once I changed the "Who can view the membership of the group" to "Everyone" everything worked as expected.

Wednesday, November 20, 2013

SharePoint field + XML = Blank field

Intro:
I've been tasked with storing the contents of an RSS feed (xml) to SharePoint via a Custom Timer Job.

When I tried to run the following code. I simply got a blank field for the "RSSContents" field of the new item.

using (System.Net.WebClient client = new System.Net.WebClient())
{
using (Stream data = client.OpenRead("http://www.bom.gov.au/fwo/IDZ00059.warnings_vic.xml"))
{
using (StreamReader reader = new StreamReader(data))
{
    SPWebApplication webApp = this.Parent as SPWebApplication;
    SPList list = webApp.Sites[0].RootWeb.Lists["TimerTest"];
    SPListItem newListItem = list.Items.Add();
    newListItem["Title"] = DateTime.Now.ToString();
    string s = reader.ReadToEnd();
    newListItem["RSSContents"] = s;
    newListItem.Update();
}
}
}

Workaround:
Add HtmlEncode into the mix:
using (System.Net.WebClient client = new System.Net.WebClient())
{
using (Stream data = client.OpenRead("http://www.bom.gov.au/fwo/IDZ00059.warnings_vic.xml"))
{
using (StreamReader reader = new StreamReader(data))
{
    SPWebApplication webApp = this.Parent as SPWebApplication;
    SPList list = webApp.Sites[0].RootWeb.Lists["TimerTest"];
    SPListItem newListItem = list.Items.Add();
    newListItem["Title"] = DateTime.Now.ToString();
    string s = reader.ReadToEnd();
    s = WebUtility.HtmlEncode(s);
    newListItem["RSSContents"] = s;
    newListItem.Update();
}
}
}

I'm working in a SharePoint 2013 environment. So your results may vary. But I suspect this is the same across each of the different SharePoint versions. 

How to: Debug a timer job deployment?

Intro:
So I've been tasked with writing a Custom SharePoint timer job.
So I googled it up and I followed Andrew Connell's article
http://www.andrewconnell.com/Creating-Custom-SharePoint-Timer-Jobs

Symptoms:
After I made modifications to suit my needs I go and try to deploy it (by pressing F5). After which I get a very descriptive message:
Error occurred in deployment step 'Activate Features': Object reference not set to an instance of an object.
So I comment out every line of the "Activate Features" code and try to diagnose it. Breakpoints don't seem to work.

Workaround/Resolution:
Insert
System.Diagnostics.Debugger.Launch();
into your code and if all goes right Visual Studio will pick up the task of debugging your code.

Tuesday, October 8, 2013

jMeter 2.9 & SharePoint 2010

Intro:
So I was tasked to find the cheapest way to apply load onto a SharePoint environment. Found jMeter which lots of people raved about.

My sample SharePoint environment is:
Windows 2012 Standard
SharePoint 2013
JMeter 2.9

Symptoms/Issue:
So I created a simple load test to hit the default page of my site collection but all I got were 401s.
Response code: 401
Response message: Unauthorized
HTTP/1.1 401 Unauthorized

How to create a basic page request in JMeter for SharePoint:
  1. Download Java Runtime Environment: http://www.java.com/en/download/index.jsp
  2. Download JMeter: https://jmeter.apache.org/download_jmeter.cgi
  3. Extract JMeter.
  4. Run jmeter.bat from the bin folder.
  5. Right click Test Plan > Add > Threads (User) > Thread Group
  6. Right click on "Thread Group" > Add > Sampler > HTTP Request
  7. In the new HTTP Request you just added:
  8. Server Name or IP: uri of your site collection (without the http(s)). For example if the landing page of my site collection is: http://spdev/Pages/Default.aspx. You would just have spdev in this field.
  9. Port Number: can be left blank if using port 80.
  10. Implementation: Java <- this is the step I had to change to get this whole thing to work for me.
  11. Path: in this example I put /Pages/Default.aspx
  12. Right click on "Thread Group" > Add > View Results in Table (or View Results Tree).
  13. Now click: Run > Start (or Ctrl + R)


 

Sunday, October 6, 2013

SharePoint 2013: CSOM List Permissions in C#

Intro: I'm building a SharePoint 2013 provided hosted app. I had a requirement to retrieve permissions for the current user to a particular list. I want to enable/disable a checkbox depending on their ability to add/edit items in a particular SharePoint list. So I search around and find this:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list.effectivebasepermissions.aspx
Unfortunately there's no sample in the above article and aren't any examples of how to use it anywhere on the web.

Issue: The EffectiveBasePermissions isn't loaded unless you specifically ask for it. This is the CSOM way.

Solution:
using (var clientContext = new ClientContext(hostWeb))
{
    Site site = clientContext.Site;
    clientContext.Load(site);
    clientContext.ExecuteQuery();

    Web web = site.OpenWeb("Name of spweb");
    clientContext.Load(web);
    clientContext.ExecuteQuery();

    List list = web.Lists.GetByTitle("Name of List");
    clientContext.Load(list, l => l.EffectiveBasePermissions); 
    clientContext.ExecuteQuery();

    bool myAddPermission = list.EffectiveBasePermissions.Has(PermissionKind.AddListItems);
    bool myEditPermission = list.EffectiveBasePermissions.Has(PermissionKind.EditListItems);
}

The code above will more than likely get the permission of the IIS App pool running your app. You may need to change the credentials in which the clientContext is running:
clientContext.Credentials = new NetworkCredential();

Explanation:
When writing server side code we can get all the data for the Web or list. Because we can afford to. But when we use CSOM we want to minimise the amount of data going back and forth. So the clientContext won't have the "EffectiveBasePermissions" unless you tell it to.

Thursday, February 16, 2012

SharePoint: Document Library as a Lookup field source

Went to create a Lookup field in a list to point at a document in a document library. Sounds pretty straight forward? Unfortunately not.

Document librarys use Name is the main column. It still contains the Title column but this column isn't required. When people upload files they will more than likely leave Title blank.

Move along to the Lookup field creation. You only have the option to pick:
Title
ID
Created
Modified
Copy Source
Version

Do you see the issue? The only good field to pick here is the Title field. But if all the Titles are blank you won't have anything to choose from?

At this stage the only workaround I can think of is to create a workflow which fills in blank Title fields on creation and on change. Messy but will fix this particular issue.

Good luck.

Sunday, October 9, 2011

Restoring a site collection and getting a "different version of Microsoft SharePoint Foundation" error

Scenario:
Restoring a site collection backup between 2 development environments. I'm using the following Powershell command:
Restore-SPSite -Identity http://spdev/sites/ctmh -Path c:\fpbackups\ctmh.bak
Where spdev is the name of my SharePoint Dev server.
ctmh.bak is the backup file.

Symptom:
Restore-SPSite : Your backup is from a different version of Microsoft SharePoint Foundation and cannot be restored to a server running the current version. The backup file should be restored to a server with version '4.1.9.0' or later.

Steps to get it working:
It seemed pretty straight forward although the version '4.1.9.0' seemed a little strange.
First step is to compare both environment's SharePoint version:
  1. SharePoint 2010 Central Administration
  2. Upgrade and Migration
  3. Check product and patch installation status
I looked up the version number on my favourite search provider and got the appropriate updates. Pretty straight forward really.

I forgot to run the "SharePoint 2010 Products Configuration Wizard" initially and the restore didn't work. So if the SharePoint versions are the same between environments it might be worth while running the wizard to check that the patches have been applied.

Friday, April 15, 2011

Hiding a Flash component in a page

I was scratching my head over this one for a while. I tried putting a Flash component in a DIV and then set the Display: none

This usually works. But not for Flash.

Long story short. The solution I found set is to set either height: 0px or width: 0px.

You may also need to set the overflow: hidden

<div style:"height: 0px; overflow: hidden>Flash thingy goes here</div>

Then when I want to display it I set the width/height via client side script.

Friday, April 8, 2011

SharePoint: Delete list via STSADM

stsadm.exe -o forcedeletelist -url http://exampleIntranet/Lists/AListToDelete

I found this very useful today.

I was having issues reaching: _layouts/sitemanager.aspx
I kept getting: Object reference not set to an instance of an object.

After a bit of poking around I found that I couldn't get to one of my lists (I'm messing with List definitions and instances). The STSADM command above saved my behind.

Thursday, April 7, 2011

SharePoint 2010: customErrors in Web.Config

Ok I've been trying to ignore this one for a while but it's got to me. I had to figure out why changing <customErrors mode="Off" /> in the usual web.config in your Web App didn't do anything.

So I did a search of the file system and found this file:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config

Yep that's right. You have to change the customErrors setting in this file as well.

Joys of SharePoint...

Thursday, October 23, 2008

Sharepoint & Melbourne Daylight Savings

I'm currently experiencing an issue where the Sharepoint timer service is kicking off an hour early. My network infrastructure people have assured me that they've installed all the service patches for all the servers.

A colleague found this MS KB Article: http://support.microsoft.com/kb/888253

And it seemed to be the solution. But when I checked my TIMEZONE.XML file the Daylight saving date appears to be correct:

<DaylightTime>
<Bias>-60</Bias>
<Date>
<Month>10</Month>
<Day>5</Day>
<Hour>2</Hour>
</Date>
</DaylightTime>

That is the correct date and time for Melbourne (this year) as per this page.

FYI I'm on the MOSS and upto version 12.0.0.6318 (Infrastructure update).

Chris Armstrong has also blogged about this yesterday (darn beat me by one day) but the daylight saving start date he uses don't appear to be correct. I'll make another post once I have a solution.

Wednesday, October 15, 2008

Running javascript after window.onload without breaking Sharepoint

If you're anything like me and are working with a lot of Javascript within Sharepoint. You will eventually need to run a script after the page loads. So you could add defer="defer" to your script tag, which sometimes works and sometimes doesn't.

You might be tempted to window.onload = someFunction(). But this will break the way Sharepoint load's it's pages. As Sharepoint also needs to do a lot of things after the page loads.

So the solution is:
window.attachEvent("onload", someFunction);

So instead of overriding the onload event. You are now adding an event to the queue. Simply replace the "someFunction" bit with your function name.

Sunday, October 5, 2008

Create a new form in Infopath without opening up a Form Library

I found this post and I thought it was really neat. Basically you can create a link anywhere in Sharepoint that creates a new form in Infopath without prompting the user for the "Open, Save As, Cancel" prompt. All you have to do is put this on your page. Change YOURSEVER with your server name, SITE to your site(s) name and FORM LIBRARY with your form libary name:

<a href="javascript:createNewDocumentWithProgID(
escapeProperlyCore('http://YOURSERVER/SITE/FORM LIBRARY/Forms/template.xsn', true),
'http://YOURSERVER/SITE/FORM LIBRARY/',
'SharePoint.OpenXMLDocuments',
true)">Create a New Document</a>