Thursday, March 14, 2013

SharePoint 2010 - Access Denied for Site Administrator - WTF

This could happen to anyone with claims authentication and the reason is 
By default, the Portal Super User account is the site’s System Account, and the Portal Super Reader account is NT Authority\Local Service.

(replace the domain\superuser and domain\superreader to the accounts set in CA for your Farm)


The domain\superuser account needs to have a User Policy set for that gives it Full Control to the entire web application. In order to do this you perform the following steps:


  1. Go to Central Administration
  2. Go to Application Management
  3. Go to Manage Web Application
  4. Select the web application we’re talking about
  5. Click User Policy
  6. Add Users
  7. Click Next
  8. Fill in domain\superuser
  9. Select Full Control
  10. Click OK

The domain\superreader account needs to have a User Policy set for that gives it Full Read to the entire web application. In order to do this you perform the following steps:


  1. Go to Central Administration
  2. Go to Application Management
  3. Go to Manage Web Application
  4. Select the web application we’re talking about
  5. Click User Policy
  6. Add Users
  7. Click Next
  8. Fill in domain\superreader
  9. Select Full Read
  10. Click OK

If your web application is using claims based authentication the users should be displayed like i:0#.w|domain\superuser and i:0#w|domain\superreader. 



Run the following to check the current configuration

$wa = Get-SPWebApplication "[YourWebAppHereBaby]"
$wa.Properties["portalsuperuseraccount"] 
$wa.Properties["portalsuperreaderaccount"]



If you are using classic mode authentication run the following cmdlets on one of your SharePoint servers:
If you don't know what type of authentication is being used for your Farm, you don't have the skills to proceed further.


$wa = Get-SPWebApplication "[YourWebAppHereBaby]"
$wa.Properties["portalsuperuseraccount"] = "domain\superuser"
$wa.Properties["portalsuperreaderaccount"] = "domain\superreader"
$wa.Update()

If you are using claims based authentication run the following from SharePoint PowerShell:
If you don't know what type of authentication is being used for your Farm, you don't have the skills to proceed further.
(replacing the domain\superuser and domain\superreader to the accounts set in CA for your Farm)

$wa = Get-SPWebApplication "[YourWebAppHereBaby]"
$wa.Properties["portalsuperuseraccount"] = "i:0#.w|domain\superuser"
$wa.Properties["portalsuperreaderaccount"] = "i:0#.w|domain\superreader"
$wa.Update()

Tuesday, March 12, 2013

Exception: System.Security.Cryptography.CryptographicException

Tired of seeing the "Exception: System.Security.Cryptography.CryptographicException" in SharePoint 2010 on Windows 2008(/R2) Server


An unhandled exception ('System.Security.Cryptography.CryptographicException') occurred in OWSTIMER.EXE [23248]. Just-In-Time debugging this exception failed with the following error: Debugger could not be started because no user is logged on...

Simply open the regedit.exe (registry editor) to delete the following registry keys:
  1. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger
  2. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger
  3. HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger
  4. HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger

Wednesday, August 3, 2011

MOSS 2007 – WSS 3.0 Version / Build Numbers

12.0.0.6529 : MOSS 2007 – WSS 3.0 Feb 2010 Cumulative update
12.0.0.6524 : MOSS 2007 – WSS 3.0 Dec 2009 Cumulative update
12.0.0.6520 : MOSS 2007 – WSS 3.0 Oct 2009 Cumulative update
12.0.0.6414 : MOSS 2007 – WSS 3.0 Aug 2009 Cumulative update
12.0.0.6510 : MOSS 2007 – WSS 3.0 June 2009 Cumulative update
12.0.0.6504 : MOSS 2007 – WSS 3.0 April 2009 Cumulative update
12.0.0.6421 : MOSS 2007 – WSS 3.0 Service Pack 2
12.0.0.6341 : MOSS 2007 – WSS 3.0 Feb 2009 Cumulative update
12.0.0.6327 : MOSS 2007 – WSS 3.0 Aug 2008 Cumulative update
12.0.0.6318 : MOSS 2007 – WSS 3.0 Infrastructure Update
12.0.0.6303 : MOSS 2007 – WSS 3.0 post-SP1 hotfix
12.0.0.6301 : MOSS 2007 – WSS 3.0 post-SP1 hotfix
12.0.0.6300 : MOSS 2007 – WSS 3.0 post-SP1 hotfix
12.0.0.6219 : MOSS 2007 – WSS 3.0 SP1
12.0.0.6039 : MOSS 2007 – WSS 3.0 October public update
12.0.0.6036 : MOSS 2007 – WSS 3.0 August 24, 2007 hotfix package
12.0.0.4518 : MOSS 2007 – WSS 3.0 RTM
12.0.0.4407 : MOSS 2007 – WSS 3.0 Beta 2 TR
12.0.0.4017 : MOSS 2007 – WSS 3.0 Beta 2

Monday, June 6, 2011

Get SPUser object from SharePoint List Item People/Group picker field

The code below is to get SPUser from a multiple user item column 
 
 
            string strURL = "http://YourSite/";
            using (SPSite oSPSite = new SPSite(strURL))
            {
                using (SPWeb oSPWeb = oSPSite.OpenWeb())
                {

                    SPList list = oSPWeb.GetList(strURL);
                    SPListItemCollection items = list.Items;
                    foreach (SPListItem oListItem in items)
                    {
                        if (oListItem["Title"].ToString() == "Test")
                        {
                            String usersString = oListItem["Audience Group"].ToString();
                            SPFieldUserValueCollection userValueColl = new SPFieldUserValueCollection(oSPWeb, usersString);

                            foreach (SPFieldUserValue userValue in userValueColl)
                            {
                                SPUser siteUser = userValue.User;
                                Console.WriteLine("User found: {0}", siteUser.Name);
                            }
                            break;
                        }
                    }
                }

Thursday, April 7, 2011

Attaching an event handler to a specific SharePoint List

When we attach an event handler through Features in SharePoint using “ListTypeId”, it attaches event handlers to all the lists of that particular type. This will result in a large performance hit. To execute the written code for a particular list we will have to check either with ListId or ContentTypeId.
So, here is a way of attaching an event handler to a specific list on “FeatureActivated” and to remove the event handler from the list on “FeatureDeactivating”. This is the best method I can find as of now for attaching and removing the event handler to a specific SharePoint List.

const string assembly = "ListItemPermissions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5";
const string listReceiverName = "ListItemPermissions.ListItemPermissionsItemEventReceiver";
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
// get a reference to the current SPWeb
SPWeb _SPWeb = SPContext.Current.Web;
_SPWeb.AllowUnsafeUpdates = true;
// get a reference to the "Projects" list
SPList _projectsList = (SPList)_SPWeb.Lists["Projects"];

// if the "projectsList" list exists
if (_projectsList != null)
{
// create an empty Guid
Guid _ItemUpdatedGuid = Guid.Empty;
Guid _ItemAddedGuid = Guid.Empty;

// enumerate thru all of the event receiver definitions, attempting to
// locate the one we are adding
foreach (SPEventReceiverDefinition _SPEventReceiverDefinition in _projectsList.EventReceivers)
{
// if we find the event receiver we are about to add
// record its Guid
if (_SPEventReceiverDefinition.Type == SPEventReceiverType.ItemUpdated &&
_SPEventReceiverDefinition.Assembly == assembly &&
_SPEventReceiverDefinition.Class == listReceiverName)
{
_ItemUpdatedGuid = _SPEventReceiverDefinition.Id;
}

if (_SPEventReceiverDefinition.Type == SPEventReceiverType.ItemAdded &&
_SPEventReceiverDefinition.Assembly == assembly &&
_SPEventReceiverDefinition.Class == listReceiverName)
{
_ItemAddedGuid = _SPEventReceiverDefinition.Id;
}
}

// if we did not find the event receiver we are adding, add it
if (_ItemUpdatedGuid == Guid.Empty)
{
_projectsList.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assembly, listReceiverName);
}
if (_ItemAddedGuid == Guid.Empty)
{
_projectsList.EventReceivers.Add(SPEventReceiverType.ItemAdded, assembly, listReceiverName);
}

_projectsList.Update();
_SPWeb.Update();
_SPWeb.AllowUnsafeUpdates = false;
}
}

catch (System.Exception ex)
{
PortalLog.LogString(ex.StackTrace);
throw new SPException(ex.Message);
}
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
try
{
SPWeb _SPWeb = SPContext.Current.Web;
_SPWeb.AllowUnsafeUpdates = true;
// get a reference to the "Projects" list
SPList _projectsList = (SPList)_SPWeb.Lists["Projects"];
while(_projectsList.EventReceivers.Count > 0)
{
if (_projectsList.EventReceivers[_projectsList.EventReceivers.Count-1].Assembly.Equals(assembly))
{
_projectsList.EventReceivers[_projectsList.EventReceivers.Count-1].Delete();
}
} // looping thru event receivers.

_projectsList.Update();
_SPWeb.Update();
_SPWeb.AllowUnsafeUpdates = false;
}
catch (System.Exception ex)
{
PortalLog.LogString(ex.StackTrace);
throw new SPException(ex.Message);
}
}

Friday, March 4, 2011

Moss 2007 - Excel Services no file permissions message

 If you receive the following Exception when you try to open the sample workbook or another workbook try the following steps:

You do not have permissions to open this file on Excel Services.Make sure that the file is in an Excel Services trusted location and that you have access to the file.

1.Open Central Administration -> go to Operations tab -Ensure that the Excel Service is running.
2.Open Central Administration -> go to your configured Shared Service -> click Excel Service Settings.

-File Access Method: ensure that it is not using Impersonation, instead the Option Process Account should be enabled.

3. Open Central Administration -> go to your configured Shared Service -> click add new trusted file location
-Field URL: here you can specify a report library or the whole portal
-Location Type: should be Windows SharePoint Services
-Children trusted: defines whether the children should also be trusted or only the definied path

Tuesday, January 25, 2011

IIS7 - Tell me plase why my debugger timed out - Coz u r slow -"The web server process that was being debugged has been terminated by IIS"

When you are debugging, IIS will not service any other requests until you are done stepping through your code. That includes the "ping" request that IIS sends to itself. Since IIS doesn't hear back from itself, it decides to shut itself down, which promptly terminates your debugging.
The solution is to increase the Ping Maximum Response Time in the application pool settings from its default value of 90 seconds. Set it to something high enough that will give you enough time to debug your code (like maybe 900 seconds). If you are not able to debug in 15 min, one should really look for a job which does include hardcore coding.

Tuesday, January 11, 2011

SPWeb GetList Exception from HRESULT: 0x80070003 System.IO.DirectoryNotFoundException

If you see something like this while calling while calling  SPWeb.GetList("BlahBlahBlah"), do not get alarmed.
All you need to provide is a site-relative URL like the following
"/sites/myWeb/Lists/myCoolList".
If you are in the top-lelel site collection and wondering what the heck , then it should be like "/Lists/myCoolList"

"Unhandled Exception: System.IO.DirectoryNotFoundException: The system cannot find the path specified. (Exception from HRESULT: 0x80070003)"

Deleting Document Library Items for large list size Failed?

For novice to use this code, specify the strings variables siteURL, listName.
The maximum items that your program can delete is 25000 which can be changed.

Hey friends, If you have saved lot of time using my code, please pay me by smiling at all the people you see today. They will smile back at you. We will all be in a pool of happy smiles. If you have a big wallet, feed a hungry stomach today.  And God will bless you.

using (SPSite site = new SPSite(siteURL))
{
 using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    StringBuilder sbDelete = new StringBuilder();
                    SPList spList = web.GetList("/" + listName);
                    sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
                    string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
                        "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar><SetVar Name=\"owsfileref\">{1}</SetVar></Method>";
                    int limit = 0;
                    foreach (SPListItem item in spList.Items)
                    {
                        limit++;
                        if (limit > 25000)
                            break;
                        sbDelete.Append(string.Format(command, item.ID.ToString(), item.File.Url));
                    }
                    sbDelete.Append("</Batch>");

                    web.ProcessBatchData(sbDelete.ToString());
                    web.Update();
                    web.AllowUnsafeUpdates = false;
                }
}

Deleting ListItems for large list size Failed?

The following code only works for List. Refer my other post for Document Library.
For novice to use this code, specify the strings variables siteURL, listName.

The maximum items that your program can delete is 5000 which can be changed.


The way web.Lists[listName] works is that it loads the meta-data information of the all lists for that specific SPWeb object and then it does SPList.Title comparison with metadata of all the lists returned and returns the first matching list from the SPWeb.Lists collection. This has got two implications:
1. The loading of list is slow as the meta-data information of all the list is loaded and then comparison happens on list name specified.
2. If there are large numbers of lists in a specific SPWeb, the process of getting the meta-data information of all the available lists may introduce transaction lock in backend database when multiple such calls happen in quick succession.

The suggested way to access a list is by using SPWeb.GetList(string url). In this case, first the GUID of list is figured out and then meta-data for the list is loaded. Obviously, this is a faster way also.
If your head is already spinning, the summary is that
"And you must use  web.GetList(listName) instead of web.Lists[listName]. Otherwise it may take for ever."

Hey friends, If you have saved lot of time using my code, please pay me by smiling at all the people you see today. They will smile back at you. We will all be in a pool of happy smiles. If you have a big wallet, find & feed a hungry stomach today(not mine).  And God will bless you.

using (SPSite site = new SPSite(siteURL))
{

 using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    StringBuilder sbDelete = new StringBuilder();

                   SPList spList = web.GetList("/Lists/" + listName);

                    sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
                    string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
                        "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
                    int limit = 0;
                    foreach (SPListItem item in spList.Items)
                    {
                        limit++;
                        if (limit > 5000)
                            break;
                        sbDelete.Append(string.Format(command, item.ID.ToString()));
                    }
                    sbDelete.Append("</Batch>");

                    web.ProcessBatchData(sbDelete.ToString());
                    web.Update();
                    web.AllowUnsafeUpdates = false;
                }
}

Wednesday, December 29, 2010

SharaPoint CAML OrderBy DefaultView Limit

The Default List view has direct effect on the number of records that return for the CAML query with OrderBy.
Changed the List's Default View limit to 5 and U see only 5items. Wierd One.
Hope this post will save a lot of time for people researching what the heck happened

Thursday, November 18, 2010

Truncate and shrink Transaction Log file in SQL Server 2008

SQL Server 2008

In SQL Server this process have been changed. In 2008, just change the recovery model to simple and then use DBCC Shrinkfile command.

use [YourDatabaseName]
select name,recovery_model_desc from sys.databases
GO
Alter database [YourDatabaseName] Set Recovery SIMPLE
GO
Declare @LogFileLogicalName sysname
select @LogFileLogicalName=Name from sys.database_files where Type=1
print @LogFileLogicalName

DBCC Shrinkfile(@LogFileLogicalName,1)



______________________________

If you may want to set the recovery back to Full. If so, add the following.
Alter database [YourDatabaseName] Set Recovery FULL

Thursday, May 27, 2010

XSLT String Padding

Create the Template

  <xsl:template name="leftjustify">
    <xsl:param name="content"/>
    <xsl:param name="width"/>

    <xsl:choose>
      <xsl:when test="string-length($content) &gt; $width">
        <xsl:value-of select="substring($content,1,$width)"/>
      </xsl:when>

      <xsl:otherwise>
        <xsl:value-of select="$content"/>
        <xsl:call-template name="spaces">
          <xsl:with-param name="length">
            <xsl:value-of select="$width - string-length($content)"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:otherwise>

    </xsl:choose>

  </xsl:template>

  <xsl:template name="spaces">
    <xsl:param name="length"/>
    <!-- the value of this next variable is 255 spaces.. -->
    <xsl:variable name="longstringofspaces">
      <xsl:text>                                                                                                                                                                                                                                                               </xsl:text>
    </xsl:variable>
    <xsl:value-of select="substring($longstringofspaces,1,$length)"/>
  </xsl:template>




Usage:


<xsl:call-template name="leftjustify">
      <xsl:with-param name="content">You can do this</xsl:with-param>
      <xsl:with-param name="width">40</xsl:with-param>
    </xsl:call-template>


Tuesday, July 7, 2009

InfoPath 2007 Template Parts

Finding tough to keep the he sections, tables, fields, data connections and dropdown lists consistent between all forms.

The InfoPath 2007 was released and it has a new feature called Template Parts. Template Parts is a new type of InfoPath template that allows for predefined forms to be saved and then imported into the InfoPath Controls Task Pane. A Template Part is capable of saving Data Connections, Rules, Conditional Formatting, Data Validation and many other things. Just having this capability has saved me a tremendous amount of time when designing forms and it has increased the ROI for the client. A standard address block is one of the first things that I create for a new client because I'm able reuse it right away and show immediate ROI. At first you might not think this would have a big impact but when you take in account that, you no longer have to worry about defining the data source fields, layout table, field widths, colors, font style/size, data connections for states/regions and country, data validation, rules or conditional formatting then the ROI is reached pretty quickly. Once I understood this capability it changed how I started developing forms.

A feature of a Template Part that you need to take in consideration when using them to help designing forms is the Update capability. The Update capability allows for existing Template Part control on a form to be updated once the master Template Part control has changed and re-imported into the designer. At first this capability was frustrating because I didn't design everything with this in mind but after understanding how it worked, I quickly changed how I was designing forms and took advantage of the Update capability.

Long story short, Template Parts are great if you put thought into how you are building and using them. If you don't do this then it will just adds more complexity when building your InfoPath form and shouldn't be used.


Thursday, July 2, 2009

Infopath - Edit in Browser + Close = "The form has been closed." Annoyed?

(12Hive)\TEMPLATE\FEATURES\IPFSSiteFeatures\FormServerEcbEntry\EcbEntry.xml

Refer
http://geek.hubkey.com/2007/01/infopath-forms-services-close-button_17.html

Forcefully Activate "IPFSSiteFeatures" feature scoped to WebApp.
iisreset / recycle the application pool.

It must take you back without the annoying page "The form has been closed."
Update your upgrade document to redo the changes after the upgrade as upgrade may reset this feature.

Monday, June 29, 2009

Sharepoint Site Creation Notification Email

Steps Involved:

1. Create an event reciever
2. Create a feature to call the reiever when activated.
3. Create a feature stapler to staple the feature to Site Defs.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb CurrentWeb = properties.Feature.Parent as SPWeb;
String Body = "A Sub Site Created with Title \""+ CurrentWeb.Title+ "\" with the URL "+CurrentWeb.Url;
foreach (SPUser user in CurrentWeb.Groups["AllAlerts"].Users)
{
SPUtility.SendEmail(CurrentWeb, false, false, user.Email, "Site Creation Alert", Body);
}
}

//Use the sharepoint inbuilt capability of sendin and email fron the SPUtility

Tuesday, June 9, 2009

List Template Id

ListId - Description
100 Generic list
101 Document library
102 Survey
103 Links list
104 Announcements list
105 Contacts list
106 Events list
107 Tasks list
108 Discussion board
109 Picture library
110 Data Sources list
111 Site Template Gallery
113 Web Part Gallery
114 List Template Gallery
115 XML Form Library (InfoPath)
120 Custom grid for list
200 Meeting Series list
201 Meeting Agenda list
204 Meeting Decisions list
207 Meeting Objectives list
210 Meeting text box
211 “Things to Bring” Meeting list
212 Meeting Workspace Pages list
300 Portal Sites list
1100 Issue Tracking list
2002 Personal document library
2003 Private document library

Friday, June 5, 2009

Sharepoint Banner

  1. Create you banner.jpg and 
  2. Copy to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES
  3. Make modification in the core.css as shown below.("C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\STYLES\CORE.CSS")
Before Modification:
.ms-globalbreadcrumb{
font-size:8pt;
text-align:right;
background-color:#ebf3ff;
padding:2px 10px 2px 5px;
}

After Modification:
.ms-globalbreadcrumb{
font-size:8pt;
text-align:right;
background-color:#ebf3ff;
background-image:url("/_layouts/images/banner.jpg");
padding:2px 10px 79px 5px;
}