Archive

Posts Tagged ‘SharePoint’

Check User Permissions on a SharePoint Site using C#

December 8th, 2010 2 comments

Another SharePoint 2007 development post from the non developer, so feel free to offer any suggestions and comments around my code as I’m still learning.  I know, I should be doing this on SharePoint 2010.  Trust me, I’m trying to get us there.

Anyways, a brief background on what I’m trying to accomplish. I’m working on a navigation solution for our current intranet that queries a list of SharePoint sites that have been requested, approved and created via our site request process.  The query results are then filter based on if the current user has access to the site.  This list contains variety of sites, site collections and sub-sites that are spread out across 3 different web applications.  The solution then displays those sites in a web part for users to have “quick access” to their collaboration sites.  It’s basically a way to provide navigation (contained in a web part) across site collections and web applications automatically off a list of sites.

In order to check for access I decided to use the DoesUserHavePermissions() function.  However, after writing this function:

private bool UserAccessToSite(String user, SPWeb testWeb, SPSite testSite){
    bool access = false;
    try{
        access = testWeb.DoesUserHavePermissions(user, SPBasePermissions.EmptyMask);
        return access;
    }
    catch{
        access = false;
        return access;
    }
}

I was getting the following error stating that the “List does not exist”

image

I tried a variety of different approaches just to get it to return false if the user has Access Denied to the site.  After a bunch of different tries and some searching online, I ran across this post by Krichie that solved the problem for me.

Right before checking DoesUserHavePermissions I had to add the line SPSite.CatchAccessDeneidExceptoin=false;

So, the final code that is now working is:

private bool UserAccessToSite(String user, SPWeb testWeb, SPSite testSite){
    bool access = false;
    try{
        testSite.CatchAccessDeniedException = false;
        access = testWeb.DoesUserHavePermissions(user, SPBasePermissions.EmptyMask);
        return access;
    }
    catch{
        access = false;
        return access;
    }
}

My web part is now configured in order to query the list and only return a link to a SharePoint site if the user currently logged into SharePoint has access to that site.  I still have some work to do on the web part and the rest of the solution, so as I continue this adventure I’ll try to post any other updates.  Who knows, maybe once I finish it I’ll even post the whole solution up here.

Again, feel free to correct my code or offer other suggestions as I continue to delve into the SharePoint development space.

SharePoint 2010 October CUs reposted

December 2nd, 2010 No comments

Just a quick update.  Yesterday Microsoft reposted the October 2010 Cumulative Updates for SharePoint 2010.  For all the information, head on over to the Microsoft SharePoint Team Blog post about the reposting.

SharePoint 2007 Navigation, Documents, Lists and Anonymous Access

October 1st, 2010 No comments

I had this problem today on one of our sites that has anonymous access enabled.  We wanted to link to some PDF files in our quick launch navigation, so, naturally, we logged into the site and manually added the links.

However, when we tested the site with anonymous access the links weren’t there! So, next step, check the document library.  It was inheriting permissions, and I could even manually type in the URL to the document library and the PDFs using anonymous access and view everything just fine.

So, time to start digging.  Fortunately I found a thread on a discussion board that pointed me here – http://support.microsoft.com/kb/927082/en-us?spid=11373&sid=200.  Apparently when you turn on Anonymous access, Microsoft doesn’t think you could really want everything to be anonymous access.  Anywho…I figured it was worth a shot, so I logged into the server, disabled the feature running the command in the KB article linked above, turned anonymous access off and back on and what do you know.  It worked!!!

So, if you are having any trouble with certain lists, documents, navigation, etc.  Give this solution a shot.  As of yet I’m not aware of negative impacts to disabling this feature, but if I find any I’ll definitely update this post.

ASP.NET Security Vulnerability Resources

September 22nd, 2010 No comments

***Update: Today Microsoft is releasing as out-of-band security update to address this issues.

- SharePoint Team Blog Announcement – http://blogs.msdn.com/b/sharepoint/

 

I’m sure by now all of you have heard about the ASP.NET security vulnerability and there are plenty of references out there about it and how to fix it so I’m not going to go into much detail here.  The key point is yes, it effects WSS 2.0, SharePoint 2007 (WSS 3.0 and MOSS) and SharePoint 2010 (Foundation and Server).

The best references I have found so far, and I will refer you to rather than writing it all up myself are":

1. The Microsoft SharePoint Team Blog, this is where the fixes are documented that you can put in place until a patch is released.

2. Scott Guthrie’s Blog, this contains a very good list of FAQs about the vulnerability.

Custom SharePoint .ASPX form–“Could Not Load Type”

July 8th, 2010 No comments

This is starting to get dangerous…I’m blogging about SharePoint development twice in a row.  Again, this may be something very basic to most SharePoint developers, but as I learn, I enjoy blogging about issues I’ve discovered and things I’ve learned as I continue to develop more.

My next venture into SharePoint development is to create some custom .ASPX forms for use within our SharePoint environment.  For our situation, InfoPath Forms Services would make much more sense, unfortunately, we only have SharePoint 2007 Standard with no plans to go to Enterprise.

So, I created a very basic .ASPX file with an equally as simple .cs (code behind file), packaged it all up as solution and deployed it.  However, when I went to access the site, I encounter a “Could Not Load Type…” error.  After a quick search on Google, I found – http://blogs.catapultsystems.com/matthew/archive/2007/12/07/could-not-load-type-error.aspx between that post and the post by Andrew Connell that was referenced there I was able to solve my problem.

When I had created my .aspx file I had failed to use the “5 part name” to reference the assembly file.  I had put Inherits=”NewForm.NewForm” rather than Inherits=”NewForm.NewForm, NewForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=*********”

As soon as I changed my .aspx file to use the 5 part name and redeployed my solution everything worked perfectly!

Reset Search Index – SharePoint Timer Job

July 7th, 2010 No comments

We have been having an issue with our search indexing and crawling in one of our SharePoint farms.  The problem is that after an undetermined set of time, pretty much all search queries wind up returning several results that show nothing but an IE icon.  The result isn’t attached or any page or give any textual information.  Obviously best case would be to figure out what causes this error, but at this point in time we haven’t been able to find the problem.

However, what we have discovered is that simply resetting the search index and running a full crawl will solve the issue.

So…until we can solve the issues, I wrote a small SharePoint timer job that simply resets our search index right before a scheduled full crawl runs.  I used Andrew Connell’s post (http://www.andrewconnell.com/blog/articles/CreatingCustomSharePointTimerJobs.aspx) to develop the Timer Job, Solution and Feature and modified it and was able to find the following code on http://www.sharepointdev.net/sharepoint–development-programming/programmatically-reset-all-crawled-content-41959.shtml that I inserted into the timer job frame work in order to automatically reset our index on a regular schedule to minimize the risk of our search issue effecting the end users.

try
{
    SearchContext sc = SearchContext.GetContext(ServerContext.Default);
    sc.Reset(true);
}
catch (Exception ex)
{
    throw new InvalidOperationException("Unable to reset content index.", ex);
}

For some of you, this may not seem like much, but coming from the SharePoint Administration/Configuration side of SharePoint and having very little real development experience I was rather proud of myself.

SharePoint 2010, Internet Explorer and FireFox

April 20th, 2010 No comments

Microsoft has been talking about how much better the user experience with SharePoint 2010 is when using browsers other than Internet Explorer, mainly, Mozilla Firefox.  They have been doing a lot of SharePoint demo’s with Firefox to demonstrate this ability and Firefox has been labels as being a level 1 browser for SharePoint 2010.

However, in my use of Firefox, I have found a couple of things so far that still work only when using Internet Explorer.

1. You can’t upload multiple files to a document library from within Firefox.  This is due to the fact that for some of these actions.  SharePoint 2010 does indeed still use ActiveX controls.  In fact, some people don’t even have this option in Internet Explorer according to this post – http://sharepoint4u.wordpress.com/2009/05/07/no-multiple-upload-no-connect-to-outlook/

2. There isn’t the ability to drag and drop to re-arrange web parts on a SharePoint site or to move them between zones.  You must move the web parts around by using the setting in the web part properties.

I am actually somewhat surprised by both of these limitations.  The first one probably more so than the second, especially considering that when using Microsoft SkyDrive you have the ability to upload multiple files using Firefox.  You would think this same type of functionality could exist in SharePoint 2010.

Based on the most recent posts by Microsoft, http://technet.microsoft.com/en-us/library/cc263526%28office.14%29.aspx, it doesn’t look like they have plans on changing any of these limitations.  This site contains additional details on these limitations as well as other limitations that exist for various browsers when accessing SharePoint 2010.

SharePoint 2010 Complete Install on Windows 7

February 20th, 2010 1 comment

So this weekend I decided to install SharePoint 2010 on my desktop at home.  My desktop is running Windows 7, and due to requirements of other software I need, I’m unable to run Windows Server 2008 on it.

Running a stand alone installation of SharePoint 2010 is great, however, I wanted to see if I could get a complete install on Windows 7 and user SQL Server 2008.  Fortunately, I found this blog post by Neil Hodgkinson that explained how to do it.  Everything appeared to be working great and the configuration wizard finished without any problems.  Unfortunately, that appearance didn’t last too long.

My problem arose when I went into Central Administration and, despite being a farm administrator, the first thing I noticed was I couldn’t create new web applications.  There were some other security issues as well, however, those are beside the point.  The purpose of this post is how to go about fixing this issue if you encounter the same thing.

After mulling over the issues for a few minutes, I remember are beloved User Access Control (UAC) and other issues I’ve seen when it is enabled on Windows Server.  So, I went into my UAC settings, disabled them complete, restarted my computer, logged into Central Administration and what do you know, it worked!  I can now create new web applications and have full control over my SharePoint 2010 installation.

SharePoint Memory Leak

February 15th, 2010 1 comment

As discovered by Todd Carter there is a memory leak in SharePoint 2007.  He has outlined the details as well as a work around to the fix the memory leak.

I decided to do some testing with it, however, when I compiled the dll, placed it into the GAC, and changed my global.asax file, I started getting this error: “Could not load file or assembly ‘[Assembly Name]’ or one of its dependencies.  The system cannot find the file specified.”

After digging into this error for a while I discovered my problem.  This may be fairly obvious to developers out there :) , but coming at this from more of a SharePoint administrator type roll, I missed this one step that isn’t outlined in the steps provided by Todd.

After deploying your dll to the GAC, you need to open up your web.config and place

<add assembly="[Assembly Name], Version=[Version Number], Culture=neutral, PublicKeyToken=[Public Key Token]" />

in the web.config file of the web application you wish to apply your fix to.  This line should be added between <assemblies> and </assemblies> in the web.config file.

All of the information: Assembly Name, Version Number and the Public Key Token can be found by right clicking on your dll in the GAC and viewing the properties of the dll.

Once I added the assembly to my web.config for the web applications I was trying to apply the fix to, everything worked as expected.

Hide Web Part Headers with SharePoint 2010

February 1st, 2010 7 comments

A while a go a write a short post on how to hide web part headers in SharePoint 2007.  Recently I had some inquire how to do the same thing for SharePoint 2010.  So, here is what to do in order to hide a web part header in SharePoint 2010.

1.  Add a content editor web part to your page.

2. Edit the Web Part

3. Click in the content area of the web part, click HTML and select “Edit HTML Source”

4. Put the following code in the web part:

  1. <style>
  2.   TR.ms-viewheadertr > TH.ms-vh2 {
  3.   DISPLAY: none
  4.   }
  5. </style>

 

5. Click “OK”

6. Expand “Appearance” (on the right side of the page)

7. Set the chrome type to “None”

8. Click “OK” and then save and check in your page.

The headers of your web part should now be hidden.  This can be extremely helpful when your page contains a web part using “boxed” for your style when creating a list view.  The only downside to this approach is if you have multiple web parts on a single page, it will hide the headers for all the web parts on your site.

How to do the same thing in SharePoint 2007