SharePoint Debugging : Determine which worker process to attach while debugging

Most of the times, during SharePoint debugging,we see that while trying to attach to process “w3wp”, many process with same name are listed.

How to determine which process we need to attach to? As the dialog box does not contain Application Pool details. Follow the steps given below to easily identify the correct worker process.

  1. Open the Command Prompt with Administrative Privilege
  2. Change the directory to c:\Windows\System\Inetsrv
  3. run “appcmd list wp“. It would list all the worker processed with ID and application pool information:

apppool

4. Find out process ID associated to the web application pool you want to debug.

5. Go back to Visual Studio “Attach to Process” dialog box and associate to correct process with ID we got in Step # 4.

Happy Debugging!!!!

sharepoint column default value settings not applied via content type

Problem:

Created Document library and associated custom content type with a site column containing default value. Say a numeric field with default value 1.

But when i upload document and select my custom content type, default value does not appear and is always blank.

Reason and solution:

Thanks to SWEE CHING’s article, that i found the solution. Reason was that my custom content type was not set as default content type. If you want your default values to appead pre-selected, you have to set your custom content type as default.

Hope it will help someone!

Content Organizer execution order

Content Organizer is used to organize your content automatically, based on custom-defined rules. However, these rules add new entity to the hierarchy of events that can be executed for the List items, and this execution order is not well documented. It’s important to understand the sequence to process documents accordingly.
For example, when the user uploads his CV to the library you want to add watermark by Workflow, update .docx metadata with event receiver and round document to “unprocessed” folder using content organizer. We have “DropOff Library” with WorkFlow, EventReceiver attached and with Content Rules. The default execution sequence will be the following:
  1. WorkFlow
  2. Event-Receiver
  3. Content Organizer Routing Rules
PS: Take into account that WF/EventReceiver sequence can be changed programmaticaly, using Sequence property of SPList.EventReceivers, but when you reconfigure Workflow it always gets the first order in execution
PPS: Content Organizer Routing Rules impersonates the Application Pool account, thus in might perform actions under “System Account” and your destination folder’s WorkFlow will not start.

Stringbuilder object returning result while using Append function

Problem

For appending content to stringbuilder object we use Append() as

$sb = New-Object -TypeName “System.Text.StringBuilder”;
 $sb.Append(“This is a demo”);
expected the result is
This is a demo
However the result is
                  Capacity                MaxCapacity                    Length
                  ——–                ———–                    ——
                        16                 2147483647                         11
This is a demo
Reason
Several of the methods on StringBuilder like Append IIRC, return the StringBuilder so you can call more StringBuilder methods. However the way PowerShell works is that it outputs all results (return values in the case of .NET method calls).
Solution
In this case, cast the result to [void] to ignore the return value e.g.:
[void]$sb.Append(“This is a demo”)

Prevent site users from adding more data

Problem

The Enterprise has embraced SharePoint technology and generates a large amount of data on the server. As disk space is consumed, at times, content size might exceed the maximum storage limit of a site collection. At such time when any user attempts to create/upload the content, there are probable chances of loss of data.

Solution

For such a scenario, SharePoint provides Locks which would prevent all users to make any kind of additions to the site collection. Not only that, but with proper privileges one could prevent users to change the content or even can prevent access to all users of the site collection. For our scenario, we would prevent all the users to add content to the site.

To do so in SharePoint 2010, open SharePoint Central Administration. Click on Application Management.

1.jpg

 

​Click on “Configure quotas and locks”.

2.jpg

Choose the appropriate Site Collection. For achieving our purpose, select “Adding Content Prevented” which would not allow any user to add content to the site collection.

3.jpg

Choose OK.
The SharePoint Administrator can also use Windows Powershell as follows:
Go to Start menu -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell.
At the command prompt type…
Set-SPSite -Identity “<SiteCollection>” -LockState “<State>”

…where <SiteCollection> will be the url of site collection and <State> will be one from Unlock, NoAdditions, ReadOnly and NoAccess.
Now try to add content to the site collection and you would face the below error. 

4.jpg

Reusing Content Type: Content Type Hub

​SharePoint defines content types to store different types of metadata. SharePoint 2007 was limited in respect to content type centralization and sharing between site collections/web applications.

SharePoint 2010 introduces a new concept called the ‘Content Type Hub’. It is a centralized application where users can create different content types and publish them. As it would be defined as content type hub, every application could use it with a single configuration. The advantage is it would be centralized and could be shared among different applications. In this article we will show how to achieve this.

First of all create a new web application and a team site.

CT -1

 

Now go to Central Administration  -> Application Management  -> Manage Service Applications  -> Select Managed Metadata Service. Click Properties on the Ribbon.

CT-2

Scroll down to the Application Pool Section. In the lower half, under Content Type Hub, we need to add the URL of the root site collection of web application which we have just created. By adding it here, it will define the web application as a content type hub. Once you have added it, click OK.

CT-3

Move back to created web application and create a content type (I name mine ‘EmployeeContentType’). It has some basic information like empname, empno, empage, empaddress and empcontact.

CT-4

After defining all metadata, click on “Manage publishing for this content type”. A screen will appear with three options “Publish”,”Unpublish” and “Republish”. In our case, Select Publish and click OK.

CT-5

Now for an immediate effect, we need to run two timer jobs. The first is the Content type Hub and other the is the Content Type Subscriber. Do this from Central Administration  -> Monitoring  -> Timer Job Definitions. 

 CT-6

Now go to the site where you want to have the defined content type. Go to Site Settings  -> Site Collection Administration  -> Content Type Publishing.

CT-7

If everything was followed correctly, you should be able to see the defined content type under ContentTypeHubService (Managed Metadata Service name). If not, click on “Refresh all published content types on next update” and select OK and by next timer job execution, it will be published and imported automatically.

CT-8

You can also check in Site Settings  -> Site Content Types. It should be listed there too.

CT-9