Would like to provide take snapshot of URL/Page in your ASP.NET application?

Challenge:

Few days back, my colleague asked me that how he can have functionality using which user can take snapshot of provided URL in his ASP.NET Application.

Solution:

I did also not know, but found the requirement very interesting. So. As usual had a chat with my best friend Google and found one nice tool named as IECapt.
I am not going to write how to use it, because someone has already done that. You can read it from here:
http://www.enestaylan.com/eng/post/2010/01/05/Taking-Snapshot-in-ASPNET.aspx
IECAPT Home Page: http://iecapt.sourceforge.net/
Just a note: IECapt# dll is also available. But it is not working with ASP.NET application. So, recommended way is to use IECapt.exe only!
Happy Sharpshooting! 🙂

Session values lost when any exception occurs

Challenge

If you’ve stored some values in session and your session values getting lost when any exception occurs. Then this article may provide you hint to solve it.

Solution

In my case the reason was as below:
Basically I was creating a directory under my web root directory and when any exception occurred I was deleting that directory. And that was the main reason for losing my session values.
So, Now I am creating/deleting directory outside my web root directory and problem is solved!
And deepest reason is Application Restart – Whenever any directory gets created/deleted under web root ASP.NET restarts the application pool. To read more about ASP.NET Application restart read my blog post.
Happy Coding! 🙂

directory

 

Could not load type 'System.Web.UI.ScriptReferenceBase' from assembly 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Challenge

If you are getting following error:
Could not load type ‘System.Web.UI.ScriptReferenceBase’ from assembly ‘System.Web.Extensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35′.
Then you are on the right article

Solution

It’s highly likely that you compiled your code using .NET 3.5 Service Pack 1 but deployed to a system that has .NET 3.5 without Service Pack 1.
ScriptReferenceBase is a new class for Service Pack 1, clearly a refactoring of ScriptReference to allow common code for the new CompositeScriptReference class. If you compile your code using SP1, you will include a reference to this class, which does not exist in .NET 3.5 pre-SP1. When the non-SP1 runtime tries to load the class, you will receive the exception above.
Solutions are:

  • Compile using .NET 3.5 without SP1.

OR

  • Install SP1 on the target system

 

Create PerfMon WebPage

Challenge

If you’ve used PerfMon – tool from microsoft for performance monitor. [if you haven’t then it is really good to use tool for monitoring your application’s performance once It is deployed on server. Try it today!].
While monitoring performance we need to run perfmon tool [START | RUN | perfmon]. But what if admins need to view it from web browser and it can be from anywhere.

Solution

Here’s the solution for that. We can configure perfmon to run inside a webpage [But you need IE!].
Step by step guide is here: http://www.myitforum.com/inc/arts/9435MMC%20to%20webpage.doc
Reference : http://www.myitforum.com/articles/15/view.asp?id=7407
Happy Performance Monitoring! 🙂

Merging two XML files in to one dataset

Challenge:

Since so long back one of my best buddy Devang asked me that how can we merge two Datasets in one. In short, suppose you’ve two XML Files and you want to read them in different dataset. So, obviously they both will belong to two different data sets. But you would like to have both of them in a single dataset. How can you do it?
Before you see the solution code. Let’s see the problem by code
[sourcecode language=”csharp”]
private const string FILE1_PATH = "~/Books1.xml";
private const string FILE2_PATH = "~/Books2.xml";
protected void Page_Load(object sender, EventArgs e)
{
// Read First Xml
DataSet dataSet1 = new DataSet();
dataSet1.ReadXml(Server.MapPath(FILE1_PATH));
// Read Second Xml
DataSet dataSet2 = new DataSet();
dataSet2.ReadXml(Server.MapPath(FILE2_PATH));
// Merge — Will not work
dataSet1.Merge(dataSet2);
// Read in Table — Will not work
dataSet1.Tables[0].ReadXml(Server.MapPath((FILE1_PATH)));
dataSet2.Tables[0].ReadXml(Server.MapPath((FILE2_PATH)));
// Merge DataSet2.Table in first dataset — WILL NOT WORK — DataTable already belongs to another DataSet.
dataSet1.Tables.Add(dataSet2.Tables[0]);
}
[/sourcecode]

Solution

When we try to use following line.
[sourcecode language=”csharp”]
// Merge DataSet2.Table in first dataset — WILL NOT WORK — DataTable already belongs to another DataSet.
dataSet1.Tables.Add(dataSet2.Tables[0]);
[/sourcecode]
It will throw following error:
DataTable already belongs to another DataSet.
System.ArgumentException was unhandled by user code
Message=”DataTable already belongs to another DataSet.”
Source=”System.Data”
StackTrace:
at System.Data.DataTableCollection.BaseAdd(DataTable table)
at System.Data.DataTableCollection.Add(DataTable table)
at _Default.Page_Load(Object sender, EventArgs e) in c:\TestHarness\MergeTwoXmlFiles\Default.aspx.cs:line 35
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Reason fort an error is dataset2’s Table number 0 can’t be added to dataset1’s tables collection as it is already in dataset2’s tables collection — Recall Reference types?
So, final solution is as below:
[sourcecode language=”csharp”]</pre>
// Remove table from second dataset
DataTable dt = dataSet2.Tables[0];
dataSet2.Tables.Remove(dt);
// and add it to first one
dataSet1.Tables.Add(dt);
[/sourcecode]
Happy Dataset Merging! 🙂

What are the differences between .NET 2.0,3.0 & 3.5?

Answer :-

Good Links:
http://dufoli.wordpress.com/2007/09/11/net-framework-11-20-30-35-21/
http://24x7aspnet.blogspot.com/2009/05/difference-between-net-203035-framework.html
In short:
2.0 => framework that shipped with VS 2005 VB 8.0 / C# 2.0
3.0 => same framework as 2.0 + WCF + WPF + WF
3.5 => all the above + LINQ technologies and will ship with the next VS including VB 9.0 and C#
Updated as per Gaurav’s comment.

PolyglotSkype : A MultiLingual Skype

Challenge

One of my friend Vishwas tried to send message in Skype and at that time he came to know  that skype dosen’t supports Unicode Characters — Which is required stuff for sending multilingual message. He asked me to develop something. I was also knowing this and in back of my mind I was thinking to create some application using which skype can support Unicode Characters.

Solution

First, I started looking on web that how can i communicate with Skype using my C# Code and I found[someone truly said : A will will find a way] Skype4COM– “Skype4COM is an ActiveX component that represents the Skype API as objects, with properties, commands, events and notifications. Use Skype4COM in any ActiveX environment, such as Visual Studio or Delphi, and with a standard scripting language, such as Visual Basic, PHP, or Javascript. [Src : http://developer.skype.com/accessories]”
Secondly, I thought to use Google’s Translate feature in my application directly. So, user no need to go to Google Translate page do translation and copy-paste message.  Then I found Google-API-for-dot-net
Now, the raw and basic material is ready with me. Now i need to write windows application and some hand crafted code to create my own Skype. But before starting i also thought a lot for name I wanted to give unique name and i found it — “PolyglotSkype” [polyglot — linguist: a person who speaks more than one language].
Finally, I am glad to share this tool with you. Below are few details of it:

Introduction

PolyglotSkype supports unicode characters, using which you can chat with your buddies in any language.

Main features

  • Unicode support.
  • Loads all your online skype friends.
  • In-built Google Translate support — Supports so many languages!.

Screen shots



System requirements

Skype
.NET 3.5 SP1

How to use?

1. Install “PolyglotSkypeInstaller”.
2. Once installed it will create shortcut on your desktop “PolyglotSkype”.
3. Now, to use PolyglotSkype you need to be logged in to Skype.
4. When you run PolyglotSkype application skype will ask you for access. Please select “Allow access”.
5. That’s it! Enjoy 🙂

I would like to hear from you

If your feedback is positive tell to your peers else tell to me at : klpatil@hotmail.com. Feel free to post your suggestions/comments/bugs at provided email id.

Technical links

For Google Translate : http://code.google.com/p/google-api-for-dotnet/
For Skype API : http://developer.skype.com/accessories
Windows Installer : http://www.simple-talk.com/dotnet/visual-studio/getting-started-with-setup-projects/

Would like to Download? Click here

Eager to have your feedback!
Sourcecode : Coming Soon…

Skype4COM

WebBrowserControl Scroll to Bottom

Challenge

I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display the messages between the user and the recipient. How do I get the control to automatically scroll to the bottom every time I update the DocumentText of the control?

Solution

I tried to Google it and found below stuff which doesn’t work as expected.

ctlWebBrowser.Document.Body.ScrollIntoView(false);

// http://stackoverflow.com/questions/990651/system-windows-forms-webbrowser-scroll-to-end

webCtrl.Document.Window.ScrollTo(0, int.MaxValue);

// http://stackoverflow.com/questions/46454/webbrowsercontrol-scroll-to-bottom
Finally, I did it using following way:
[sourcecode language=”csharp”]
private void ScrollMessageIntoView()
{
// MOST IMP : processes all windows messages queue
System.Windows.Forms.Application.DoEvents();
if (webBrowserControlRcdMsg.Document != null)
{
webBrowserControlRcdMsg.Document.Window.ScrollTo(0,
webBrowserControlRcdMsg.Document.Body.ScrollRectangle.Height);
}
}
[/sourcecode]
Thanks to this Link : http://social.msdn.microsoft.com/forums/en-US/winforms/thread/74694382-dc0d-4824-ac8f-3a4046f45111/

Awesome DataAccess Tutorials

Hello All, Today while looking at my some old data i found very good ASP.NET DataAccess Tutorials. Which i was using a lot when i was totally newbie[Even today also I’m newbie only :)]  in ASP.NET this tutorials contains everything and the content and the way tutorial teaches is really awesome. You must be thinking this guy is prasing and just keep talking about tutorials but where are the tutorials? Here you go : http://www.asp.net/data-access/tutorials And all tuorials are available in PDF Format for Download 🙂
I hope this tutorials help the same way it helped me. Thanks to the Author for writing such a nice tutorials!