Sunday, September 23, 2012

List the "vti_" properties using PowerShell

Every file/document in SharePoint possess some meta-info. It is stored in hashtable presented by SPFile.Properties property. Most of the properties start with "vti_". We cannot write the "vti_" properties as they are read-only.

But we can use this property-bag store custom meta-property for the file. We can manage the custom properties using below method:
  • SPFile.AddProperty
  • SPFile.SetProperty
  • SPFile.GetProperty

SPFile.CustomizedPageStatus property determines the customization status of wiki page or page layout using below properties.
  • vti_setuppath
  • vti_hasdefaultcontent
Different SharePoint objects has the hashtable based property to store these kind of properties. e.g SPWeb.AllProperties. SPWeb.AllProperties["__PagesListId"] stores the GUID value of "Pages" library created on activating publishing feature.

Changing the UIVersion of migrated sites automatically updates the master page to appropriate UIVersion. This is possible because of the SPWeb.AllProperties. It stores the master page details related to each UIVersion.

PowerShell script to list the "vti_" properties of a file.

$web=Get-SPWeb <webSite URL >
$list=$web.Lists["Site Pages"]
foreach($item in $list.Items)
{
    $item.File.Name
    Write-Host "**********"
    foreach($key in $item.File.Properties.Keys)
    {
        Write-Host $key "=" $item.File.Properties[$key]
    }
    Write-Host "------------------*****---------------------------"
}

PowerShell script to list "vti_" properties of web site.

$web=Get-SPWeb <webSite URL >
foreach($key in $web.AllProperties.Keys)
{
     Write-Host $key "=" $web.AllProperties[$key]
}

Have a look!

Saturday, July 7, 2012

Missing IIS_WPG group on SharePoint 2010 server

If you have came across this TechNet link, you will find that the SP 2010 setup user account should be present in IIS_WPG group. We faced some issue for which we were investigating the account permissions and their group memberships.

On our servers we found that there is no IIS_WPG group. Initially I thought this can be the cause of issue. But I also noted that there is IIS_IUSRS group. I never paid attention to this group or never came across any such group in the context of Web development.

I googled for IIS_WPG and IIS_IUSRS keywords. I found a good link explaining the difference of these group. IIS_WPG is replaced by IIS_IUSRS group in IIS 7. Our servers are Window 2008 based and so our systems have the IIS 7.

IIS_WPG group is specific to earlier versions of IIS.

So if you find similar discrepancy in SharePoint systems, do not panic. Check for availability of IIS_IUSRS group.

Friday, June 15, 2012

Insert Picture From SharePoint is disabled in CEWP

Recently I came across a scenario in which the user was using content editor web part (CEWP) and using the Rich Text Editor ribbon of SharePoint 2010 to format the content. The user noted that "Insert Picture From SharePoint" option is disabled on a page.



I started investigating and came across MSDN Forum where it is mentioned that activating a publishing feature will resolve the issue. The site must be in publishing context. In our case, the site has the publishing feature activated.

We tried creating various kind of pages (Wiki Page, Web Part Page and Publishing Page). The option was enabled for every kind of page on the same site.

The option was disabled for only one page i.e. default.aspx. The page resides at the site root. I created a web part page in "Site Pages" and verified the option is enabled for the page. I opened the site in SharePoint Designer 2010. I moved the page to the site root. Again, I browsed for the page in edit mode and verified the option, it was disabled.

The page at site root does not belong to any library and has no associated content type for it. The page has few content management features disabled such as "Versioning", "Edit Properties". This is because the page was not child of any library (an orphan page or the parent is site).

Publishing feature has a strong bond with content management features. As the page do not have content management features available, it was not able to take advantage of the publishing context also. That's the reason, it was showing "Insert Picture From SharePoint" in disabled state.

This is not only this option, it also disables capabilities to cut, copy, paste in the Rich Text Editor.

Wednesday, June 13, 2012

Content Editor Web Part duplicating content

Today I received a request mentioning that Content Editor Web Part is duplicating the content. The user was adding clock object prepared in Adobe Flash. This clock was being duplicated whenever the user is editing the web part.

I checked the content editor web part. It has got too many "<embed>" tag. The tags were being duplicated. The clock was being rendered using some JavaScript method. We inspected the method. The method was using "document.write" to add the "<embed>" tag.

Content editor web part renders its HTML/JavaScript content on its canvas. So document.write was adding "<embed>" tag on every "Save" for the web part. So every edit action for the web part was adding "<embed>" tag causing duplicate clocks (content).

We resolved the issue by creating separate content file for Content Editor Web Part. The content file is linked to the Content Editor Web part. As the "document.write" is moved to separate file, for every request the file is read and parsed for render. "document.write" do not append content in the file. So it has no duplication of content.

Always use separate content file whenever we have a content which includes "document.write" in JavaScript.

More Reference(s):

Wednesday, May 23, 2012

SPDocumentLibrary.CheckedOutFiles? A Common Misunderstanding

What is a checked out file?
Any file which locked for changes...so the changes are not visible to the other users. In SharePoint, we have a option to check out a file.
Go to the library, open a file's ECB (Edit Control Block) menu options and clik "Check Out" menu item.

So any file, which is checked out this way, is a checked out file. Isn't it? Yes, it is checked out file.

Now, try this.
Write a small console application, which will display count of SPDocumentLibrary.CheckedOutFiles. In case of SharePoint 2010, a small PowerShell script will do.

Execute the utility and note down the count of Checked Out files. Go to a document library and check out one file. Re-execute the utility and read the count...It does not change.Try again with two-three files. It does not change the count of SPDocuemntLibrary.CheckedOutFiles.

Why?
 MSDN describes "SPDocumentLibrary.CheckedOutFiles" as "the collection of files that are uploaded to the document library but are not checked in."

If the document library requires check out before editing any file and you upload a file to this library...the file will added in a checked out state. The file does not have a checked in version available. The file will not be visible to any one before check in.

SPDocumentLibrary.CheckedOutFiles represent the collection of files, which do not have a checked in version.

"Requires Check out" setting is available in "Version Settings" of library.

Can we override Check out of these files from Object Model?
SPDocumentLibrary.CheckedOutFiles is a collection of SPCheckedOutFile objects. SPCheckedOutFile does not derive from any class. SPCheckedOutFile does not have any member to check in the file.

SPCheckedOutFile has a property "ListItemId". If we exploit it to retrieve SPFile object, then we can check in the file. SPFile has a method "CheckIn". Code must be executed with the credentials of the user who has the ownership of these files. As the files are not visible to others, code with other user credentials fails to retrieve the SPFile object for these files.

SPCheckedOutFile type has a method "TakeOverCheckOut". If we use this method, you will have the file ownership and then we can retrieve the SPFile object for check in purpose.

Can we override check out of these files from UI?
These files are only visible to the user who has uploaded the files. Then how to override the check out for these files.
Go to the library settings, you will see a link "Manage Checked Out Files" in "Permissions and Management" category. MOSS 2007 and SharePoint 2010 has different versions of the link text as  follows.
MOSS 2007:
SPS 2010:
SharePoint 2010 corrected the confusing text.

So click on this link, and you can see the files which do not have checked in version. The UI provide the option to take the ownership of these files. Take the ownership of this files and from library view, you can check in/ delete the files. Taking ownership of these files, makes the files visible to you only and other users can not see the files.

Files checked out which have checked in version
Any file which is explictly checked out from the library...is visible to all with check out status. It can be retrieved as SPFile object. SPFile has properties to read the details of check out. These details are also presented in UI.

SPFile.CheckOutStatus property indicates whether the file is checked out or not. There are other members of SPFile which gives details about check out. e.g.CheckedOutBy, CheckedOutDate etc.

As the files are visible to all, we can easily override the check out of these files from UI or Object Model code.

To summarize
SPDocumentLibrary.CheckedOutFiles represents files which does not have checked version. This property does not count the files, which are explictly checked out. This property should not be used to report the number of checked out files.

Use loop in object model and count the files with CheckedOutStatus turned ON.  Then add the count of SPDocumentLibrary.CheckedOutFiles.

In UI, create a view of checked files, note the count of files. Visit "Manage Checked out files" link in library settings, count the files. Add the counts of these files.

Tuesday, May 8, 2012

Home page of Wiki Page Library / Site

SPFolder class has a "WelcomePage" property. This property is used to set home page for a site / a library or a folder. How to do use it in PowerShell?

1. To set site home page.

$web=Get-SPWeb {webUrl} #remove curly braces
$web.RootFolder.WelcomePage="default.aspx" #change to appropriate value
$web.RootFolder.Update()

2.To set a default page for Wiki Page Library. If clicking on "Wiki Page Libray" in quick launch menu or in all site contents directly opens a page in the library instead of showing the library pages, execute below script. It will start showing all pages.

$web=Get-SPWeb {webUrl} #remove curly braces
$list=$web.Lists[{Wiki Library Name}] #curly braces must be removed.
$list.RootFolder.WelcomePage="Forms/AllPages.aspx"
$list.RootFolder.Update()

Saturday, May 5, 2012

List Settings Error 0x80070024

Recently we faced a problem accessing "List Settings". The error said "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator. 0x80070024." The List Settings page was working fine in the other site collections.

We created one custom list with one item. The list has the same issue even though it has single item.

We found an entry in ULS Logs saying "big list, slow query operation" The log has mentioned the List GUID which is being queried. I wrote a Powershell to find the list. The list is hidden "Workflows" document library. I tried the document library URL in browser, it returned me "404 Not found". One of my colleague used the list guid with _layouts/listedit.aspx(application page List Settings refer) and it did show us the Library settings. We verified the library settings but it did not helped.

I wrote a PowerShell to find the number of items in the list and it returned 0. So there are no items but still it is causing the issue. We were clueless about the behavior. I wrote the below PowerShell script, executed it, and there were no errors on hitting the "List Settings".

$web=Get-SPWeb [webUrl]  #remove the square bracckets here
$list=$web.Lists["Workflows"]  #Keep the square brackets in this line.
$list.EnableThrottling=$false
$list.Update()

For the time being, we used this solution. I am investigating the cause for the issue. The "Workflows" document library is used to store the site level workflows. The library is created by SharePoint Designer (SPD) on first ever SPD workflow creation in the site.

Visit again, for the updates!
[Update 05/08/2012: I found that the "Workflows" library reports -1 in ItemCount. As such, no list or library should report ItemCount as a negative number. As mentioned in this post, Microsoft has accepted that MOSS 2007 has the issue of negative ItemCount. The site, we are referring to, is a migrated site. So the library was reporting negative ItemCount. Negative item count is a cause for failure of indexing operation. If indexing fails, queries perform slow. It was causing the throttle issue even though the "Workflows" library is empty.

Resolution: If the "Workflows" library is empty, delete it. SharePoint Designer will recreate the library on SPD workflow creation. If the library is not empty, then there will be no issue as ItemCount will always report positive number.

The issue may occur only in migrated sites hoping that Microsoft has taken care of the issue in SharePoint 2010.]