Dynamics CRM: Get Parent GUID from C# Plugin

 

QueryExpression query = new QueryExpression(“msdyn_workorder”);

query.ColumnSet.AddColumns(“msdyn_postalcode”);

Guid parentId = ((EntityReference)entity[“msdyn_workorder”]).Id;

 

Entity parentEntity = service.Retrieve(“msdyn_workorder”, parentId, new ColumnSet(true));

 

String postalcode = parentEntity[“msdyn_postalcode”].ToString();

Advertisements
Posted in Uncategorized | Leave a comment

ProTip: Ensure your IIS Timeout is on par with your Web.Config and SQL Timeouts

This may sound like a foolish thing to miss, and in reality, it was.  But, I found out the long and hard way just how careful you have to be with your configurations.

Our SharePoint 2010 application is a large custom tool that operates on top of subsites and lists, almost as if they were tables or entities within a normal CRM app.  There are queries that must traverse all 400+ subsites and each of their lists and document libraries, so there were frequent SharePoint errors for our users.

About a year back, before I had access to the actual Prod servers, we had requested the timeout values in our Web.config be altered to 10 minutes (600 seconds) to match what was set forth on the SQL Server query timeout.  This ended up not helping at all, but no one on the team could understand why.

After getting access to the servers and doing some heavy digging, I stumbled upon the Advanced Setting > Connection Timeout for an IIS site.  It’s hidden at the bottom, and also is in a submenu that has to be maximized (sorry, not at a Server now or I’d check its name).  At any rate, this value was only set to 120 seconds.  The problem with this is that if IIS times out at 2 minutes, it does not allow the Web.config to be read, and obviously terminates the query to SQL as well.  We had identified the bottleneck that has been causing so many SharePoint Errors.

So, after putting the necessary paperwork in to up this value (which seemed overkill to me, but clients are clients), we have seen a drastic decrease in the number of errors that our end users see.  Obviously, processing of these requests that used to bring errors can now last up to 10 minutes – and may still end up in error, but in my testing, most of the tasks that used to error out needed only an additional 30 seconds to a minute to complete.  Our users are much happier overall.

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

SharePoint 2010 and PowerShell to count all list items in a Web Application

This problem manifested itself for a variety of reasons, but mainly, our vast Site and its subsites (over 400) have been growing very close to our List View Threshold (LVT), which has already been increased to 10,000.  Normally this wouldn’t be a huge problem, but the custom application we have sitting on top of SP 2010 does not handle lists over the LVT very well, as many of our operations perform tasks on “All List Items” – which as you know is disabled when you pass the LVT.   I have found that you can bypass this in code, however I am not a developer and the C#.NET project is over 600 files, which would be a huge undertaking  for someone like myself.  So, we needed to be able to identify and act upon any list in our web application that would be accessed by our code.  Without a development resource, I figured I’d start playing around in PowerShell for a solution.

After much research, trial, and error,  I have created a great script to do the following, all using SharePoint 2010 Management Shell (or PowerShell):

  • Delete the existing monitoring list before it runs.  This keeps the list items manageable for users who may be analyzing the data in SharePoint.  This was chosen over deleting list items for performance reasons.  Since the list data has no real value to us after the CSV is created, it is more there as a by-product of my research and development.  This will likely be removed before going to production.
  • Re-Create a list based on a saved  template.  This ensures our write methods will have the proper containers to be written to.
  • Create a new .CSV file and append a date string to it.  This is important for a number of reasons — firstly, the script requires a file be present to be written to.  Secondly, we want to be able to store different versions of this file on the filesystem.  Lastly, and most importantly, we want to ensure that there is a Document Library on the SharePoint site that holds all versions of this document.  The date string can be modified to meet your needs, I included mm-s at the end because this script was used in a test environment and I was running it much more frequently than I would in production.
  • Loop through all SPList (baseType =”GenericList” — Change this to “DocumentLibrary” to loop through SP DocLibs) items within any given web application and gather the URL, List Name and ItemCount for each item.  ItemCount is used to get the number of Folders+Items.  You can also add other methods of the SPList class to get other data available through the SharePoint API.
  • Save all results of the List processing to a CSV File.  This is the CSV file that was created in Step 3 above.
  • Write each row of the CSV file to it’s own SPList item.  These items exist in the list created in step 2 above.
  • Upload the finalized CSV file to a SharePoint Document Libary

So after a long intro and discussion, here is the actual script.  There are some comments in-line to give the reader a better idea of what each function is doing.

A Windows Scheduled Task will be created to call this script on a weekly basis.  This will allow us to have up to date counts every Monday morning so we can plan corrections as needed.  The CSV files will be available to download to any user who has access to the Document Library listed in the code, and the List will be kept up to date (weekly) by being cleared out and re-created.

This is my first real foray into using PowerShell to work with and manipulate a SharePoint application and it’s sites.  I am excited to continue realizing the potential of PowerShell for scripting with SharePoint.

 

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
#Delete Existing List
$w = Get-SPWeb "http://sitecollection/web"
$w.Lists.Delete([System.Guid]$w.Lists["ListMonitoring"].ID)

#Create New List based on template to have columns
$site = Get-SPSite http://sitecollection
$web = Get-SPWeb http://sitecollection/web
$listTemplates = $site.GetCustomListTemplates($web)
$web.Lists.Add("ListMonitoring", "Auto-Created List to Monitor List     Counts", $listTemplates["ListMonitor"])


#Start Actual Script for Counting
Start-SPAssignment -Global
$date = Get-Date -format "yyyy-MM-dd-hh-mm-s"
New-Item -path D:\Folder  -name Doc$date.csv -type "file"
$OutputFile ="D:\Folder\Doc"+$date+".csv"

$results = @()
$webApps = Get-SPWebApplication http://webapp

foreach($webApp in $webApps)
{
    foreach($siteColl in $webApp.Sites)
    {
        foreach($web in $siteColl.AllWebs)
        {
            $webUrl = $web.Url
            $docLibs =  $web.Lists | Where-Object {$_.BaseType -eq "GenericList"}
            $docLibs | Add-Member -MemberType ScriptProperty -Name WebUrl -Value {$webUrl}
            $results += ($docLibs | Select-Object -Property WebUrl, Title, ItemCount)
                    #$count = ($docLibs | Select-Object -Property ItemCount)     
        } #endforeach web in SiteColl.AllWebs
    } #endforeach SiteColl in WebApp.Sites
} #end foreach webapp in webapps

#populate CSV
$results | Export-Csv -Path $OutputFile -NoTypeInformation

#Write each CSV Row to a new list item

#CSV path/Filename
$contents = Import-csv "$OutputFile"

#WebURL
$myweb = Get-SPWeb -Identity "http://sitecoll/web"

#SPListName
$list = $myweb.Lists["ListMonitoring"]

#Process List after CSV is complete to help processing speeds
foreach ($row in $contents)
{
$item = $list.Items.Add();
$item["Title"] = $row.WebUrl.ToString();
$item["Count"] = $row.ItemCount.ToString();
$item["List"] = $row.Title.ToString();
$item.Update();
} #endforeach row in contents

$myweb.Dispose();
$web.Dispose();
Stop-SPAssignment –Global

#Upload CSV to Document Library for Historical Purposes
function UploadFile($Web, $DocLibName, $FilePath)
{
   $List = $Web.GetFolder($DocLibName)
   $Files = $List.Files
   $FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1)
   $File= Get-ChildItem $FilePath
   $Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false)
 }
$SiteUrl = "http://sitecoll/web"
$Web = Get-SPWeb $SiteUrl
UploadFile $Web "DocumentCounter" "$OutputFile"
Write-Host "Documents Uploaded to $SiteUrl"
$web.Dispose()
Posted in Uncategorized | Tagged , , , | 1 Comment

SharePoint 2010 System.Security.Cryptography.CryptographicException occured in OWSTIMER.EXE – Resolved

This is an error that only appears when you have Visual Studio installed on your SharePoint 2010 box — so typically, in development and testing environments.  This error is known to pop up at least once a day, when the OWSTIMER.exe recycles itself, by default, once a day.  You can also force this error by stopping the SharePoint Timer service (either in services.msc or by running ‘Net stop sptimerv4’ in PowerShell).

JITDebug

I have seen numerous posts about this exact error, and most people just say ‘disable Just In Time Debugger’ for Visual Studio — Well, that is not a proper solution, and frankly, I wouldn’t trust someone who told me that it was.  I dug into this a bit deeper with one of my developer co-workers, and we found a quick and easy fix to this.

First, if you are running more than one SharePoint Server (in our topology, we have 2 WFE servers as well as a dedicated Central Admin server), verify that the same account is running the Share Point Timer Service.  This account will need to be in the administrators group on each of the SharePoint boxes as well, but if your Timer service was working before, I’d assume you’ve taken those steps already.

Now, take note of the account that is running the SPTimer service, and go to the Farm Administrators Group in Central Administration.  To do this, From the default page of CA, under the Security Group, click ‘Manage the farm administrators group’.  Open that, and be sure that the account which is running the service is listed there.  If it is not, add it.

To test, open a new PowerShell window and run:
Net Stop SPTimerv4

If no error pops up, you have fixed the error.  You are now free to restart your Timer service and enjoy your now-error-free SharePoint server.

Posted in Uncategorized | Tagged , , , | 2 Comments

SharePoint 2010 – Deleting Service Applications via SharePoint 2010 Management Shell

Our SharePoint 2010 environment is hosted in a virtualized private cloud in the basement of our headquarters office, and there was a request to have snapshots taken of the server configuration and then restored.  When this happened, we were left with a faulty FAST Search Search Service Application (SSA), SSA Proxy, and Content Source.  After scouring the internet, the best remedy I could find was to delete these SSAs and then re-create them. 

I navigated to the Central Admin site, and clicked on Manage Service Applications (under Application management).  Once you highlight the record you wish to delete (don’t click the link) there is a ‘Delete’ option in the ribbon above.  After waiting for quite some time for this to go through, it ended up timing out, and leaving me with the service applications, even though I had waited upwards of an hour to complete this. 

After more searching, I found the remedy of how to delete these service apps through the PowerShell/SP2010 Management Shell.  Here are my findings:

Note: This deletes your service application and it cannot be undone.  Please pay careful attention to the GUID that you are using so as to not delete an SA that you wish to keep in tact.

  • Firstly, open up SPS2010 Management Shell (Start > All Programs > Microsoft SharePoint 2010 Products > SPS2010 Management Shell)
    • This SPS2010 management shell has the trusty old ‘STSADM.EXE’ functionality built into it, which was a gotcha at first pass.  I tried to locate STSADM.EXE and drag into a CMD window, like you would in MOSS 07, but there is no STSADM.EXE living on the box.
  • The following command will delete your SA:  stsadm -o deleteconfigurationobject -id GUID.  The GUID can be found by mousing over the SA you wish to delete, and then looking in the status bar at the bottom of IE, where you’ll typically see the target of the link.  This GUID is long, so I took a screenshot so I knew I wouldn’t mess it up
    • The actual command I ran was (no quotes): “stsadm -o deleteconfigurationobject -id f526fa41-de2b-44d0-b678-8e2fcc5df40
  • “Operation Completed Successfully” is dislayed on the Management Shell window.  You can now navigate back to CA and refresh your Service Applications screen, you should not see the items you deleted.
 
 I hope this helps and saves some time for the other SPS 2010 developers/administrators out there.
 
Posted in SPS 2010 | Tagged , , | Leave a comment

Deploying WSP in SharePoint 2007 via CMD Prompt, Central Admin

After much searching around on the web, and multiple failed attempts to deploy a WSP into my MOSS 07 environment, I have pieced together the correct steps for doing this.  If you’re unfamiliar with WSPs, well, you probably wouldn’t be reading this article, but basically they allow for teams to send out solution packages to baseline disparate environments.  These WSP files will remove all of the data in the Web Application to which it is deployed — so be sure to either back it up, or have a small amount of data that is easily reproduced.  WSPs were used without data backups in a development and testing effort for a MOSS 07 build.

Some of the sites tell you to drag STSADM.EXE onto a CMD window and enter some code, and pray that it works.  I can tell you from experience that this is quite a pain to do, so I have taken the approach from many different sites and pulled them together.   This is assuming you’ve been handed a WSP by a colleague and need to deploy (and have the rights to the database to do so — You’ll need an account with full control of the DB you’re hitting)

Note: If you have already deployed a previous version of the same WSP, you will need to retract and then remove it.  WSPs are tracked not only by filename, which likely will change with updates, but also by GUID.  You will need to follow these steps to retract/remove the WSP.

  • Navigate to Central Administration and click Operations
  • Under Global Configurations, click on Solution Management
  • You should see your WSP listed.  Click on the hyperlink (name field)
  • Click on “Retract Solution”  The screen will pop up and say “retracting”
  • Refresh, you should see Status: Retracted.  You will need to click the hyperlink again (name field)
  • Click Remove solution
  • Say yes to the prompt
  • Your solution is removed.  Now you can go ahead with the deployment of a new solution.

 

  • Navigate to your Application server, where you’ll have imported the WSP already.
    • Note: You will have to manually type out the location of the WSP, I place mine on the root of the system (E:\WSP\) to make it a bit easier.
  • Open a Command Prompt Window
  • Type the following:
    @SET STSADM=”c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm.exe”
  • Press Enter
  • Type the following:
    %STSADM% -o addsolution -filename OfficeSpaceFeature.wsp  (Path for mine was E:\WSP\file.wsp)
  • You will see a confirmation message “Operation Completed Successfully

The solution has been placed in the solution store, now you have to go into Central Administration and deploy it;

  • Open Central Administration
  • Navigate to Operations
  • Under Global Configuration, click Solution Management
  • You will see a list of all the solutions you have in your environment — Click the hyperlink for the solution you just placed in the solution store.
  • Choose if you want to deploy it to All web applications, or just a specific web application
  • You can also schedule this for a time when you won’t interrupt traffic (After the WSP is deployed, IIS automatically restarts)
  • You are brought to the Solutions page and the solution shows “Deploying”
  • Once it says Deployed, your solution package has been deployed

Now you have deployed the solution, and need to enable the features on the Site Collection and Site level.

  • Navigate to the Site Collection which you will be deploying the WSP to
  • Click Site Actions
  • Click Site Settings
  • Under Site Collection Administration, Click Site Collection Features
  • Find the feature you want to deploy (whoever compiled the WSP will have this name) and click Activate

Your WSP has been enabled at the site collection level.

  • Navigate to the site which you will deploy the WSP to
  • Click Site Actions
  • Click Site Settings
  • Under Site Administraiton, click Site Features
  • Find the feature you want to deploy(whoever compiled the WSP will have this name) and click Activate

Your WSP has been enabled at the site level

Note: This process is for MOSS 2007, and I have not tested it in SPS 2010.  I would imagine the process is similar, but STSADM is built into PowerShell for SharePoint in 2010, so when I do some WSP moving in 2010, I will post another blog entry.

 

Posted in MOSS 2007 | Tagged , , | Leave a comment