Sep 222015
 

Issue

Just be careful with the SharePoint 2013 August 2015 CU. One of the security fixes in this cumulative update package has a bug: https://support.microsoft.com/en-us/kb/3085501. Because this is a security fix most companies will push this fix to their servers.

The bug pops up when you try to attach a file to a list item or a calendar item. Here’s how the error message will look like…

Message from webpage
===================================================
File names can’t contain the following characters: &”?<>#{}%~/\
===================================================
<<Ok>>

Attaching a file to a list item is a feature that is rarely used so I guess customer’s affected will be just a minority. Microsoft is planning to fix this issue in October CU.

Workaround

There are some workarounds listed in below blog link. Please make sure you back up the JavaScript files before modifying it.
http://thesharepointfarm.com/2015/08/august-2015-cu-error-file-names-cant-contain-the-following-characters/

Another workaround is to do the following…

  1. Create the list item without adding any attachments
  2. Go back to the list and select the list item you created in item 1.
  3. Ribbon->Items->Attach File and provide the attachment.

This will work for list items, but I’m not sure if this will work for calendar items.

Aug 142015
 

In this post we’ll be discussing on how to manipulate strings using PowerShell. PowerShell comes with the following string manipulation operators…

  • split – case sensitive split
  • isplit – case insensitive split
  • csplit – case sensitive split
  • join – joins an array into one string
  • replace – case sensitive split
  • ireplace – case insensitive split
  • creplace – case sensitive split
Split Demo Using Split Function Call
#store comma delimited wild animals list into a string
$wildanimals = "Tiger,Lion,Elephant,Bear,Fox,Jackal,Hyena"
#split the string using Split function based on ","
$wildanimals.Split(",")
Output
========
Tiger
Lion
Elephant
Bear
Fox
Jackal
Hyena
Split Demo Using -Split Operator
#split array using -split operator
$wildanimals -split ","
Output
========
Tiger
Lion
Elephant
Bear
Fox
Jackal
Hyena
#split into three strings, this will leave the third string unsplit
$wildanimals -split ",", 3
Output
========
Tiger
Lion
Elephant,Bear,Fox,Jackal,Hyena
#replace all "," with " "
$wildanimals = ($wildanimals -replace ",", " ")
#alternate syntax, with no split criteria the default is to use " " as split criteria
-split $wildanimals
#restore "," back instead of " "
$wildanimals = ($wildanimals -replace " ", ",")
Join Demo
#store into an array
$wildanimalsarray = $wildanimals -split ","
#join operator takes an array and makes it a string, each element separated by ","
$wildanimalsarray -join ","
Output
========
Tiger,Lion,Elephant,Bear,Fox,Jackal,Hyena
Replace Demo
#replace all instances of Elephant with Zebra
$wildanimals -replace "Elephant","Zebra"
Output
========
Tiger,Lion,Zebra,Bear,Fox,Jackal,Hyena
Conclusion

The case sensitive and insensitive operators are similar in usage except they are sensitive/insensitive to case. Hope this helps you.

Jul 232015
 
Very important:

Please make sure necessary backups are in place before you perform this operation. First test in your dev/test environment and only then use in your production environment.

Ideally a feature will be scoped to a Farm, WebApplication, Site, or Web, but orphaned features won’t be having a scope. The command to list all orphaned features in a SharePoint farm is as follows…

PowerShell command to list all orphaned features…
Get-SPFeature | ? { $_.Scope -eq $null }
Sample output…
PS C:\windows\system32> Get-SPFeature | ? { $_.Scope -eq $null }

DisplayName                    Id                                       CompatibilityLevel   Scope                         
-----------                    --                                       ------------------   -----                         
ReportServerCentralAdmin       5f2e3537-91b5-4341-86ff-90c6a2f99aae     14                                                 
ReportServerStapling           6bcbccc3-ff47-47d3-9468-572bf2ab9657     14                                                 
PowerView                      bf8b58f5-ebae-4a70-9848-622beaaf2043     14                                                 
ReportServerCentralAdmin       5f2e3537-91b5-4341-86ff-90c6a2f99aae     15                                                 
ReportServerStapling           6bcbccc3-ff47-47d3-9468-572bf2ab9657     15                                                 
PowerView                      bf8b58f5-ebae-4a70-9848-622beaaf2043     15
PowerShell command to delete an orphaned feature…
foreach($f in @(Get-SPFeature | ? { $_.DisplayName -eq "ReportServerCentralAdmin" }))
{
    $f.Delete()
}

Why did we need a foreach? Because a feature could be listed twice with different “CompatibilityLevel” values. So in this case “ReportServerCentralAdmin” is listed twice with “CompatibilityLevel” set to 14 and 15. So we delete both via $f.Delete().

Jul 222015
 

Introduction

Get-SPFeature is a command used to list out all the features in a SharePoint farm (scope can be set). You can scope this command to different levels, the levels are…

  • Farm – Only SharePoint farm level features are displayed
  • Web Application – Only web application level features are displayed
  • Site – Only site level features are displayed
  • Web – For sub sites

Examples…

#Display all SharePoint farm features
Get-SPFeature –Limit All
Scoping features…
#Display all SharePoint features scoped to farm
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "FARM"}

#Display all SharePoint features scoped to web application
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "webapplication"}

#Display all SharePoint features scoped to site
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "site"}

#Display all SharePoint features scoped to web
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "web"}
List all features in a Site Collection…

#Displays all SharePoint features for a site collection using Grid view

Get-SPSite http://mysiteurl | Get-SPWeb -Limit ALL |%{ Get-SPFeature -Web $_ } | Out-GridView –Title “All features for this site”

Sample Grid Output…
All Features in a Sharepoint Site Collection

Help…

#For detailed help type in… Get-Help Get-SPFeature –Full

May 012015
 

Here are some sample PowerShell commands to manipulate XML contents in memory and then later dump them to an XML file. I’ve added comments inline to explain a line of PowerShell command.

#Clear output
cls

#Sample XML content
$xml = @'
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book genre="novel" style="hardcover">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" style="other">
<title>The Poisonwood Bible</title>
<author>
<first-name>Barbara</first-name>
<last-name>Kingsolver</last-name>
</author>
<price>11.99</price>
</book>
<book genre="novel" style="paperback">
<title>The Bean Trees</title>
<author>
<first-name>Barbara</first-name>
<last-name>Kingsolver</last-name>
</author>
<price>5.99</price>
</book>
</bookstore>
'@

# Dump XML to output window
$xml.InnerXml

#Get all attributes named "genre" from above XML
$nodes = $xml.SelectNodes("//@genre")
$nodes.Count 
#Output: 3

#Get first book in the XML
$firstbook = $xml.SelectSingleNode("/bookstore/book[1]")
$firstbook.InnerXml 
#Output: <title>The Handmaid's Tale</title><author><first-name>Margaret</first-name><last-name>Atwood</last-name></author><price>19.95</price>

# Using Select-Xml: Get last book in the XML
$selxml = Select-Xml -Xml $xml -XPath "/bookstore/book[last()]"
$selxml.ToString() 
#Output: <title>The Bean Trees</title><author><first-name>Barbara</first-name><last-name>Kingsolver</last-name></author><price>5.99</price>

# Filter out nodes based on conditions, dump titles of books whose price is greater than 11
$xml.SelectNodes("/bookstore/book[price>11]/title") | Format-Table
#Output: #text 
 # ----- 
 #The Handmaid's Tale 
 #The Poisonwood Bible
 
# Modify XML value of a node, change price
$xml.SelectSingleNode("/bookstore/book[price<11]/price") #Old price
$xml.SelectSingleNode("/bookstore/book[price<11]/price").InnerText = 10 #New Price
$xml.SelectSingleNode("/bookstore/book[price<11]/price") #Print new price
#Output: #text 
 #----- 
 #5.99 
 #10

#Save XML
$xml.Save("$env:userprofile\\desktop\\testxml.xml")
Nov 252014
 

What’s ResourceDigger?

Wrote a utility (long back) for displaying resources from binary files, recently did some modifications as well. We know visual studio does provide a similar functionality but this one’s better with respect to viewing resources. You can view as many resource files as you like (haven’t put a limit). You can drag and drop folders or binaries into the application to get them loaded. Loads up any binary as long LoadLibrary succeeds. Quite useful for a quick view of resources in a binary file, will add editing of resources in the next version of this tool. Hope this helps.

Here is a screenshot of how the tool looks…

ResourceDigger: Application Screenshot

How to use ResourceDigger

Easy to use. Just drag and drop a folder or a bunch of executables. Or…
To load an executable press Ctrl + L or Load Exe toolbar button

ResourceDigger: Load Executable

To load a folder press Ctrl +D, or Scan Folder toolbar button. Select “Load Sub Directories” if you want to recurse into sub-directories.

ResourceDigger: Load a folder of resources

What features are supported in ResourceDigger

Some of the features supported by the application…

  • Viewing animated gifs, normal gifs, pngs, jpegs, bmps, HTML files, manifest files.
  • Display group icons, cursors with detailed description of each of them… See screenshot…
    ResourceDigger: Icon Group Display
  • Friendly display of accelerator table, a good way to know all the shortcuts provided by an application…
    ResourceDigger: Accelerator Resource
  • Friendly display of string table…
    ResourceDigger: String table resource
  • Displays resources in all available languages
    ResourceDigger: Multi Languages Resource
    ResourceDigger: Multi Language Dialog Resource
  • Animated view of AVI file. With a toolbar to control frames in the AVI file.
    ResourceDigger: Version Resource
  • Version display… (there are few issues, I’m working on them)
    image
  • Clear view of registry resources…
    ResourceDigger: Registry Resource
  • Toolbar resource view…
    ResourceDigger: Toolbar Resource
  • Menu resource display…
    ResourceDigger: Menu Resource
  • Hex display of custom resources…
    ResourceDigger: Hex display of unknown resources

Known Issues

  • Hangs up if you give a folder with a humungous list of binaries.
  • This is not multithreaded so just be patient until resources finish loading.

Tips

Press ‘*’ on a particular node to expand all its child nodes.

Download Link (rename from .Jpg to .exe)

Do let me know your suggestions…

Nov 212014
 

TextAnalysisTool.Net to analyze large log files

This tool is written by . Recently bumped into this tool during an internal presentation and since the tool is available for public download I thought I’ll share this with my audience as well. I think this is pretty handy to analyze large log files like MSBuild logs, other traces etc.

Animated Screenshot

TextAnalysisTool.NET Demonstration

Download Link

David’s blog
Direct download

Nov 192014
 

Introduction

I’m writing this post to tell my readers that MFC support for MBCS is now deprecated. I’ve been reading several posts and internal emails within Microsoft. For customer’s who are deep rooted into MBCS, please wake up, start removing this piece from your codebase (so easy to say).

MFC support for MBCS is now Deprecated

MFC support for MBCS is now deprecated in Visual Studio 2013 and Visual Studio 2015. So eventually MBCS will be removed from the product entirely but (could be, maybe) could remain as a separate download. The term deprecation means gradually this thing will be removed. We normally start with warnings and then eventually we remove it. So now in 2013 is you build a project with MBCS support note that you’ll start to see a warning saying MFC support for MBCS is deprecated, time to move on. You can of course, as always, disable this warning using #define NO_WARN_MBCS_MFC_DEPRECATION.

Reasons why MFC support for MBCS is Deprecated

After reading blogs and comments the reasons that I could gather are as follows…

  • Research by Microsoft has shown that usage of MBCS by customer’s has significantly gone down.
  • Unicode is already popular and it can represent almost every language.
  • Native Windows API’s has been supporting Unicode interface for a long time now hence MFC will now be more aligned with the SDK as well, gets rid of the performance hits customer’s run into while using non-Unicode API’s. These API’s will eventually convert non-Unicode parameters to Unicode and then call corresponding Unicode version of this API, for e.g. GetWindowTextA will eventually call GetWindowTextW to get a window’s text.
  • Faster downloads. Reduced size of MFC libraries since these days Visual Studio is downloaded instead of being written onto a disk. MBCS libraries are now available as a separate download package. The size of the package is showing up as 64.3 MB. Doesn’t sound that huge though!

Why Would Somebody Still Require MFC Support for MBCS?

Few reasons that I could think off are as follows…

  1. Large codebase.
  2. Huge cost on testing code changes as the changes will be significant and impact will be huge as well. The benefits of this change to end customer is pretty trivial though.
    1. For him the application worked then and it will continue working.
    2. End customer will also might have do some heavy testing if they’re dependent on a library which removed MBCS support. So library vendors will have a pain there as well.
    3. Government customers will be affected as well as they have their own code validation process before accepting an application from a vendor.
  3. Reading in old data files or data from databases (?).
  4. Customer’s who have portable code cannot convert to UTF-16 just like that. They might have to eventually rewrite something just for Windows. Surprised smile

Workaround?

  • MBCS as of now will come as a separate download. See below screenshot…
    VS2015 download link
    MFC support for MBCS
  • Do not move to a newer version of Visual Studio which doesn’t support MBCS, that’s what I would do if I’m worried about about MBCS eventually not being supported by an IDE version.
  • Raise your voice, let it be heard.

References

MFC support for MBCS deprecated in Visual Studio 2013
Download Visual Studio 2015

Nov 052014
 

What’s a Command Prompt?

This is the line of text prefixed automatically by the environment to the command you’re writing for an e.g. see below screenshot…

Customizing Command Prompt

How Can I Customize The Command Prompt?

Microsoft provides a built in command named as Prompt. As the name suggests this just help customize the prompt text shown in a command window. See the help for this command…

c:\Windows\System32>prompt /?
Changes the cmd.exe command prompt.

PROMPT text

text    Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

$A   & (Ampersand)
$B   | (pipe)
$C   ( (Left parenthesis)
$D   Current date
$E   Escape code (ASCII code 27)
$F   ) (Right parenthesis)
$G   > (greater-than sign)
$H   Backspace (erases previous character)
$L   < (less-than sign)
$N   Current drive
$P   Current drive and path
$Q   = (equal sign)
$S     (space)
$T   Current time
$V   Windows version number
$_   Carriage return and linefeed
$$   $ (dollar sign)

If Command Extensions are enabled the PROMPT command supports
the following additional formatting characters:

$+   zero or more plus sign (+) characters depending upon the
depth of the PUSHD directory stack, one character for each
level pushed.

$M   Displays the remote name associated with the current drive
letter or the empty string if current drive is not a network
drive.

Some Killer Sample Prompt Commands and Their Output

Please refer above help to figure what every character after the $ mean…

  • Command: prompt ——$G$P$G
    • New Prompt: ——>c:\Windows\System32>
  • Command: c:\Windows\System32>prompt $V$G$P$G
    • New Prompt: Microsoft Windows [Version 6.3.9600]>c:\Windows\System32>
  • Command: c:\Windows\System32>|>prompt $P$G$B$+$G
    • New Prompt: c:\Windows\System32>|>.
      The above prompt adds a ‘+’ sign for every pushd you do and removes the last ‘+’ after a popd. See below…
  • c:\Windows\System32>|>pushd c:\
    c:\>|+>pushd e:\
    e:\>|++>popd
    c:\>|+>popd
    c:\Windows\System32>|>
  • Funky Command:  prompt ╔═════════════════════╗$_║$P:$G$+║$_╚═════════════════════╝$_
    • New Prompt:
      ╔═════════════════════╗
      ║c:\Windows\System32:>║
      ╚═════════════════════╝

This just shows that you can customize the prompt to some extent. Above prompt will be ok if the current directory path is a small one but once it gets bigger you’ll have to adjust the square…

How to Make the Command Prompt Permanent?

Your custom command prompt will stick only for this session of cmd. If you start another instance of a cmd.exe you’ll end up seeing the default value or the one that’s setup elsewhere (as shown below).

So the question is how do we setup a command prompt that stays across sessions? Via the environment variable PROMPT. See below for my case…

Permanently Customizing Command Prompt

My personal favorite prompt is the one set by following command…

PROMPT $P$G$_$$$G

To set this as your prompt you can add an environment variable called PROMPT. Open environment variable window and then add the value as shown below…

Permanently Customizing Command Prompt

So now if you open a cmd instance you should see the following prompt…

Permanently Customizing Command Prompt

How do I revert my changes to the Command Prompt?

Valid question. To revert back to the original prompt, just type in command PROMPT without any arguments. You should see the prompt revert back to default. You might also want to remove the environment variable PROMPT else for next session you’ll again see the prompt you’ve setup.

Oct 292014
 

What’s Z7 and Zi?

These are compiler switches which tells the compiler where to dump debugging information collected from a C/C++ source file during compilation. Z7 tells the compiler to dump debugging information into a .obj file. Zi tells the compiler to dumps debugging information into an intermediate .pdb file.

What’s the Difference between Z7 and Zi?

Regarding Z7…

This option produces a .obj file containing full symbolic debugging information for every C/C++ source compiled for use with the linker. The symbolic debugging information includes the names and types of variables, as well as functions and line numbers. .Obj files get bigger in size because of the debugging information dumped in by the compiler into this file and then bloats your disk. /Z7 is based on the old code view format. This option introduces additional burden on the linker to parse every .obj file for debugging information. These .obj files will then be collated into a one .pdb file which will normally be named after the executable file name during linking phase.

Advantages of using Z7 switch
  • Good thing here is that there is no contention to write to one file (as you’ll see below).
  • Every .cpp file will have its own debugging information which will eventually be collated by the linker.
Disadvantages of using Z7 switch
  • Downside being the time taken to link, size of files on disk and old format.
  • Minimal rebuild feature (/Gm) will not work if /Z7 is enabled. You’ll get following warning…
    Command line warning D9007: ‘/Gm’ requires ‘/Zi or /ZI’; option ignored
  • The biggest disadvantage of Z7 is that this format doesn’t allow Edit and Continue, well this matters if you use this feature at all?
During Debugging what’s the effect of Z7 switch?

When debugging the debugger will tell us from where it has loaded a pdb file for a binary that its debugging. It loads the pdb file generated by the Linker which is unaffected by either /Zi or /Z7. Please see highlighted path of .pdb file from the debugger. So yes linker generates .pdb file which is the final .pdb file.

ConsoleApplication4.exe .\ConsoleApplication4.exe Symbols loaded. .\ConsoleApplication4.pdb 00E50000-00E70000 [5476] ConsoleApplication4.exe: Native

Demo

With /Z7 enabled you’ll see following list of files in your intermediate folder, note the size of .obj files…

10/23/2014  06:07 PM               136 ConsoleApplication4.res
10/23/2014  06:07 PM               348 ConsoleApplication4.log
10/23/2014  06:07 PM             2,473 ConsoleApplication4.Build.CppClean.log
10/23/2014  06:07 PM           117,615 ConsoleApplication4.obj
10/23/2014  06:07 PM         4,920,987 stdafx.obj
10/23/2014  06:07 PM        36,175,872 ConsoleApplication4.pch

Please compare above size of .obj files with below output files generated when /Zi is enabled.

Regarding Zi…

The compiler writes debugging information to one centralized file. The compiler names the program database named VCx0.pdb (or what you’ve configured it to be named), where x is the major version of Visual C++ in use.

Advantages of using Zi
    • When you use this option, your .obj files will be smaller, because debugging information is stored in the .pdb file rather than in .obj files.
    • Easy on the linker. It just has one file to parse to figure out debugging information for a binary that’s linking up.
    • Duplicate debugging information doesn’t make into the .pdb file generated by the compiler since its now working on one .pdb file instead of multiple .obj files where it doesn’t maintain a list of symbols generated to figure out duplicate ones.
    • Minimal Rebuild (/Gm) will work only work with /Zi or /ZI.
    • Advanced debugging features like Edit and Continue (/ZI) will work (making code changes when debugging, the changes are then built and we continue debugging again without stopping the debugging session). Sample effect on the debugger when a code change is done when debugging with Edit and Continue enabled…

clip_image002

——– Edit and Continue build started ——–

——————— Done ———————-

Disadvantages of using Zi
  • High contention to write to the one .pdb file as we’ve parallel builds running. Some machines will have several parallel builds configured.
Demo

With Zi enabled you’ll see following list of files generated. Take a note of sizes for the .obj files. Note that now we’ve got a

10/23/2014  06:00 PM               136 ConsoleApplication4.res
10/23/2014  06:00 PM               192 ConsoleApplication4.log
10/23/2014  06:00 PM             2,473 ConsoleApplication4.Build.CppClean.log
10/23/2014  06:00 PM           103,106 ConsoleApplication4.obj
10/23/2014  06:00 PM           933,490 stdafx.obj
10/23/2014  06:00 PM         1,551,360 vc120.idb
10/23/2014  06:00 PM         4,239,360 vc120.pdb <<<-- This is the pdb that the compiler generates, which contains debugging information from all the cpp files (path is generated using following pattern: $(IntDir)vc$(PlatformToolsetVersion).pdb). Now .obj files will not have debugging information. Compare their sizes with earlier output.
10/23/2014  06:00 PM        36,896,768 ConsoleApplication4.pch

When debugging the debugger tells exactly from where a pdb file is loaded. It loads the pdb file generated by the Linker which is unaffected by either /Zi or /Z7. Please see highlighted path of .pdb file from the debugger. So yes linker generates .pdb file which is the final .pdb file.

ConsoleApplication4.exe .\ConsoleApplication4.exe  Symbols loaded. .\ConsoleApplication4.pdb [4660] ConsoleApplication4.exe: Native

What’s the effect of these options when debugging in Visual Studio or a crash dump?

As far as debugging is concerned there is zero effect as the linker will eventually generate one final pdb file which is controlled by the linker switch: /DEBUG.

clip_image003

The compiler only generates an ‘intermediate’ .pdb file which contains debugging information collected during compilation which the linker will then eventually dump to a ‘final’ .pdb file. So all that you should be worried is the final .pdb file generated by the linker. This .pdb file is placed alongside the executable. This is the .pdb file that will be used when debugging the application or crash dumps.

So you might ask what if we disable .pdb generation in the compiler settings? Well then your code breakpoints will not hit. The breakpoints will be disabled since the linker couldn’t figure symbols for your code as the compiler didn’t generate any!

Please let me know if you have further questions?