Another one of those problems which is a short post but which took me hours upon hours to fix. The error is as follows:
You log into SharePoint Central Admin with the intent of creating a site collection. You go to Applications and do the necessary, ensuring it is added to the correct Web Application yada yada yada. And then you go to the new link for your site collection - because you want to create some sites in it, naturally enough.
Access Denied Error!
Butbutbut - I'm the Farm Administrator! How can this be? How can I not see my own damn site collections?
By the time I had found the solution, via the good offices of google, I was quite ready to be the Funny Farm Administrator. But never mind. I know now what it is.
1. Central Admin. Attempt to access SharedServices1 page. Chances are you will get an Access Denied error
2. Application Management - Policy for Web Application. Is your farm account listed there with Full Control? If not, add it for the relevant Web Application (you'll see the web app filter in the view dropdown on the top right)
3. Still having problem? Go to Operations - Service Accounts. BE VERY CAREFUL ABOUT DOING THIS ON A PRODUCTION SERVER, HAVE A BACKUP FIRST:
Click "Web application pool" option button
Select Web Service - Winds SharePoint Services Web Application
Select Application Pool - usually only Sharepoint - 80 available. That's fine.
Select "Configurable" radio button and enter farm admin account user and password
Click OK
A lot of the links in SharedServices will still be broken but you will be able to view SharedServices1 and more importantly your site collections!
Showing posts with label central admin. Show all posts
Showing posts with label central admin. Show all posts
Thursday, 27 September 2012
Monday, 13 August 2012
Impersonating a SharePoint search
Here is code which will run a SharePoint search and return the results in a StreamWriter object, which can be outputted to a file. Hook it up to a console app and off you go!
Note
- you must specify a row limit or it will only return the first 50 results
- user under which it runs will need to have read access to the content database containing the Central Administration Shared Services. This is usually called SharedServices1_DB or some such variant. Error logs will indicate very clearly if that error occurs so make sure to have good error handling
- Microsoft.Office.Server.Search.Query is another one of those annoying DLLs that is impossible to find. It's not one of the SharePoint dlls - you might find it in the ISAPI folder or otherwise in the list of other .NET dlls.
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search;
public class SearchResults
{
public string errorArgs;
public SearchResults()
{
//constructor don't do nuthin'
errorArgs = string.Empty;
}
protected DataTable ReturnSearchResults(string searchCriterion, string siteUrl)
{
DataTable dt = new DataTable();
try
{
//Available fields: Title,FileExtension,ContentType,Created,LastModifiedTime,IsDocument,owsStartDate,Path
searchCriterion = searchCriterion.Replace(" ", "+");
string fullTextSQL = "SELECT Title, FileExtension, ContentClass, ContentType, Created, URL FROM SCOPE() ";
fullTextSQL = fullTextSQL + "WHERE CONTAINS ('" + searchCriterion + "') ";
//do whole site for the moment
using (SPSite site = new SPSite(siteUrl))
{
errorArgs = "accessing office search component";
Microsoft.Office.Server.Search.Query.FullTextSqlQuery search = newMicrosoft.Office.Server.Search.Query.FullTextSqlQuery(site);
Microsoft.Office.Server.Search.Query.ResultTableCollection results;
//configure the query - limit it to 50 for the moment
errorArgs = "preparing search";
search.QueryText = fullTextSQL;
search.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
search.RowLimit = 1000;
search.TrimDuplicates = true;
results = search.Execute();
errorArgs = "search successful";
if (results.Count > 0)
{
using (Microsoft.Office.Server.Search.Query.ResultTable relevantResults = results[Microsoft.Office.Server.Search.Query.ResultType.RelevantResults])
{ dt.Load(relevantResults, LoadOption.OverwriteChanges); }
}
return dt;
}
}
catch (Exception ex)
{
//handle error here
return null;
}
finally
{
}
}
public StreamWriter ReturnResultsInStream(string searchCriterion, string siteUrl,FileStream fs)
{
try
{
StreamWriter stream = new StreamWriter(fs);
DataTable results = this.ReturnSearchResults(searchCriterion, siteUrl);
foreach (DataRow dr in results.Rows)
{
foreach (object field in dr.ItemArray)
{
if (field is string)
{
stream.Write(field.ToString());
stream.Write(";");
}
}
stream.WriteLine();
}
return stream;
}
catch(Exception ex)
{
//HANDLE YOUR ERROR HERE
return null;
}
}
}
Tuesday, 15 November 2011
Creating and Installing a SharePoint Timer Job
Important: this should be carried out on a non-production server first and then refined before deploying to live!
I just created a timer scheduled job in SharePoint with the help of Some Code Off The Internet (TM) plus a few hard-earned lessons all of my own.
The important thing to realise about a timer job is that it's just another SharePoint feature plus dll with some feature overriding code in it. Nothing more, nothing less. When I download a project with all the components and setup stuff, I tend to just work with the actual .cs files in a class library, make the dll and then do it manually. That means I know what's going on.
The code I downloaded was here
(thank you Alexander Brütt)
But what I did rather than open the whole package as a Visual Studio item was to open the whole thing and drop all the build instruction files because I was deploying to another machine anyway. The three files you really need are
Job.cs
JobInstaller.cs
Feature.xml (which you will put somewhere separate in the FEATURES folder in the Twelve Hive anyway)
The rest is just detail. But don't forget the strong key. It saves time since that's the key in your feature.xml file. Also there are some items in the folder with dollar signs on them. They're for you to change the name. I called the Job class CustomSharePointJob and the Installer class CustomSharePointJobInstaller. Yes I was looking for an easy life there :)
Build the thing as a dll (forgetting the manifest xml and all that packaging stuff) and if there are build errors, chances are you need to conjure up a couple of GUIDs to identify the dll as the code has $guid somewhere, I think. It should eventually build ok.
OK, then GAC register your dll and make sure the info in the feature.xml file matches up. The Feature Receiver line should be the same as your components. Stick it into the Twelve Hive. Now fire up the command line, change dir to your twelve hive BIN folder and enter the following piece of sublime poetry:
stsadm -o installfeature -filename CustomSharePointJob\Feature.xml
And then
Hopefully it should give you the thumbs up. But just to make sure, open up SharePoint Central Admin and navigate to Operations - Timer Job Definitions. Your timer job should be there and its schedule should be Minutes.
OK, we want to deactivate it for a moment and do some work on it. So in stsadm
The wonderful thing about this code is that it has event receivers for the feature deactivating, and the event triggers a delete. So you don't have to worry about taking the job off the list in sharepoint central admin, it's all taken care of.
Now in Visual Studio, have a look at the Job.cs folder. I put in instructions to send me an email when the job fired - just to make sure it worked ok. In order to do that I had to instantiate an SPSite object and SPWeb object which I did as per usual using a site url. But there is one important difference to note. The code here specifies a job lock type of SPJobLockType.ContentDatabase. This means that the job is designed to fire against every content database on that server. I was wondering why I was getting nine emails! Go into your Job.cs file and change that to SPJobLockType.Job and you are sorted, it will only fire the once.
Also, what else do I need to do. Well I don't want the damn thing running every 2 minutes, once a day is enough. I scoured the internet looking for something telling me how to set up a daily schedule and eventually found a solution which I've amended slightly to run at 6am. If, for testing purposes, you want to change that hour, just move up the BeginHour and EndHour properties:
SPDailySchedule schedule = new SPDailySchedule();
schedule.BeginHour = 6;
schedule.BeginMinute = 15;
schedule.BeginSecond = 0;
schedule.EndSecond = 15;
schedule.EndMinute = 15;
schedule.EndHour = 6;
myCustomSharePointJob.Schedule = schedule;
myCustomSharePointJob.Update();
I put in some code to do the thing I wanted to do on the site I wanted to do it on - this goes in the Execute method - recompiled the dll and GAC registered it once more. Ready to do battle - but wait -
Now this next step is very important
Save yourselves a good few hours of pain and do this now. Just when you've finished running gacutil from the command line, enter the following line:
net stop sptimerv3
(it will be sptimerv4 for you sharepoint 2010 heads)
And then straight afterwards type
net start sptimerv3
This stops and restarts the OWSTIMER.EXE process for sharepoint. (This is why not to do this on live.) The reason this has to be done is otherwise, the process will cache your old dll FOREVER. It doesn't matter if you re-register it seven times, doesn't matter if you delete the damn thing or restart the job or whatever - it will just keep caching it.
This has to be done every time the dll is recompiled!
Then - and only then - reactivate the feature by going into stsadm and entering the activatefeature command as described above. Then hopefully all should be well.
I would like to recommend the following links which are very helpful:
Subscribe to:
Posts (Atom)