Archive

Archive for the ‘Uncategorized’ Category

New Programming Jargon

August 6, 2012 2 comments

 

Love this new list of jargon used by teams around the world. Find it here http://www.codinghorror.com/blog/2012/07/new-programming-jargon.html

 

My favourite – possible because it happens far to often

Protoduction

 

A prototype that ends up in production. Heard this from a tech at the Fermi lab. He said he didn’t coin the term but had heard it used a number of times at Fermi.

Advertisements
Categories: Uncategorized

Getting Project Server database information via C# / How to run PowerShell command in C#

July 31, 2012 2 comments

For a long time now I have had a few scenario’s where it would be helpful for me to know what the database server and database names are of a Project Server instance. The PSI does not provide this information but there is a PowerShell command that will give you the information.

Get-SPProjectWebInstance –url <URL>

This gives me all the info a want about the instance.

image

So now I know I can get the info i need i just need a way of getting this within c# code.

Helpfully you can use System.Automation to execute PowerShell scripts within .NET

We start with a simple method that will execute PowerShell commands

private string RunScript(string scriptText)
        {
            string addWss = "Add-PSSnapin microsoft.sharepoint.powershell";
            Runspace runspace = RunspaceFactory.CreateRunspace();
            runspace.Open();
            Pipeline pipeline = runspace.CreatePipeline();
            pipeline.Commands.AddScript(addWss);

            pipeline.Commands.AddScript(scriptText);
            pipeline.Commands.Add("Out-String");
            var results = pipeline.Invoke();

            runspace.Close();

            StringBuilder stringBuilder = new StringBuilder();
            foreach (PSObject obj in results)
            {
                stringBuilder.AppendLine(obj.ToString());
            }

            return stringBuilder.ToString();
        }

The above code needs

using System.Management.Automation;
using System.Management.Automation.Runspaces;

NOTE: You’ll need to add a reference to the version of PowerShell you have installed in your GAC to the Visual Studio project file. To do so, you’ll open the project file as a text file and add the following line into the <ItemGroup> section:

<Reference Include=”System.Management.Automation” />

I was able to cheat and “browse” to the assembly using the following path

C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll

Now that we have the helper method I can actually get the info I want.

string answer = RunScript("Get-SPProjectWebInstance -url http://vm641/pwa2");
string reportingDatabaseServer = string.Empty;
string reportingDatabaseName = string.Empty;

var output = answer.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).Cast<string>();

reportingDatabaseServer = (from x in output where x.StartsWith("ReportingServer") select x).First().ToString();
reportingDatabaseName = (from x in output where x.StartsWith("ReportingDatabase") select x).First().ToString();

reportingDatabaseServer = reportingDatabaseServer.Replace("ReportingServer", "").Replace(":", "").Trim();
reportingDatabaseName = reportingDatabaseName.Replace("ReportingDatabase", "").Replace(":", "").Trim();

Bingo I have the name of the reporting server and the database name.

I needed this months ago to auto configure a PSI extension that was written but i need it now to auto configure a feature when it is deployed.

I’ll wrap all the above code into a single class that accepts the instance URL in its constructor and then expose properties with the information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation.Runspaces;
using System.Management.Automation;
using System.Text;

public class ProjectWebInstanceInformation
{
    #region Fields and Properties
    public string ReportingServer { get; private set; }
    public string ReportingDatabase { get; private set; }
    #endregion

    #region Constructor
    protected ProjectWebInstanceInformation()
    {
    }

    public ProjectWebInstanceInformation(string Url)
    {
        try
        {
            string answer = RunScript(string.Format("Get-SPProjectWebInstance -url {0}", Url));
            string reportingDatabaseServer = string.Empty;
            string reportingDatabaseName = string.Empty;

            var output = answer.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Cast<string>();

            ReportingServer = (from x in output where x.StartsWith("ReportingServer") select x).First().ToString().Replace("ReportingServer", "").Replace(":", "").Trim();
            ReportingDatabase = (from x in output where x.StartsWith("ReportingDatabase") select x).First().ToString().Replace("ReportingDatabase", "").Replace(":", "").Trim();
        }
        catch { }

    }

    #endregion

    #region Methods
    private string RunScript(string scriptText)
    {
        string addWss = "Add-PSSnapin microsoft.sharepoint.powershell";
        Runspace runspace = RunspaceFactory.CreateRunspace();
        runspace.Open();
        Pipeline pipeline = runspace.CreatePipeline();
        pipeline.Commands.AddScript(addWss);

        pipeline.Commands.AddScript(scriptText);
        pipeline.Commands.Add("Out-String");
        var results = pipeline.Invoke();

        runspace.Close();

        StringBuilder stringBuilder = new StringBuilder();
        foreach (PSObject obj in results)
        {
            stringBuilder.AppendLine(obj.ToString());
        }

        return stringBuilder.ToString();
    }
    #endregion
}

SharePoint 2010 and 2013 WSP

July 25, 2012 1 comment

 

Nice post here about creating a WSP for both 2010 and 2013. Or i should say upgrading your 2010 WSP to work on both

 

http://www.danlarson.com/sharepoint-2010-and-2013-wsp-compatibility/

Categories: Uncategorized

Null content database and how to resolve

July 19, 2012 Leave a comment

So i have just had a fun problem. In some custom code I access the first database in the SPContentDabaseCollection against the webapplication.

This was returning a null object because the database didn’t exist. I clearly broke something when doing a system rollback.

Anyway, to solve the issue i followed the steps in the following post and it all worked.

Didn’t need to do any database hacking 🙂

Solution:
This is a case of at least 1 orphaned database associated to the problematic web application.
1. Run below powershell command to get GUID of web application.
get-spwebapplication | ? {$_.displayname -eq “Problematic Web Application Name”} | fl
2. Run this SQL query against configuration database.
select ID, Name, CAST (properties as xml) from Objects where ID = ‘GUID of webapp from Step 1’
3. The results returned from step 2 will have 1 column with the properties as xml. Click on the results and it should open a new window in SQL Mgmt studio with xml output.
4. Search for the word “m_Databases” in the xml output.
5. Carefully read through the tag that stores the above searched word. You should be able to see fld tags. Find out a tag which has fld tag with value null. This is the orphan database. Its GUID is the xml line above where you found null.
6. Cross verify all databases currently associated with the web application and make sure this database is not getting used.
7. Run below powershell script,
$webapp.contentdatabases.delete(‘ID-of-bad-content-db’)
This script will throw an object reference error. Do not worry, it works its magic under the hood.
Try to create a new site collection now and it should work.

http://mydailytechlog.blogspot.co.uk/2011/12/sp2010-cannot-create-new-site.html

Categories: Uncategorized

Jquery to drop IE 6 7 and 8 support in version 2.0

July 16, 2012 Leave a comment

I suspect we will start to see a lot more of these statements in the near future.

Next year when v2.0 of Jquery is released it will not support IE6, IE7 or IE8

Read more on their blog http://blog.jquery.com/2012/06/28/jquery-core-version-1-9-and-beyond/

 

 

Categories: Uncategorized

How to deploy InfoPath forms with code as part of a feature

Very well written blog post explaining the real way to include an infopath form with code as part of a feature.

http://nader.elshehabi.com/2011/08/how-to-really-deploy-infopath-2010-forms-with-code-behind-as-a-feature/

Categories: Uncategorized

Test Post

This is a quick post to test a friends cross posting tools

Categories: Uncategorized Tags: