Digitally Imported – Windows Radio Player

Music broadcast has come a long way from age old radio stations to digitally downloadable to online streamed contents. Online radio stations have survived for almost a decade and with decreasing internet tariffs they are fast becoming popular.

Couple of my favourite online radio station are di.fm and sky.fm which have some awesome channels. These stations stream content in various formats such as MP3, AAC etc. The only problem with them is, you have to rely on their website to change the channels if used from desktop based systems.

Coming back to the problem of relying on website to change channels, I was planning to develop my own Windows desktop based client. While doing research related to this came across a project at DI’s forums called as “DI Radio Player”

It has some good features and few of my favourites are listed below.

  • Listing of current track
  • Choose radio stations
  • Choose channels
  • Auto Update
  • Visualization options

This radio player is based on .NET 2.0.

You can follow the following link to discuss and download the player.

Discussion: http://forums.di.fm/world-of-music/digitally-imported-windows-player-unofficial-269504/
Download: http://tobiass.eu/

Both these Digital Imported & Sky FM channels have awesome mobile clients (DI, Sky) in almost all mobile OS categories + For the upcoming Window 8 Pro OS based tablets, this app will be a good option. Especially with Intel Clover Trail

Installing SharePoint 2013 Prerequisites Without an Internet Connection

When a SharePoint 2013 needs to be deployed in a server which doesn’t have internet access, and SharePoint requires prerequisite to be installed, we can do couple of things.

  1. Download prerequisites in a different machine which has access to internet.
  2. Move that to the actual server where SharePoint needs to be deployed.
  3. Use prerequisite installer to use local folder for installing the prerequisite.

Downloading prerequisites

We can download prerequisites using Powershell. Please use the following script.

Import-Module BitsTransfer
## Prompt for the destination path
$DestPath = Read-Host -Prompt "- Enter the destination path for downloaded files"
## Check that the path entered is valid
If (Test-Path "$DestPath" -Verbose)
{
	## If destination path is valid, create folder if it doesn't already exist
	$DestFolder = "$DestPath\PrerequisiteInstallerFiles"
	New-Item -ItemType Directory $DestFolder -ErrorAction SilentlyContinue
}
Else
{
	Write-Warning " - Destination path appears to be invalid."
	## Pause
	Write-Host " - Please check the path, and try running the script again."
	Write-Host "- Press any key to exit..."
	$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
	break
}
## We use the hard-coded URL below, so that we can extract the filename (and use it to get destination filename $DestFileName)
## Note: These URLs are subject to change at Microsoft's discretion - check the permalink next to each if you have trouble downloading.
$UrlList = ("http://download.microsoft.com/download/D/0/F/D0F564A3-6734-470B-9772-AC38B3B6D8C2/dotNetFx45_Full_x86_x64.exe", # Microsoft .NET Framework 4.5
            "http://download.microsoft.com/download/5/2/B/52B59966-3009-4F39-A99E-3732717BBE2A/Windows6.1-KB2506143-x64.msu", # Windows Management Framework 3.0 (CTP2)
	    "http://download.microsoft.com/download/9/1/3/9138773A-505D-43E2-AC08-9A77E1E0490B/1033/x64/sqlncli.msi", #Microsoft SQL Server 2008 r2 Native Client
	    "http://download.microsoft.com/download/D/7/2/D72FD747-69B6-40B7-875B-C2B40A6B2BDD/Windows6.1-KB974405-x64.msu", #Windows Identity Foundation (KB974405)
	    "http://download.microsoft.com/download/E/0/0/E0060D8F-2354-4871-9596-DC78538799CC/Synchronization.msi", # Microsoft Sync Framework Runtime v1.0 SP1 (x64) 
	    "http://download.microsoft.com/download/A/6/7/A678AB47-496B-4907-B3D4-0A2D280A13C0/WindowsServerAppFabricSetup_x64.exe", #Windows Server AppFabric
            "http://download.microsoft.com/download/0/1/D/01D06854-CA0C-46F1-ADBA-EBF86010DCC6/r2/MicrosoftIdentityExtensions-64.msi", # Windows Identity Extensions
            "http://download.microsoft.com/download/9/1/D/91DA8796-BE1D-46AF-8489-663AB7811517/setup_msipc_x64.msi", # Microsoft Information Protection and Control Client
            "http://download.microsoft.com/download/8/F/9/8F93DBBD-896B-4760-AC81-646F61363A6D/WcfDataServices.exe", # Microsoft WCF Data Services 5.0
            "http://download.microsoft.com/download/7/B/5/7B51D8D1-20FD-4BF0-87C7-4714F5A1C313/AppFabric1.1-RTM-KB2671763-x64-ENU.exe" # CU Package 1 for Microsoft AppFabric 1.1 for Windows Server (KB2671763)
			)
ForEach ($Url in $UrlList)
{
	## Get the file name based on the portion of the URL after the last slash
	$DestFileName = $Url.Split('/')[-1]
	Try
	{
		## Check if destination file already exists
		If (!(Test-Path "$DestFolder\$DestFileName"))
		{
			## Begin download
			Start-BitsTransfer -Source $Url -Destination $DestFolder\$DestFileName -DisplayName "Downloading `'$DestFileName`' to $DestFolder" -Priority High -Description "From $Url..." -ErrorVariable err
			If ($err) {Throw ""}
		}
		Else
		{
			Write-Host " - File $DestFileName already exists, skipping..."
		}
	}
	Catch
	{
		Write-Warning " - An error occurred downloading `'$DestFileName`'"
		break
	}
}
## View the downloaded files in Windows Explorer
Invoke-Item $DestFolder
## Pause
Write-Host "- Downloads completed, press any key to exit..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

 Once all the prerequisites are downloaded, copy them to server in a particular path and create the following batch file.

 Installing prerequisites

set PreReqPath="E:\Install\SharePoint\PrerequisiteInstallerFiles"
PrerequisiteInstaller.exe /SQLNCli:%PreReqPath%\sqlncli.msi ^
	/PowerShell:%PreReqPath%\Windows6.1-KB2506143-x64.msu ^
	/NETFX:%PreReqPath%\dotNetFx45_Full_x86_x64.exe ^
	/IDFX:%PreReqPath%\Windows6.1-KB974405-x64.msu ^
	/Sync:%PreReqPath%\Synchronization.msi ^
	/AppFabric:%PreReqPath%\WindowsServerAppFabricSetup_x64.exe ^
	/IDFX11:%PreReqPath%\MicrosoftIdentityExtensions-64.msi ^
	/MSIPCClient:%PreReqPath%\setup_msipc_x64.msi ^
	/WCFDataServices:%PreReqPath%\WcfDataServices.exe ^
	/KB2671763:%PreReqPath%\AppFabric1.1-RTM-KB2671763-x64-ENU.exe

Source: http://www.dontpapanic.com/blog/?p=241

Convert List<int> to List<string> in C#

I was faced with a micro challenge, of converting a List<int> to List<string>. After struggling for some time, decided to Google and found the the following solution !

List intList = new List();
List stringList = new List();

for (int i = 0; i < 10; i++)
	intList.Add(i);

stringList = intList.ConvertAll(delegate(int i) { return i.ToString(); });

Source: http://stackoverflow.com/questions/44942/cast-listint-to-liststring-in-net-2-0

TFS 2010: MSF Agile vs. Visual Studio SCRUM 1.0 Smackdown

TFS 2010: MSF Agile vs. Visual Studio SCRUM 1.0 Smackdown – Chris’s Blog – Just weedin around Microsoft – Site Home – TechNet Blogs(Click to view)

 

TFS 2010: MSF Agile vs. Visual Studio SCRUM 1.0 Smackdown– Planning w/ Agile (Part II) – Chris’s Blog – Just weedin around Microsoft – Site Home – TechNet Blogs(Click to view)

 

TFS 2010: MSF Agile vs. Visual Studio SCRUM 1.0 Smackdown — Planning w/ Agile (Part III) – Chris’s Blog – Just weedin around Microsoft – Site Home – TechNet Blogs(Click to view)

Access Denied – SharePoint code execution

When doing certain code operations in SharePoint like getting list of templates will lead to “Access Denied” exceptions. For such instances we can wrap the code within the following lines to execute code with elevated privileges.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
        //Code goes here
});

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

We were developing a Server Object Model based functionality in SharePoint involving site creation using template. During development we use to get the following error in quick watch window.

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

To solve this issue we added the following code before the actual statement and issue was solved.

SPSecurity.CatchAccessDeniedException = false;

 

Deleting a file from library using SharePoint ASMX web service

The following is the code for deleting a particular file from a library using SharePoint ASMX web service.
The technique involves identifying the document ID using “GetListItems” of the file and then executing “UpdateListItems”

public string DeleteFileFromSharePoint(string siteUrl, string libraryName, string fileName, FileDeleteInput input)
    {
        Lists listService = new Lists(); //Web reference of http://<server>/sites/<site>/_vti_bin/lists.asmx
        listService.Url = "http://<server>/sites/<site>/_vti_bin/lists.asmx";
        listService.UseDefaultCredentials = true;
        string sourceUrl = fileName;
        string output = string.Empty;

        try
        {
            int fileId = GetFileIdFromList(siteUrl, libraryName, fileName, listService.Url);

            XmlDocument doc = new XmlDocument();
            XmlElement Batch = doc.CreateElement("Batch");
            Batch.SetAttribute("OnError", "Continue");
            Batch.SetAttribute("ListVersion", "1");
            Batch.SetAttribute("ViewName", "");
            string strBatch = "<Method ID='1' Cmd='Delete'>";
            strBatch += "<Field Name='ID'>" + fileId + "</Field>";
            strBatch += "<Field Name='FileRef'>" + siteUrl + libraryName + "/" + fileName + "</Field>";
            strBatch += "</Method>";
            Batch.InnerXml = strBatch;

            XmlNode returnvalue = listService.UpdateListItems(libraryName, Batch);

            if (returnvalue.InnerXml.Contains("0x00000000"))
            {
                output = "Success: File Deleted";
            }
            else if (returnvalue.InnerXml.Contains("Invalid file name"))
            {
                output = "Failure: No such file exists";
            }
            else if (returnvalue.InnerXml.Contains("Access denied"))
            {
                output = "Failure: No such file exists";
            }
            else
            {
                output = "Failure: File couldn't be deleted";
            }
        }
        catch (SoapException ex)
        {
            throw ex;
        }
        catch (Exception)
        {
            throw ex;
        }
        return output;
    }

    protected int GetFileIdFromList(string siteUrl, string libraryName, string fileName, string serviceUrl)
    {
        int id = 0;

        Lists listService = new Lists(); //Web reference of http://<server>/sites/<site>/_vti_bin/lists.asmx
        listService.Url = serviceUrl;
        listService.UseDefaultCredentials = true;

        // Build the CAML Query
        System.Text.StringBuilder queryStringBuilder = new System.Text.StringBuilder();
        queryStringBuilder.Append("     <Query>");
        queryStringBuilder.Append("         <Where>");
        queryStringBuilder.Append("             <Eq>");
        queryStringBuilder.Append("                  <FieldRef Name=\"FileLeafRef\" />");
        queryStringBuilder.Append("                  <Value Type=\"Text\">" + fileName + "</Value>");
        queryStringBuilder.Append("             </Eq>");
        queryStringBuilder.Append("        </Where>");
        queryStringBuilder.Append("    </Query>");

        XmlDocument query = new XmlDocument();
        query.LoadXml(queryStringBuilder.ToString());

        //Build the View Query 
        queryStringBuilder.Clear(); // Clear the string builder
        queryStringBuilder.Append("    <ViewFields>");
        queryStringBuilder.Append("    <FieldRef Name=\"ID\" /><FieldRef Name=\"Title\" /><FieldRef Name=\"Name\" />");
        queryStringBuilder.Append("    </ViewFields>");

        XmlDocument viewFields = new XmlDocument();
        viewFields.LoadXml(queryStringBuilder.ToString());

        //Build the CAML Query Options
        queryStringBuilder.Clear(); // Clear the string builder
        queryStringBuilder.Append("    <QueryOptions>");
        queryStringBuilder.Append("         <Folder>" + libraryName + "/</Folder> />");
        queryStringBuilder.Append("    </QueryOptions>");

        XmlDocument queryOptions = new XmlDocument();
        queryOptions.LoadXml(queryStringBuilder.ToString());

        XmlNode listItems = listService.GetListItems(libraryName, null, query, viewFields, null, queryOptions, null);

        foreach (XmlNode outerNode in listItems.ChildNodes)
        {
            if (outerNode is XmlWhitespace)
                continue;
            else
            {
                if (outerNode.Name == "rs:data")
                {
                    foreach (XmlNode innerNode in outerNode.ChildNodes.OfType<XmlNode>())
                    {
                        if (innerNode is XmlWhitespace)
                            continue;
                        else
                        {
                            id = Int32.Parse(innerNode.Attributes["ows_ID"].Value.ToString());
                        }
                    }
                }
            }
        }

        return id;
    }