Convert ‘\\’ to ‘\’ in c#


This post would sound pretty weird to any c# developer. However, a situation i had been in last week forced me to bring this into notice.

I had an XML file in which i had node values like ‘Requirements Management\XYZ’. I read the XML using XLinq and the c# string looked like ‘Requirements Management\\XYZ’. At first i felt its fine, as C# compiler added that extra backslash to handle an escape sequence. But when i tried using this value (stored in a variable), it was always returning me the string with ‘\\’. 😛

After 4 hours of trial and error, i found the solution. Believe it or not, i tried the extreme of exploiting the ‘Split’ and ‘Replace’ methods string gives me. 😛

Solution:

Whenever you need to assign this variable to some object property, in my case Area Path and Iteration Path for my TFS 2010 SDK API, you just need to make use of the powerful ‘@’ operator & String.Format method

string strXyz = Xdoc..Load(“myXML.xml”).Element(“abc”).Value; //This returned ‘Requirements Management\\XYZ’

Now to use this:

Obj.XYZ = String.Format(@”{0}”,strXyz); //The string value assigned to my ‘Obj’ object will be ‘Requirements Management\XYZ’.

It doesn’t make much sense, but this will handle the conversion of the double slashes to slash conversion.

But if you are using strings all the way, there’s nothing to worry, C# compiler will handle such situations. For instance displaying it on a textbox or some label or something.

Ideally you cannot convert double slashes to single slashes.. 🙂

SSRS Export to PDF breaking the columns in larger reports


This is a wierd problem, one could face in SSRS. The export to PDF or Word, appears to break the columns in larger reports with 10 or more columns.

The main reason being the report size specifications.

You can check your report properties to find the report size specifications. Check the screenshot below:

Check the Width and Height properties of the dialog that pops up (Right-click on the Report -> Report Properties)

The Fix:

Find the width of your report tablix (in inches). This will be a good start. Do not worry about height now. Set the Width to the width property in the above dialog, from your calculation. This is indeed a trial and error process, until you get all the columns in one single page. You will also need to adjust the Margins accordingly.

This should solve the issue of columns being spilled over to the next page, while taking export to PDF or Word.

New Problem that can come up:

In the first page of the exported report, you see only one row in the tablix.

Fix:

Adjust the margins to a lower value, less that 0.5in. They can be real culprits in this case.

Hope this helps with your SSRS issue.

jQuery noConflict Tips


Some tips which i feel you need to know before using jQuery library:

1. You can use jQuery instead of $.

2. Predefined alias for jQuery: you can assign jQuery to any variable. With this you can load any versions of jQuery into your site.

<!– load jQuery 1.1.3 –>
<script type=”text/javascript” src=”http://code.jquery.com/jquery-1.1.3.js”></script>
<script type=”text/javascript” src=”jquery.dimensions.min.js”></script>

<!– revert global jQuery and $ variables and store jQuery in a new variable –>
<script type=”text/javascript”>
var jQuery_1_1_3 = $.noConflict(true);
</script>

<!– load jQuery 1.3.2 –>
<script type=”text/javascript” src=”http://code.jquery.com/jquery-1.3.2.js”></script>

<!– revert global jQuery and $ variables and store jQuery in a new variable –>
<script type=”text/javascript”>
var jQuery_1_3_2 = $.noConflict(true);
</script>

3. To use the $ variable even when an alias is mentioned
 Syntax:  (function($){//$ Code goes here})(jQuery_1_3_2);

(function($) {
 $(‘<button>Use jQuery 1.1.3</button>’)
  .click(function() {
   alert(‘Top: ‘ + $(this).offset().top + ‘\n’ +
    ‘jQuery: ‘ + $.fn.jquery);
  })
  .appendTo(‘body’);
})(jQuery_1_1_3);

4. Always ensure that jQuery’s noConflict method is called above any other javascript libraries. Or else the noConflict will be of no use and gives errors.

5. Finally to check if jQuery is defined:

 if(typeof (jQuery) == “undefined”) {//jQuery undefined} else {//jQuery defined}