A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Archive for January, 2010

Setting up Dual wallpaper on dual monitors

Posted by kiranpatils on January 26, 2010

if you are using dual monitors and you would like to set up dual wallpapers on both the monitors. Then it’s not directly possible. I know that there is something called NView from NVIDIA. But i didn’t liked it too much. It’s my personal view.

After googling a bit i found nice tool called “wallmaster” which is free and source is also available at codeplex :

http://wallmaster.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=23483

WallMaster 0.1.3 Download

Posted in Tools and Utilites | Leave a Comment »

Remote desktop in the same session

Posted by kiranpatils on January 26, 2010

Challenge:

I want to access my machine from another machine using Remote desktop with the same credentials at both the places. But when i do remote desktop from another machine using “mstsc” and my Machine Name then it gives me new session. But i want my same old session as i have so many programs runing on it and so many files are open. Pls note that i am doing this using Windows Server 2003.

Solution:

I googled it bit. But in the mean time one of my colleague told me to use “mstsc /console” to access the same session. And it’s working :) . Then i read a bit and found that in Windows XP it will always give you console mode — means if user is same then same session will be given. While in Windows Server 2003 you have to use “mstsc /console”. Here are the steps:

1. Go to Run(Window + R).

2. type “mstsc /console”. [Without quotes]

3. Which will open Remote Desktop connection dialgobox. Provide computer as your machine name/ip address on which you would like to connect.

4. Provide the credentials[pls note that credentials should be the same means if on A machine X user is logged in then from B machine X user should log in].

5. That’s it!

Happy Remoting! :)

Posted in Miscellaneous | Leave a Comment »

Object dosen’t support this property or method with showModalDialog

Posted by kiranpatils on January 11, 2010

Challenge:

We’re trying to open Modal Window from Modal Window on button click which is inside update panel:

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(Button1, page.GetType(), "OpenModalDialog", "<script type=text/javascript>window.showModalDialog('http://www.gooogle.com, null, 'dialogHeight:100px;dialogWidth:280px;status:no'); </script>", false);
}

But it was giving an error Object dosen’t support this property or method

Solution:

Pls  check that pop-up blocker is not active. [Tools | Pop-Up Blocker|Turn-off Pop-up Blocker].

Posted in Javascript | Leave a Comment »

Exceeded storage allocation. The server response was: 5.7.0 Our system detected an illegal attachment on your message.

Posted by kiranpatils on January 7, 2010

If you are genearting zip file runtime in memory and sending mail at run time. and you faced the error as shown below:

Exceeded storage allocation. The server response was: 5.7.0 Our system detected an illegal attachment on your message.

Then to fix it, you have to do the following change in your code(Pls note I’ve used SharpZipLib and Memory Stream for sending an email at run time using gmail server):

MemoryStream zipFileStream = new MemoryStream();
zipOutputStream = new ZipOutputStream(zipFileStream);
..
..
..
//read from stream and add to zipoutputstream code should go here
...
..
// Seek to begining -- IF YOU DON' ADD BELOW LINE IT Will give above error
zipFileStream.Seek(0, SeekOrigin.Begin);
mailMessage.Attachments.Add(new Attachment(zipFileStream, "myzipfile.zip"));

if you’ve seen the above code. Below line says MemroyStream to seek to Begining of the stream, So when SMTP Server scans the file before sending it gets perfect file.

zipFileStream.Seek(0, SeekOrigin.Begin);

Happy Mailing!


Posted in SharpZipLib | 4 Comments »

The Compressed (zipped) Folder is invalid or corrupted with SharpZipLib

Posted by kiranpatils on January 6, 2010

I have generated Zip File using SharpZipLib. But when i try to access it using Windows XP extraction tool it shos following error:  Compressed (zipped) Folder is invalid or corrupted and it worked fine with 7zip. So, i did googling and found one nice solution from this link : http://blog.tylerholmes.com/2008/12/windows-xp-unzip-errors-with.html

Solution is — extracted from the above blog only.

...
ZipEntry entry = new ZipEntry(Path.GetFileName(sourceFilePath));
entry.DateTime = DateTime.Now;
/* By specifying a size, SharpZipLib will turn on/off UseZip64 based on the file sizes. If Zip64 is ON
* some legacy zip utilities (ie. Windows XP) who can't read Zip64 will be unable to unpack the archive.
* If Zip64 is OFF, zip archives will be unable to support files larger than 4GB. */
entry.Size = new FileInfo(sourceFilePath).Length;
zipStream.PutNextEntry(entry);
...

If it works say thanks to Tyler Holmes — Above Blog author, for such a nice article!

Happy zipping!

Posted in SharpZipLib | 4 Comments »

UnSupported Compression method

Posted by kiranpatils on January 6, 2010

Challenge:

I was writing a piece of code which generates zip file from the files read from Database and send  as an attachment mail to user. I used SharpZiLib library for that. And i completed writing my logic and mail goes fine to user’s mail box. So, far so good :) . But when user tries to extract the attached zip file using 7Zip it shown following error and was working fine with winzip:

UnSupported Compression method for FILENAME.FILEXTENSION ERROR

Solution:

Then i just started going through the code and i just commented following line of cod and it worked!

//Crc32 crc = new Crc32();
//crc.Reset();
//crc.Update(buffer);
//zipEntry.Crc = crc.Value;

Hope this helps you to resolve your problem and say happy zipping!

Posted in SharpZipLib | 1 Comment »

Performing a Long Running Task with ASP.NET

Posted by kiranpatils on January 1, 2010

Challenge:

Suppose, you have one Web Page and it contains one Button on click of it you perform some long running task for instance Copying thousands of Selected Data from one database to another database or something which takes too much time.

Now, if you perform this type of operation what will happen that if after click of your button it goes to server and start executing the server code on server side and client waits for a long to hear a response from server. But as the Server side code has to do so many things it takes time and after sometime on client page you will see “Page Can not be displayed” screen or something like that which confuse end user whether the work is done or not.

So, you may say that why don’t you do the server side task in chunks[Means copying employees from one database to another in a 100/100 Chunks.] Yeap, you are correct we can do this. But it needs human interaction and the person who is going to do this will feel boring. [Work should be fun :) ]. So, let me show you how can you perform long running task asynchronously without human interaction and show result at the end of process.

Solution:

After goggling a lot and finding a lot of options[UpdateProgess and some JS stuff which sounds bit complex and dirty solution to me] finally i got link of MSDN Site which i found the best option Clean,Clear and Not Complex. I’ve derived my solution from MS Solution only.

Follow the steps given as below:

1. Create one class file in your Solution with name as ThreadResult.cs and the copy-paste following code in it.


/// <summary>
/// This class will be used to
/// store  ThreadResult in a
/// HashTable which has been
/// declared as static.
/// </summary>
public class ThreadResult
{
 private  static System.Collections.Hashtable
 ThreadsList = new  System.Collections.Hashtable();

public static void Add(string key, object value)
 {
 ThreadsList.Add(key, value);
 }

public static object Get(string key)
 {
 return  ThreadsList[key];
 }

public static void Remove(string key)
 {
 ThreadsList.Remove(key);
 }

public static bool Contains(string key)
 {
 return  ThreadsList.ContainsKey(key);
 }

}

2. On your LongRuning Task page – Where you have kept the button and on click of it you perform long running task. Go to it’s server side click event handler and amend the code as shown below:

Markup file’s Code – LongRuningTask.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</a>>
<html xmlns="<a href="http://www.w3.org/1999/xhtml%22">http://www.w3.org/1999/xhtml"</a>>
<head runat="server">
 <title>Long Running Task  Page</title>

<script language="javascript" type="text/javascript">
 function OpenProgressWindow(reqid)
 {
 window.showModalDialog("ResultPage.aspx?RequestId="+reqid
 ,"Progress  Window","dialogHeight:200px; dialogWidth:380px");
 }
 </script>

</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:Button ID="btnLongRuningTask"  runat="server" Text="Long Runing Task" OnClick="btnLongRuningTask_Click"
 />
 </div>
 </form>
</body>
</html>

Code-behind file’s code — LongRuningTask.aspx.cs


using System;
using System.Threading;
using System.Web.UI;

public partial class _Default : System.Web.UI.Page
{

 protected  void Page_Load(object sender, EventArgs e)

{

}
 protected Guid requestId;

 protected void  btnLongRuningTask_Click(object sender, EventArgs e)
 {
 requestId = Guid.NewGuid();

// Start the long running task on one thread
 ParameterizedThreadStart parameterizedThreadStart = new  ParameterizedThreadStart(LongRuningTask);

 Thread thread = new Thread(parameterizedThreadStart);

 thread.Start();

// Show Modal Progress Window
 Page.ClientScript.RegisterStartupScript(this.GetType(),
 "OpenWindow", "OpenProgressWindow('" + requestId.ToString() + "');",true);

 }

private void LongRuningTask(object data)
 {
 //  simulate long running task – your main logic should   go here
 Thread.Sleep(15000);

// Add ThreadResult -- when this
 // line executes it  means task has been
 // completed
 ThreadResult.Add(requestId.ToString(), "Item Processed Successfully."); // you  can add your result in second parameter.
 }
}

In Above code on click of Button we’ve create one new Thread and started the thread – means long runing method will be called and start processing on different thread without blocking current executing thread – your main web form page. and opened a new popup window which opens ResultPage.aspx with RequestId as a Query String[We will see it in Step 3] to check the progress and result of a process.

LongRuningTask Method will be called by Thread and it does main processing logic and on finish of the operation it adds the Result in ThreadResult – mapping table which we have created in step 1 for Mapping. Where RequestId is Key and Process result is value of HashTable. It’s main use will see shortly in step 3.

3. So far so good :) Now we need one .aspx page which shows progress to end user and keep checking that is thread executed successfully or not. For that Create one .aspx page with the name “ResultPage.aspx”. for simplicity I’ve followed single file model for ResultPage.aspx and i would suggest the same to you.

ResultPage.aspx

</pre>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</a>>

<script runat="server">
void Page_Load(object sender, EventArgs e)
{
string requestId = Request.QueryString["RequestId"];

if (!string.IsNullOrEmpty(requestId))
{
// if we found requestid means thread is processed
if (ThreadResult.Contains(requestId))
{
// get value
string result = (string)ThreadResult.Get(requestId);

// show message
lblResult.Text = result;

lblProcessing.Visible = false;
imgProgress.Visible = false;
lblResult.Visible = true;
btnClose.Visible = true;
// Remove value from HashTable
ThreadResult.Remove(requestId);

}
else
{
// keep refreshing progress window
Response.AddHeader("refresh", "2");
}
}
}
</script>

<html xmlns="<a href="http://www.w3.org/1999/xhtml&quot;">http://www.w3.org/1999/xhtml"</a>>
<head runat="server">
<title>Result Page</title>
<base target="_self" />
<style type="text/css">
.buttonCss
{
color:White;
background-color:Black;
font-weight:bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblProcessing" runat="server" Text="We are processing your request. Pls don't close this browser." />
<br />
<center>
<img id="imgProgress" runat="server" src="Progress.GIF" width="50" height="50" />
</center>
<asp:Label ID="lblResult" runat="server" Visible="false" Font-Bold="true" />
<br />
<center>
<asp:Button ID="btnClose" runat="server" Visible="false" Text="Close" OnClientClick="window.close();" CssClass="buttonCss" />
</center>
</div>
</form>
</body>
</html>
<pre>

4. You are done with coding stuff. Let’s keep fingers crossed and F5 the code.

Long Runing Task

Long Runing Task

Long Runing Task

That’s it! I hope this article helped you to perform long running task in a good way.

Happy Long Running Task! :)

Posted in ASP.NET | 2 Comments »

Milestone : MCPD Exam Cleared

Posted by kiranpatils on January 1, 2010

Hi, all my blog readers. first of all Happy New year to you and may this year adds more passion in you towards your profession!

After clearing MCTS – Web before few months. Today, i would like to share one great news with you all. I’ve cleared MCPD – Web (70-547) exam on 28/12/2009 with 975/1000 Marks :)

MCPD _ Web_Large

Thanks to all who wished me luck and boosted me up on my last achievement!

Journey towards this certification was too good and too challenging too. let me tell you challenging how it was!

Challenge to complete Book : I purchase the hard copy of book on 10/7/09[Price – 640 from Ask InfoTech Vadodara]. Now I’ve aimed to give exam on 26/10/2009. But as usual was heavily loaded with my stuff at office and the book is more theoretical. So, it needs more inputs and concentration compared to Practical stuff. In between i stopped reading then in start of November i come to know about Certification offer from Microsoft[25% Discount]. Which stimulated me bit and moreover I’ve thought to complete the MCPD certification before end of 2009. So, deadline was coming near and near(And as human nature as exam date comes near and near we start reading with full concentration :) and same hold true for me too!].

Challenge to give exam : You must be thinking how the giving exam could be a challenging task? Yeap, It was because in my city(Vadodara,Gujarat) one prometric is there which was down from last since months due to some technical reasons. So, now I’ve started looking at another options. And finally i found HCL Career Development Center – Ahmadabad and Thanks a lot to Asha ma’m[She manages prometric exams at this center] who helped me a lot during this process over the call only which saved my time. So, i booked my exam with 25% offer (1800 INR).

Challenge to Maintain one Transcript: I already had a MCP ID. But after clearing this exam i come to know that i will get new MCP ID and my MCPD Certificate will be in different Transcript..Hooh!! But finally i managed to get it done by calling at Regional Service Center

Now, finally when i see my certificate and logo. I feel good about fruitful result of completing this many challenges :)

Again Thanks and Happy Reading!

Posted in Milestones | Tagged: | 11 Comments »

 
Follow

Get every new post delivered to your Inbox.

Join 167 other followers