Tuesday, October 19, 2010

Print specific ASP.Net control from a Web Page

I ran into a requirement, where i had to print only asp.net grid. And this had to work on all browsers. I had similar requirement to print a SSRS report on non IE browser.
So, I came up with this solution(rather, i would call it as workaround). Approach is to select the inner html of the control and print only this area. To do so, i am selecting the inner html  from the control and setting it as a HTML source of an IFRAME which is of size 0x0 and printing it immediately.
Following is the Javascript from the aspx page to this. I have taken reportviewer control for now.








If you are using this for reportviewer, just keep in mind that you are only printing the current page instead of all the visible pages.



I still need to work on getting the styles from the parent page and applying it on the IFRAME so that we dont miss any style information.

Friday, October 15, 2010

Error:Microsoft.ReportingServices.Diagnostics.Utilities.SecureConnectionRequiredException: The operation you are attempting requires a secure connection (HTTPS)

I had this problem from long time and was in such a urgency that i started working with HTTPS. But finally i had to move my machine out of the domain, and left with only option of fixing it.

First step i did was went to “C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\LogFiles”, which you have already figured out i guess. At the latest log file, you will see this error listed. Which means that RS is configured only for HTTPS and not for HTTP.

To resolve… lets change it.

For not using SSL you need to modify following section in reportserver.config file, at C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer and change

<Add Key="SecureConnectionLevel" Value="2"/>




entry with value from 2 to “0”

Monday, July 5, 2010

How to change Win 7 logon screen

Windows 7 OS enables OEMs to set their own Log-on screen. So if you want to customize yours, you can make use of this registry setting.

  • First you need to enable the custom wallpaper flag in registry. To do so, navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background

image 

  • Now set the DWORD value OEMackground to 1, by default it will be 0.
  • Now you have enabled the custom background feature, to select the defaultbackground navigate to c:\Windows\System32\oobe\
  • Create a new folder here called info then one more inside called backgrounds
  • Copy a JPG file to this folder now and  call it backgroundDefault.JPG. Final structure should look something like this…
  • image 

Win + L, now you see it!!!

Friday, June 25, 2010

Why live writer is better than MS Word for blogs

Well this is the first article, as well as the test article for using Windows Live Writer for blogger. At first glance I found following advantages

  • Its WYSIWYG – Yeah, it uses your blog theme, CSS, font… everything
  • You have a preview and option to edit the source code
  • Finally a neat HTML, doesn’t crap like Word does
  • Support for publish scheduling
  • Easy way to publish photos – still testing… Smile ( tested, working fine)

image

  • Loads faster and doesn’t have many unwanted options.
  • easy to load previous entries and edit
  • Easy to label articles

Anyway I strongly recommend downloading and using Windows Live Essentials

Monday, June 21, 2010

Hosting Silverlight Application on Facebook

Objective is to create a game using Silverlight which will utilize Facebook platform and publish on facebook application directory. Following are the features which we will target to deliver
  1. You can compare your score with friends
  2. You can invite your friends on Facebook
  3. You can post your score and events like beating a friend on to your wall
  4. List top 100 scores
  5. List your friends top score along with their profile pictures
In simple words, we are going to walk through the creation of ittiGator Game on Facebook. Take a break now, have a good look at it and come back. Here you go… http://apps.facebook.com/ittigator
Creating game using Silverlight
I will not go into details, its left to your creativity and coding to create a working model. Make sure you make it modular, and lets make a module called ScoreCard and place a control called ScoreCardControl. Here we will list out 6 users including the player , ordered by scores. What you would need from Facebook will be friends list, and friend’s photo. Scores we will be maintained in our SQL Server DBs

To be continued...

Saturday, June 12, 2010

Displaying FBJS dialog on top of Plug-in content

You cannot display any HTML Content on top of a plugin content. This is because of different window message loops running for browser and the plugin content. If you are working with Silverlight there is an option to specify to Silverlight to use browser windows message loops for paint messages. Set windowless=true to make use of this.

However this is not recommended as it will drastically slowdown your Silverlight application. Well, there is no point in using a slow Silverlight application.

If you have realized the limitations by now, lets work on the workaround. I have an application called ittiGator( a facebook game http://apps.facebook.com/ittigator ) where we are prompting with a publish dialog on completing the game.


What we will do is, we will create two DIVs sitting one top of other. We will host our Silverlight in one and publish button in other.
DIV – Publish button with some background.
DIV – Silverlight Content

Do you want to share your High Score with your friends?
We will call a JavaScript method called publish from Silverlight using
HtmlPage.Window.Invoke("publishScore", new string[] { UserScore.Text, UserName.Text });
In this publishscore method we will increase the height of ShowCase div to amount that is enough to push the plugin content just below the visible screen area.

function publishscore (score, usrname) 
{
document.getElementById("Showcase").style.height = '800px';
}
Reset the height on the publish dialog call back function
FB.Connect.streamPublish('', g_attachment, g_action_links, null, 'Post your high score and let the world follow you!', stream_callback_resizetheDiv);

This should work if you work with flash based application or even if you have an activex control embedded.

Leave a comment if you need any assistance in implementing this.

Thursday, June 10, 2010

Publishing your Product/Corporate website

If you are a startup and don’t want to spend much time in getting your website out, here we have a solution.

http://www.drupalgardens.com/ can get your website ready in 15 mins!!! To be practical, you can have your full blown website ready in a day. If you say that you have other providers who can do this, believe me they can’t. I strongly recommend you to run through the video and think again. I tried their beta and I am a fan of Drupal garden now!




What it is?

It’s a Drupal based hosting, with a great pluggin added for customization. With this admin plug-in you can

1) Chose templates
2) Chose themes
3) Chose color schemes( this is too good)
4) See workflows
5) Provide your custom CSS etc



Even though they are prized lil high, I think its worth if you are a start-up and focus on your product than the overheads.

Tuesday, May 18, 2010

Dealing with browser repaints

Recently i wanted to hide a silverlight plugin content and display some html content in its place. As you might be knowing, plug-in content redrawing is a known problem all the time. So i decided to put both the contents in a table row and dynamically set the row height.



document.getElementById("Showcase").style.height = '0px';
               and
document.getElementById("Showcase").style.height = '500px';

Problem later i found that it works fine with IE, FF, Chrome but in opera its a problem. It requires you to scroll once for redrawing the content.  So you will still see the flash/Silverlight content and the new html content, untill you scroll.

This has been discussed in couple of places, but could not find any solution. So, i decided to put a scroll automatically. I tried scrolling it with 1 px, it worked!!! So i tried with 0px.... and ... it worked too!!!!

window.scroll(0, 0);
Try and let me know if it fixes your repain problem too...

Wednesday, March 24, 2010

Listing all the websites installed

Following Managed C++ code enumerates all the Websites. Useful if you are writing some kind of installer.

This requires IIS6 Metabase pack installed on IIS 7.X. Refer my other article for IIS 7 based installers.

For now...

System::String* entryName = System::String::Format(S"IIS://{0}/w3svc", computerName);
System::Text::StringBuilder* sb = new System::Text::StringBuilder(512);
System::DirectoryServices::DirectoryEntry* rootEntry = NULL;
System::DirectoryServices::DirectoryEntry* childEntry = NULL;
try
{
rootEntry = new System::DirectoryServices::DirectoryEntry(entryName);
rootEntry->RefreshCache();
System::Collections::IEnumerator* iterator = rootEntry->Children->GetEnumerator();
while(iterator->MoveNext())
{
childEntry = dynamic_cast(iterator->Current);
if(!childEntry->Name->Equals( S"AppPools", System::StringComparison::CurrentCultureIgnoreCase ))
{
if(!childEntry->Name->Equals(S"Filters", System::StringComparison::CurrentCultureIgnoreCase))
{
if(!childEntry->Name->Equals(S"Info", System::StringComparison::CurrentCultureIgnoreCase))
{
//Print childEntry->Name;
}
}
}
}
}

Friday, January 15, 2010

Deadlock!!! ..and getting out of it.

Its easy to create deadlocks in SQL, just one slip in your code and lot of load on your script makes the ideal condition for deadlock to occur.
Microsoft believes you, have lot of faith in you. So it offers tools to resolve and rescue from your coding disaster.

Say you have a deadlock, show it. Find how you can reproduce this, unless you know how to reproduce it, you will never be sure of your fix; well, like always.

First thing to do once you see a deadlock is, extract the deadlock trace data. To do so, you can set flags in SQL by running following command
dbcc traceon (1204, 3605, 1222, -1)
This flag is set only for current session of SQL server, if you restart the SQL you need to redo it. You can also set this flag as startup parameter by adding –T1222 in SQL server properties dialog.
When deadlock occurs, you can see the DB log to contain the most of the information. I have found graph drawn by the profiler as more useful than the log.

This graph you can view in profiler and you can store as XML. This XML has all the information that can give you a lead. XDL – ie XML representation of Deadlock graph has information like
1) Procedures involved
2) Line number involved in deadlock
3) Script line involved
4) Data involved
5) Victim thread, SQL terminates one process to break the deadlock
6) Mode of lock on the resource
Most of the cases this information would be sufficient to get you out of it.

Common solutions:
1) Consider rearranging the script so that you isolate all different operations like select, delete, insert and update. Make sure you have same pattern in both the scripts who are involved in deadlock. Say delete first, select next then you do a insert in both the stored procedures.
2) Un-clustered indexes adds overhead of updating indexes which require exclusive locks and if select is also running on table, then there is a possibility of deadlock. Making the clustered index can resolve the problem.
3) Run the Query analyzer and see the execution graph. You can see the pattern of two scripts running and see the overlap. This could give you fair idea on what could be going wrong, or gives the idea on possibilities.

Now you are on your own…
Posted by Picasa